Zig caches every build globally and per project, and neither clears itself
Zig keeps a global cache in ~/.cache/zig and a .zig-cache in each project. How big they get and how to clear them safely.
Zig's build system caches aggressively, which is why incremental builds are fast. There are two caches: a global one shared by all projects, and one in each project. Neither has a size limit.
du -sh ~/.cache/zig 2>/dev/null
find ~ -maxdepth 4 -type d \( -name .zig-cache -o -name zig-cache \) -prune -exec du -sh {} + 2>/dev/null | sort -hNewer Zig versions name the project cache .zig-cache; older ones used zig-cache. Build output goes to zig-out.
Clear them
rm -rf ~/.cache/zig
# In a project
rm -rf .zig-cache zig-cache zig-outThe next build takes longer while the caches refill. Old Zig versions from a version manager are covered in version managers.
Common questions
Where is the Zig cache on a Mac?
The global cache is in ~/.cache/zig, and each project has a .zig-cache folder, or zig-cache in older versions.
Is it safe to delete the Zig cache?
Yes. It only holds build results. The next build rebuilds what it needs.
Does the Zig cache have a size limit?
No. It grows until you clear it.