Skip to content

Commit

Permalink
improved buildbuddy workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Hilgers committed May 27, 2024
1 parent c4cc011 commit 886fec3
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 165 deletions.
12 changes: 6 additions & 6 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ build --remote_timeout=3600
build --spawn_strategy=remote,sandboxed
build --remote_executor=grpcs://remote.buildbuddy.io

build:remote --host_platform=@buildbuddy_toolchain//:platform
build:remote --platforms=@buildbuddy_toolchain//:platform
build:remote --extra_execution_platforms=@buildbuddy_toolchain//:platform
build:remote --crosstool_top=@buildbuddy_toolchain//:toolchain
build:remote --extra_toolchains=@buildbuddy_toolchain//:cc_toolchain
build:remote --define=EXECUTOR=remote
build --host_platform=@buildbuddy_toolchain//:platform
build --platforms=@buildbuddy_toolchain//:platform
build --extra_execution_platforms=@buildbuddy_toolchain//:platform
build --crosstool_top=@buildbuddy_toolchain//:toolchain
build --extra_toolchains=@buildbuddy_toolchain//:cc_toolchain
build --define=EXECUTOR=remote

build --remote_cache_compression
build --noslim_profile --experimental_profile_include_target_label --experimental_profile_include_primary_output
Expand Down
9 changes: 9 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ bazel_dep(name = "aspect_rules_js", version = "1.42.1")
bazel_dep(name = "rules_android", version = "0.2.0")
bazel_dep(name = "rules_buildbuddy", version = "0.0.1")
bazel_dep(name = "rules_robolectric", version = "4.11.1")
bazel_dep(name = "rules_android_ndk", version = "0.1.0")
git_override(
module_name = "rules_android_ndk",
commit = "1ed5be3498d20c8120417fe73b6a5f2b4a3438cc",
patch_cmds = ["touch BUILD.empty.tpl"],
patches = ["//patches:rules_android_ndk.patch"],
remote = "https://github.com/bazelbuild/rules_android_ndk",
)

single_version_override(
module_name = "rules_robolectric",
patches = ["//patches:rules_robolectric.patch"],
Expand Down
140 changes: 0 additions & 140 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
load("@rules_android//rules:rules.bzl", "android_sdk_repository")
load("@rules_android_ndk//:rules.bzl", "android_ndk_repository")

android_sdk_repository(
name = "androidsdk",
api_level = 34,
)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_android_ndk",
sha256 = "f238b4b0323f1e0028a4a3f1093574d70f087867f4b29626469a11eaaf9fd63f",
strip_prefix = "rules_android_ndk-1ed5be3498d20c8120417fe73b6a5f2b4a3438cc",
url = "https://github.com/bazelbuild/rules_android_ndk/archive/1ed5be3498d20c8120417fe73b6a5f2b4a3438cc.zip",
)

load("@rules_android_ndk//:rules.bzl", "android_ndk_repository")

android_ndk_repository(
name = "androidndk",
api_level = 26,
Expand Down
4 changes: 2 additions & 2 deletions buildbuddy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ actions:
resource_requests:
disk: 50G
bazel_commands:
- "run --noenable_bzlmod //tools/workflow:workflow_setup"
- "test --config=remote --repo_env=ANDROID_HOME=/home/buildbuddy/workspace/.home/.android/sdk/ --repo_env=ANDROID_NDK_HOME=/home/buildbuddy/workspace/.home/.android/sdk/ndk/26.3.11579264/ //..."
- "bazel run //tools/workflow:workflow_setup"
- "bazel --bazelrc=ci.bazelrc test //..."
1 change: 1 addition & 0 deletions patches/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
exports_files(
srcs = [
"rules_android_ndk.patch",
"rules_kotlin.patch",
"rules_robolectric.patch",
"uniffi_bindgen.patch",
Expand Down
24 changes: 24 additions & 0 deletions patches/rules_android_ndk.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git rules.bzl rules.bzl
index e310c2a..9a6ad51 100644
--- rules.bzl
+++ rules.bzl
@@ -25,8 +25,9 @@ def _android_ndk_repository_impl(ctx):
"""
ndk_path = ctx.attr.path or ctx.os.environ.get("ANDROID_NDK_HOME", None)
if not ndk_path:
- fail("Either the ANDROID_NDK_HOME environment variable or the " +
- "path attribute of android_ndk_repository must be set.")
+ # Create an empty repository that allows non-Android code to build.
+ ctx.template("BUILD.bazel", ctx.attr._template_empty)
+ return None

if ctx.os.name == "linux":
clang_directory = "toolchains/llvm/prebuilt/linux-x86_64"
@@ -121,6 +122,7 @@ android_ndk_repository = repository_rule(
"_template_target_systems": attr.label(default = ":target_systems.bzl.tpl", allow_single_file = True),
"_template_ndk_clang": attr.label(default = ":BUILD.ndk_clang.tpl", allow_single_file = True),
"_template_ndk_sysroot": attr.label(default = ":BUILD.ndk_sysroot.tpl", allow_single_file = True),
+ "_template_empty": attr.label(default = ":BUILD.empty.tpl", allow_single_file = True),
},
local = True,
implementation = _android_ndk_repository_impl,
24 changes: 18 additions & 6 deletions tools/workflow/workflow_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,28 @@ sudo bash -c "$(declare -f install_jre); install_jre"
VERSION_LONG="10406996"
FILENAME="commandlinetools-linux-${VERSION_LONG}_latest.zip"
SHA256="8919e8752979db73d8321e9babe2caedcc393750817c1a5f56c128ec442fb540"
ANDROID_SDK_ROOT="$HOME/.android/sdk"

if [[ ! -d ~/.android/sdk ]]; then
if [[ ! -d "$ANDROID_SDK_ROOT" ]]; then
wget -O "$FILENAME" "https://dl.google.com/android/repository/commandlinetools-linux-${VERSION_LONG}_latest.zip"
echo "${SHA256} ${FILENAME}" >SHA256SUMS
sha256sum -c SHA256SUMS
mkdir -p ~/.android/sdk/cmdline-tools/
unzip $FILENAME -d ~/.android/sdk/tmp
mv ~/.android/sdk/tmp/cmdline-tools ~/.android/sdk/cmdline-tools/latest
mkdir -p "$ANDROID_SDK_ROOT/cmdline-tools/"
unzip $FILENAME -d "$ANDROID_SDK_ROOT/tmp"
mv "$ANDROID_SDK_ROOT/tmp/cmdline-tools" "$ANDROID_SDK_ROOT/cmdline-tools/latest"
fi

(yes || true) | ~/.android/sdk/cmdline-tools/latest/bin/sdkmanager --licenses
(yes || true) | "$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager" --licenses

~/.android/sdk/cmdline-tools/latest/bin/sdkmanager "ndk;26.3.11579264" "build-tools;34.0.0" "platforms;android-34"
"$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager" "ndk;26.3.11579264" "build-tools;34.0.0" "platforms;android-34"

ANDROID_HOME="$ANDROID_SDK_ROOT"
ANDROID_NDK_HOME="$ANDROID_HOME/ndk/26.3.11579264"

cat <<EOF >ci.bazelrc
common --repo_env=ANDROID_HOME=$ANDROID_HOME
common --repo_env=ANDROID_NDK_HOME=$ANDROID_NDK_HOME
EOF

echo $PWD
ls -la $PWD

0 comments on commit 886fec3

Please sign in to comment.