Moving ZIG_LOCAL_CACHE_DIR -- is it safe?

Apparently zig build by default creates .zig-cache next to build.zig.

This is not ideal for me, because all my projects are synchronized, and the cache grows really fast, wasting space on all of the other machines. (And keeping syncthing more busy than it needs to be.) I could set up some ignore rules but Ideally I’d just like to have the cache somewhere outside my synced directory.

IIUC, the solution is to set ZIG_LOCAL_CACHE_DIR, but is it safe?

My thinking is, there must be a reason to have N local caches in the first place, right? (Actually, there’s already a global cache in ~/.cache/zig, so we end up with1 + N caches.)

So is there a risk from setting ZIG_LOCAL_CACHE_DIR globally and thus merging all local caches into one directory (perhaps even the same dir being already used by global cache)?

Moving the cache is safe.
Sharing a cache between projects should be fine, AFAIK
Try it, see what happens :3

Moving and removing the cache is safe, actually removing it at times is good if you update the compiler a lot as it will keep growing.

Note that tests currently hardcode tmpdir to .zig-cache https://github.com/ziglang/zig/blob/master/lib/std/testing.zig#L606

There’s open PR to address the issue but seems to be in limbo std.testing: make tmpDir respect ZIG_LOCAL_CACHE_DIR by 0x5a4 · Pull Request #20071 · ziglang/zig · GitHub

1 Like