Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ build --worker_sandboxing

build --experimental_output_directory_naming_scheme=diff_against_dynamic_baseline

build:linux --sandbox_add_mount_pair=/tmp
build:macos --sandbox_add_mount_pair=/var/tmp
build:windows --sandbox_add_mount_pair=C:\Temp

build:macos_toolchains --extra_toolchains @zig_sdk//toolchain:darwin_amd64,@zig_sdk//toolchain:darwin_arm64
build:macos_toolchains --action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build:macos_toolchains --build_tag_filters=
Expand Down
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,14 @@ And this to `.bazelrc` on a Unix-y systems:

```
common --enable_platform_specific_config
build:linux --sandbox_add_mount_pair=/tmp
build:macos --sandbox_add_mount_pair=/var/tmp
build:windows --sandbox_add_mount_pair=C:\Temp
```

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 preferred
for zig cache, set:
The default zig cache location is within `./zig-cache` in the workspace root. If
a different path is preferred for zig cache, set it. (It is always resolved
against the workspace root):

```
build --repo_env=HERMETIC_CC_TOOLCHAIN_CACHE_PREFIX=/path/to/cache
build --sandbox_add_mount_pair=/path/to/cache
build --repo_env=HERMETIC_CC_TOOLCHAIN_CACHE_PREFIX=path/to/cache
```

The snippets above will download the zig toolchain and make the bazel
Expand Down Expand Up @@ -441,6 +435,5 @@ On a more practical note:
[subset]: https://en.wikipedia.org/wiki/Subset
[universal-headers]: https://github.com/ziglang/universal-headers
[go-monorepo]: https://www.uber.com/blog/go-monorepo-bazel/
[pr-83]: https://github.com/uber/hermetic_cc_toolchain/issues/83
[pr-10]: https://github.com/uber/hermetic_cc_toolchain/issues/10
[examples]: https://github.com/uber/hermetic_cc_toolchain/tree/main/examples
4 changes: 0 additions & 4 deletions examples/bzlmod/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ build --verbose_failures
build --worker_sandboxing
build --experimental_output_directory_naming_scheme=diff_against_dynamic_baseline

build:linux --sandbox_add_mount_pair=/tmp
build:macos --sandbox_add_mount_pair=/var/tmp
build:windows --sandbox_add_mount_pair=C:\Temp

test --sandbox_default_allow_network=false
test --test_output=errors
3 changes: 0 additions & 3 deletions examples/rules_cc/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ build --verbose_failures
build --worker_sandboxing
build --experimental_output_directory_naming_scheme=diff_against_dynamic_baseline
build --action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build:linux --sandbox_add_mount_pair=/tmp
build:macos --sandbox_add_mount_pair=/var/tmp
build:windows --sandbox_add_mount_pair=C:\Temp

test --sandbox_default_allow_network=false
test --test_output=errors
9 changes: 3 additions & 6 deletions toolchain/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,9 @@ def _zig_repository_impl(repository_ctx):

cache_prefix = repository_ctx.os.environ.get("HERMETIC_CC_TOOLCHAIN_CACHE_PREFIX", "")
if cache_prefix == "":
if host_os == "windows":
cache_prefix = "C:\\\\Temp\\\\zig-cache"
elif host_os == "macos":
cache_prefix = "/var/tmp/zig-cache"
elif host_os == "linux":
cache_prefix = "/tmp/zig-cache"
if host_os == "windows" or host_os == "macos" or host_os == "linux":
# Use a shared cache directory in the execroot for all platforms
cache_prefix = "../../../zig_cache"
else:
fail("unknown os: {}".format(host_os))

Expand Down
12 changes: 9 additions & 3 deletions toolchain/zig-wrapper.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ const EXE = switch (builtin.target.os.tag) {
.windows => ".exe",
else => "",
};

const CACHE_DIR = "{HERMETIC_CC_TOOLCHAIN_CACHE_PREFIX}";

const usage =
Expand Down Expand Up @@ -208,6 +207,13 @@ fn parseArgs(
);
};

const zig_cache_dir = if (CACHE_DIR[0] == sep[0])
CACHE_DIR
else
try fs.path.join(arena, &[_][]const u8{
cwd.realpathAlloc(arena, ".") catch unreachable,
CACHE_DIR,
});
const zig_lib_dir = try fs.path.join(arena, &[_][]const u8{ root, "lib" });
const zig_exe = try fs.path.join(
arena,
Expand All @@ -218,8 +224,8 @@ fn parseArgs(
return parseFatal(arena, "error getting env: {s}", .{@errorName(err)});

try env.put("ZIG_LIB_DIR", zig_lib_dir);
try env.put("ZIG_LOCAL_CACHE_DIR", CACHE_DIR);
try env.put("ZIG_GLOBAL_CACHE_DIR", CACHE_DIR);
try env.put("ZIG_LOCAL_CACHE_DIR", zig_cache_dir);
try env.put("ZIG_GLOBAL_CACHE_DIR", zig_cache_dir);

// args is the path to the zig binary and args to it.
var args = ArrayListUnmanaged([]const u8){};
Expand Down
Loading