How to diagnose build system cache misses?

I have a project that routinely rebuilds even when nothing in the source has changed. E.g. zig build && zig build will run compilation twice. rm -rf .zig-cache fixes the problem temporarily. What I’d like to know is if there’s an argument I can pass to zig build or a modification I can make to my build.zig that will help me narrow down what source file(s) are causing the cache misses.

Can you post the build.zig? That isn’t normal behavior, but it can be opted into with something like:

some_lib.has_side_effects = true;

I think that if one of your dependencies has that flag set, that every zig build will rebuild that library. I’ve only used it for test builds, so I can time them with a second run without including compilation time in the run.