Skip to content

Commit

Permalink
Merge pull request #163 from motiejus/var-tmp
Browse files Browse the repository at this point in the history
MacOS default cache dir: /tmp -> /var/tmp
  • Loading branch information
motiejus authored Feb 14, 2024
2 parents 9b0c3df + d391b62 commit c836a66
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ build --worker_sandboxing

# TODO: turn this back on when Zig can build CGo (https://github.com/uber/hermetic_cc_toolchain/issues/10)
#build --action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build --experimental_output_directory_naming_scheme=diff_against_dynamic_baseline
build --sandbox_add_mount_pair=/tmp
build --sandbox_add_mount_pair=/var/tmp

build --experimental_output_directory_naming_scheme=diff_against_dynamic_baseline
build:darwin_toolchains --extra_toolchains @zig_sdk//toolchain:darwin_amd64,@zig_sdk//toolchain:darwin_arm64
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
with:
key: cache-${{ matrix.os }}-${{ hashFiles('.bazelversion', 'toolchain/private/zig_sdk.bzl', '.github/workflows/ci.yaml') }}
path: |
C:\Temp\hermetic_cc_toolchain
C:\Temp\zig-cache
~\AppData\Local\bazelisk'
- uses: actions/cache@v4
Expand All @@ -38,7 +38,7 @@ jobs:
with:
key: cache-${{ matrix.os }}-${{ hashFiles('.bazelversion', 'toolchain/private/zig_sdk.bzl', '.github/workflows/ci.yaml') }}
path: |
/tmp/zig-cache
/var/tmp/zig-cache
~/Library/Caches/bazelisk
- uses: actions/cache@v4
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ And this to `.bazelrc` on a Unix-y systems:

```
build --sandbox_add_mount_pair=/tmp
build --sandbox_add_mount_pair=/var/tmp
```

Windows:
Expand All @@ -70,10 +71,11 @@ Windows:
build --sandbox_add_mount_pair=C:\Temp
```

The directories can be narrowed down to `/tmp/zig-cache` and
`C:\Temp\hermetic_cc_toolchain` respectively if it can be ensured they will be
created before the invocation of `bazel build`. See [#83][pr-83] for more
context. If a different place is prefferred for zig cache, set:
The directories can be narrowed down to `/tmp/zig-cache` (Linux),
`/var/tmp/zig-cache` (MacOS) and `C:\Temp\zig-cache` respectively
if it can be ensured they will be created before the invocation of `bazel
build`. See [#83][pr-83] for more context. If a different place is prefferred
for zig cache, set:

```
build --repo_env=HERMETIC_CC_TOOLCHAIN_CACHE_PREFIX=/path/to/cache
Expand Down Expand Up @@ -329,7 +331,7 @@ will be accepted.

### Zig cache location

Currently zig cache is stored in `/tmp/hermetic_cc_toolchain`, so `bazel clean
Currently zig cache is stored in `/var/tmp/zig-cache`, so `bazel clean
--expunge` will not clear the zig cache. Zig's cache should be stored somewhere
in the project's path. It is not clear how to do it.

Expand Down
8 changes: 7 additions & 1 deletion ci/test
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@

set -xeuo pipefail

cache_prefix="${HERMETIC_CC_TOOLCHAIN_CACHE_PREFIX:-/tmp/zig-cache}"
case "$(uname)" in
Linux) default_cache_prefix='/tmp/zig-cache' ;;
Darwin) default_cache_prefix='/var/tmp/zig-cache' ;;
*) default_cache_prefix='C:\Temp\zig-cache' ;;
esac

cache_prefix="${HERMETIC_CC_TOOLCHAIN_CACHE_PREFIX:-$default_cache_prefix}"

# check a very hermetic setup with a single target. Re-building all of
# them takes a long time, so using only one. If we ever decide to build all
Expand Down
4 changes: 4 additions & 0 deletions examples/bzlmod/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
test --sandbox_default_allow_network=false
test --test_output=errors

build --incompatible_disallow_empty_glob
build --verbose_failures
build --worker_sandboxing

build --action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1

build --sandbox_add_mount_pair=/tmp
build --sandbox_add_mount_pair=/var/tmp

build --experimental_output_directory_naming_scheme=diff_against_dynamic_baseline
3 changes: 3 additions & 0 deletions examples/rules_cc/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
test --sandbox_default_allow_network=false
test --test_output=errors

build --incompatible_disallow_empty_glob
build --verbose_failures
build --worker_sandboxing

build --action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1

build --sandbox_add_mount_pair=/tmp
build --sandbox_add_mount_pair=/var/tmp
build --experimental_output_directory_naming_scheme=diff_against_dynamic_baseline
8 changes: 6 additions & 2 deletions toolchain/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,13 @@ def _zig_repository_impl(repository_ctx):
cache_prefix = repository_ctx.os.environ.get("HERMETIC_CC_TOOLCHAIN_CACHE_PREFIX", "")
if cache_prefix == "":
if os == "windows":
cache_prefix = "C:\\\\Temp\\\\hermetic_cc_toolchain"
else:
cache_prefix = "C:\\\\Temp\\\\zig-cache"
elif os == "macos":
cache_prefix = "/var/tmp/zig-cache"
elif os == "linux":
cache_prefix = "/tmp/zig-cache"
else:
fail("unknown os: {}".format(os))

repository_ctx.template(
"tools/zig-wrapper.zig",
Expand Down

0 comments on commit c836a66

Please sign in to comment.