Subdirectories under a project's .zig-cache

For zigclc I cache the parsed results of running zig build --help, so I can more quickly present the completions for build steps, system integrations and project options, as they all depend on build.zig and I don’t want to run zig build --help every time you press TAB.

Originally I put the parsed info in a file .zig_build.txt (next to build.zig/build.zig.zon), but since I need to cache some more stuff in different files I now store this in a .zigclc subdirectory. Both these solution have the same problem: you need to add them to your VCS’ ignore file (.hgignore, .gitignore, .csvignore, …) otherwise your VCS will nag you about them when you query its status (to be clear: you shouldn’t put that cached information in your VCS).

I expect that most developers already have .zig-cache in their ignore file, and if I would just add a subdirectory .zig-cache/zigclc under that, and store my stuff there, users would not have to add another file/directory to their ignore file.

Is it acceptable to create subdirectories in .zig-cache? Is there some information on what goes in which directories under .zig-cache? It seems to have c, h, o, tmp, and z (sometimes a few more) but it is not clear what not to use (e.g. no single character directory names)? I don’t want to add a directory there and then find out that it breaks compilation of some projects, or gets in the way of future extensions.

if you pick a name that is unlikely to be used by the compiler, I don’t see any problem with it

1 Like

I actually use some form of std.testing.TmpDir to create a unique tmp folder for file-creating during tests: TempDir

Maybe that is similar to what you need / want to do:

I create the a folder with a reasonable unique name and everything else (file creation / deletion) takes place in there.
Afterwards I clean up, although as long as you avoid collision, you can also keep your temp folders. They just stack up unless you have some deterministic naming schema.

I don’t necessarily want something temporary, if the build.zig doesn’t change I’ll be happy to continue to use the cached data indefinately.

I looked at your code, and realise I never looked beyond createDirPath() and open separately instead of using openDirPathOpen().

One thing I noticed is that you seem to assume your program runs in the directory where the .zig-cache dir is located (or normally would be created). I don’t do that, I go up the tree to find build.zig ( and verify that either build.zig.zon is there, or that pub fn build is at the start of a line in that file ) and create/use .zig-cache next to that file. I do that because you can run zig build etc. from any subdirectory in the project, so I need to accomodate hat for command-line completion for the zig compiler.