Append username to the default tmp directory#187
Open
laurentlb wants to merge 1 commit into
Open
Conversation
When two people build code on the same machine, there can be a collision. The second person may not be able to write to zig-cache if it was created by someone else. When it happens, the error message is quite confusing (see `_compile_failed` variable). With this commit, each user should get a different directory by default. It's still possible to change the default using HERMETIC_CC_TOOLCHAIN_CACHE_PREFIX. Signed-off-by: Laurent Le Brun <laurentlb@gmail.com>
Author
|
It looks like this will conflict with #183. We can close this PR if the other one gets merged. |
Contributor
|
yeah, and quoting a discussion with @sluongng:
|
Closed
This was referenced May 22, 2026
Contributor
|
I've submitted #254 which takes a similar approach (appending the username) but resolves it at runtime in |
linzhp
pushed a commit
that referenced
this pull request
Jun 23, 2026
## Summary Fixes #83 — multiple users on the same machine collide on the shared zig cache directory (`/tmp/zig-cache`), causing permission errors. This PR appends the OS username to the zig cache directory **at runtime** in `zig-wrapper`, so each user gets a separate cache directory (e.g. `/tmp/zig-cache-alice`, `/tmp/zig-cache-bob`). ### Why runtime, not build time? Previous approaches (#187) embedded the username into the compiled `zig-wrapper` binary via template substitution. This means the binary differs per user, which [invalidates remote build cache](#187 (comment)) for every C++ action. By resolving the username at runtime instead, the compiled binary is identical for all users and remote cache is preserved. ### Changes - **`toolchain/zig-wrapper.zig`**: Read `USER` (Unix) or `USERNAME` (Windows) from the environment at runtime and append `-{username}` to the compiled-in cache directory base. Falls back to the base directory if the env var is unset (containers, headless environments). - **`toolchain/defs.bzl`**: The repository rule's compile step (which compiles zig-wrapper itself) also uses a per-user cache directory to prevent collisions during toolchain setup. The template substitution still uses the base prefix — the binary is not affected. - **`.github/workflows/ci.yaml`**: Updated cache paths to include the runner username (`runner` on Linux/macOS, `runneradmin` on Windows). - **`README.md`**: Updated cache directory documentation to reflect per-user behavior. ## Test plan - [x] `zig test zig-wrapper.zig` — new test verifies cache dir includes username suffix - [x] `tools/bazel test //...` — all 7 tests pass (4 skipped for non-matching platforms) - [x] CI will validate cross-platform behavior 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When two people build code on the same machine, there can be a collision. The second person may not be able to write to zig-cache if it was created by someone else. When it happens, the error message is quite confusing (see
_compile_failedvariable).With this commit, each user should get a different directory by default. It's still possible to change the default using
HERMETIC_CC_TOOLCHAIN_CACHE_PREFIX.