1

Support configuring cache prefix with an environment variable

The user may want to build with `--sandbox_tmpfs_path=/tmp`, in which
case the Zig cache will not be shared between sandboxes, massively
slowing down the build. With this feature, the user can pass flags
like `--repo_env=BAZEL_ZIG_CC_CACHE_PREFIX=$HOME/.cache/bazel-zig-cc`
together with `--sandbox_writable_path=$HOME/.cache/bazel-zig-cc` to
put the cache somewhere else which can be shared between sandboxes.
This commit is contained in:
Ken Micklas 2022-08-25 19:24:38 +01:00 committed by Motiejus Jakštys
parent 23d9b9d39e
commit 0612c6ed9c

View File

@ -79,7 +79,9 @@ def toolchains(
ZIG_TOOL_WRAPPER = """#!/usr/bin/env bash
set -e
if [[ -n "$TMPDIR" ]]; then
if [[ -n "{cache_prefix}" ]]; then
_cache_prefix="{cache_prefix}"
elif [[ -n "$TMPDIR" ]]; then
_cache_prefix=$TMPDIR
elif [[ -n "$HOME" ]]; then
if [[ "$(uname)" = Darwin ]]; then
@ -149,6 +151,7 @@ def _zig_repository_impl(repository_ctx):
zig_tool_wrapper = ZIG_TOOL_WRAPPER.format(
zig = str(repository_ctx.path("zig")),
zig_tool = zig_tool,
cache_prefix = repository_ctx.os.environ.get("BAZEL_ZIG_CC_CACHE_PREFIX", ""),
)
if os == "windows":
zig_tool_wrapper = ZIG_TOOL_WRAPPER_WINDOWS.format(