# CLI: improved local cache directory logic · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/21236c015140cbb1061e6161faa8011915d15de3)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 21236c015140cbb1061e6161faa8011915d15de3

Requested commit: 21236c015140cbb1061e6161faa8011915d15de3

Commit: 21236c015140cbb1061e6161faa8011915d15de3

Tree: 7d4439167a93fdee99bf87f6e170381877a8545d

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
CLI: improved local cache directory logic

Previously, when choosing the local cache directory, if there was no
root source file, an explicitly chosen path, or other clues, zig would
choose cwd + zig-cache/ as the local cache directory.

This can be problematic if Zig is invoked with the CWD set to a
read-only directory, or a directory unrelated to the actual source files
being compiled. In the real world, we see this when using `zig cc` with
CGo, which for some reason changes the current working directory to the
read-only go standard library path before running the C compiler.

This commit conservatively chooses to use the global cache directory
as the local cache directory when there is no other reasonable choice,
and no longer will rely on the cwd path to choose a local cache directory.

As a reminder, the --cache-dir CLI flag and ZIG_LOCAL_CACHE_DIR
environment variable are available for overriding the decision. For the
zig build system, it will always choose the directory that build.zig is
+ zig-cache/.

Closes #7342

```

## Parents

- [ea70a983ba54efe1d73b85d393596dcb98e19c02](https://git.cafe/gitcafe/zig/commit/ea70a983ba54efe1d73b85d393596dcb98e19c02?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/21236c015140cbb1061e6161faa8011915d15de3?format=markdown)
