diff --git a/.bazelrc.common b/.bazelrc.common index 118f1b3b..3fa351d2 100644 --- a/.bazelrc.common +++ b/.bazelrc.common @@ -30,3 +30,13 @@ test --test_output=errors test --test_verbose_timeout_warnings # docs: https://bazel.build/reference/command-line-reference#flag--incompatible_exclusive_test_sandboxed test --incompatible_exclusive_test_sandboxed + +# docs: https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config +common --enable_platform_specific_config +# Enable persistent Zig cache directory within the sandbox, +# see https://github.com/aherrmann/rules_zig/issues/87, +# and https://github.com/uber/hermetic_cc_toolchain/issues/83. +# docs: https://bazel.build/reference/command-line-reference#flag--sandbox_add_mount_pair +build:linux --sandbox_add_mount_pair=/tmp +build:macos --sandbox_add_mount_pair=/var/tmp +build:windows --sandbox_add_mount_pair=C:\Temp diff --git a/README.md b/README.md index 0000a099..c06b8341 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,8 @@ and build configuration features well. The instructions assume basic familiarity with the Bazel build system. Take a look at [Bazel's documentation][bazel-intro] if you are unfamiliar. +Consider the [_Additional Setup_](#additional-setup) section as well. + [bazel-intro]: https://bazel.build/about/intro ### Using Bzlmod with Bazel >=6 @@ -135,6 +137,34 @@ information. --> +### Additional Setup + +#### Zig Cache + +The Zig compiler caches intermediate outputs on disk. This cache is shared and +persisted between Bazel builds and build actions. You can configure the cache +directory using the following set of environment variables, you can configure +them through Bazel by using the `--repo_env` flag. + +- `RULES_ZIG_CACHE_PREFIX_LINUX`: Cache directory on Linux, default `/tmp/zig-cache`. +- `RULES_ZIG_CACHE_PREFIX_MACOS`: Cache directory on MacOS, default `/var/tmp/zig-cache`. +- `RULES_ZIG_CACHE_PREFIX_WINDOWS`: Cache directory on Windows, default `C:\Temp\zig-cache`. +- `RULES_ZIG_CACHE_PREFIX`: Cache directory fall-back for all platforms, default `/tmp/zig-cache`. + +> [!Note] +> On Bazel 7 and above you need to explicitly allow persistence in the sandbox. +> You can use the following `.bazelrc` snippet, adjust the paths depending on +> your cache configuration. +> +> ``` +> common --enable_platform_specific_config +> # You can configure `/tmp/zig-cache`, or similar, specifically, +> # if you can ensure that the directory exists before the build. +> build:linux --sandbox_add_mount_pair=/tmp +> build:macos --sandbox_add_mount_pair=/var/tmp +> build:windows --sandbox_add_mount_pair=C:\Temp +> ``` + ## Usage Examples