diff --git a/.bazelrc b/.bazelrc index 9b10eee..68fa4c4 100644 --- a/.bazelrc +++ b/.bazelrc @@ -10,6 +10,21 @@ common --tool_java_runtime_version=remotejdk_25 # Match Gradle's manifest merger: plugin library permissions must reach the APK. common --merge_android_manifest_permissions +# Hermeticity. Every toolchain (LLVM, Rust, JDK, Android SDK/NDK, Dart/Flutter, +# Go) is downloaded and checksummed, so no action needs the network, and no +# host C/C++ compiler may be autodetected as a fallback toolchain. +common --sandbox_default_allow_network=false +common --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 +# Persistent workers (Javac, Kotlin, Android tools) otherwise run unsandboxed +# and can read undeclared inputs from the execroot. +common --worker_sandboxing + +# A disk cache shared by every checkout and worktree on this machine: action +# keys are independent of the workspace path, so a fresh worktree reuses the +# outputs of all others instead of rebuilding from scratch. +common --disk_cache=~/.cache/bazel-disk-cache +common --experimental_disk_cache_gc_max_size=60G + # BuildBuddy is opt-in so a fresh clone works without credentials. See # user.bazelrc.example; --config=remote also enables this cache/BES config. build:buildbuddy --bes_backend=grpcs://remote.buildbuddy.io @@ -20,7 +35,6 @@ build:buildbuddy --experimental_remote_downloader_local_fallback build:buildbuddy --remote_timeout=10m build:buildbuddy --remote_cache_compression build:buildbuddy --remote_cache_async -build:buildbuddy --remote_download_toplevel build:buildbuddy --nolegacy_important_outputs build:buildbuddy --bes_upload_mode=fully_async @@ -32,6 +46,14 @@ build:buildbuddy --build_metadata=REPO_URL=https://github.com/pawelchcki/razemif # the workflow runner because this organization has no remote-executor pool. build:ci --config=buildbuddy build:ci --build_metadata=ROLE=CI +# The runner's output base and the BuildBuddy cache already cover what the +# local disk cache would, without spending runner disk on a third copy. +common:ci --disk_cache= +# Fail rather than silently re-resolve when MODULE.bazel.lock is stale. +common:ci --lockfile_mode=error +# Only download what a step inspects; steps that need artifacts on disk pass +# --remote_download_toplevel explicitly. +build:ci --remote_download_minimal # //:clippy is a gate, so warnings must fail it -- the equivalent of # `cargo clippy -- -D warnings`. diff --git a/MODULE.bazel b/MODULE.bazel index afb0a29..0d6a3fd 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -94,11 +94,16 @@ register_toolchains( # rules_rs is implemented on a patched compatibility repository. Keep that # implementation detail behind a rules_rs-owned apparent name; Razemify's Rust -# build rules are loaded exclusively from @rules_rs. The local patch fixes -# response-file substitutions while rules_rs bootstraps its process wrapper. +# build rules are loaded exclusively from @rules_rs. The local patch redacts the +# exec root from build-script env output when it precedes `=`, as in the +# `--remap-path-prefix==.` that rav1e and av-scenechange echo back +# from CARGO_ENCODED_RUSTFLAGS. Unpatched, those outputs embed the per-action +# sandbox path, so neither crate is ever a cache hit on a fresh output base. +# Drop once https://github.com/hermeticbuild/rules_rust/pull/84 reaches a +# rules_rs release. rules_rs_internal = use_extension("@rules_rs//rs:rules_rust.bzl", "rules_rust") rules_rs_internal.patch( - patches = ["//bazel:rules_rs_bootstrap_determinism.patch"], + patches = ["//bazel:rules_rs_build_script_env_determinism.patch"], strip = 1, ) use_repo(rules_rs_internal, rules_rs_internal = "rules_rust") diff --git a/bazel/BUILD.bazel b/bazel/BUILD.bazel index ae2ed15..5101d39 100644 --- a/bazel/BUILD.bazel +++ b/bazel/BUILD.bazel @@ -17,5 +17,5 @@ exports_files([ "rules_android_desugar_memory.patch", "rules_android_manifest_log_determinism.patch", "rustix_determinism.patch", - "rules_rs_bootstrap_determinism.patch", + "rules_rs_build_script_env_determinism.patch", ]) diff --git a/bazel/rules_rs_bootstrap_determinism.patch b/bazel/rules_rs_bootstrap_determinism.patch deleted file mode 100644 index 948634e..0000000 --- a/bazel/rules_rs_bootstrap_determinism.patch +++ /dev/null @@ -1,64 +0,0 @@ -diff --git a/util/process_wrapper/private/bootstrap_process_wrapper.cc b/util/process_wrapper/private/bootstrap_process_wrapper.cc ---- a/util/process_wrapper/private/bootstrap_process_wrapper.cc -+++ b/util/process_wrapper/private/bootstrap_process_wrapper.cc -@@ -1,6 +1,7 @@ - #include - #include - #include - #include -+#include - #include - #include -@@ -138 +139,40 @@ bool replace_environment_placeholders(const char* name, -+bool expand_response_file(std::string* arg, -+ const std::string& pwd, -+ const std::string& output_base, -+ const std::string& exec_root) { -+ if (arg->empty() || arg->front() != '@') { -+ return true; -+ } -+ -+ const std::string input_path = arg->substr(1); -+ const std::string output_path = input_path + ".expanded"; -+ std::ifstream input(input_path); -+ if (!input) { -+ std::fprintf(stderr, -+ "bootstrap_process_wrapper: cannot read response file %s\n", -+ input_path.c_str()); -+ return false; -+ } -+ std::ofstream output(output_path, std::ios::trunc); -+ if (!output) { -+ std::fprintf(stderr, -+ "bootstrap_process_wrapper: cannot write response file %s\n", -+ output_path.c_str()); -+ return false; -+ } -+ -+ std::string line; -+ while (std::getline(input, line)) { -+ output << replace_placeholders(line, pwd, output_base, exec_root) << '\n'; -+ } -+ if (!input.eof() || !output) { -+ std::fprintf(stderr, -+ "bootstrap_process_wrapper: failed expanding response file %s\n", -+ input_path.c_str()); -+ return false; -+ } -+ *arg = "@" + output_path; -+ return true; -+} -+ - } // namespace -@@ -132,6 +172,9 @@ int main(int argc, char** argv) { - std::vector command_args; - command_args.reserve(static_cast(argc - first_arg_index)); - for (int i = first_arg_index; i < argc; ++i) { -- command_args.push_back( -- replace_placeholders(argv[i], pwd, output_base, exec_root)); -+ std::string arg = replace_placeholders(argv[i], pwd, output_base, exec_root); -+ if (!expand_response_file(&arg, pwd, output_base, exec_root)) { -+ return 1; -+ } -+ command_args.push_back(arg); - } diff --git a/bazel/rules_rs_build_script_env_determinism.patch b/bazel/rules_rs_build_script_env_determinism.patch new file mode 100644 index 0000000..d4f4ded --- /dev/null +++ b/bazel/rules_rs_build_script_env_determinism.patch @@ -0,0 +1,14 @@ +--- a/cargo/private/cargo_build_script_runner/lib.rs ++++ b/cargo/private/cargo_build_script_runner/lib.rs +@@ -340,6 +340,11 @@ + value + .replace(&format!("{exec_root}/"), "${pwd}/") + .replace(&format!("{exec_root}\\"), "${pwd}\\") ++ // Flags such as `--remap-path-prefix==.` (which build ++ // scripts see in CARGO_ENCODED_RUSTFLAGS and may echo back as ++ // `cargo:rustc-env`) follow the exec root with `=`. Leaving it ++ // unredacted bakes the per-action sandbox path into the output. ++ .replace(&format!("{exec_root}="), "${pwd}=") + } + + /// Redact for env vars: uses the generic `${out_dir}` token, resolved diff --git a/buildbuddy.yaml b/buildbuddy.yaml index b60c30a..4f55fda 100644 --- a/buildbuddy.yaml +++ b/buildbuddy.yaml @@ -9,6 +9,14 @@ actions: - "*" container_image: "ubuntu-24.04" timeout: "30m" + # The default Linux workflow VM (3 CPU, 8GB RAM, 20GB disk) runs out of + # disk once the Android SDK/NDK, LLVM, Flutter and JDK repositories, the + # output tree, and the recycled runner's state add up, and 3 CPUs make + # every remote-cache miss slow. + resource_requests: + cpu: 16 + memory: 32GB + disk: 60GB steps: - run: | bazel test \