I don’t think this is currently possible, but I am trying to compile a C++ project with zig build and would like it to be able to re-build things when I add .cpp files or add new sub-directories with .cpp files. Ideally, this can all happen while under zig build --watch. I know I can manually list source files and sub-directories for include paths, but I would really rather not do that as I’m more used to the makefile-style glob syntax for compiling an entire directory and sub-directories of cpp files.
Is this at all feasible? In my understanding, I can just dir.iterate() in the build.zig script, but since that only runs once during configuration, it doesnt update under --watch mode.
the word “include path” is i think a red herring here. include paths are for header files included by your source files. to me it sounds like what you is to gather all the cpp source files in a directory as source files. i believe you can do that by writing normal Zig code in your build.zig file. if the logic is sufficiently complicated you should consider writing an external script.
I think zig 0.17.0 will let you do it with Configure Cache Poisoning, specifically std.Build.dependOnDirectoryMetadata. That tells the ‘maker’ to rerun the ‘configurer’ if the directory contents changes. NB: it is not recursive.
That said, I recommend listing individual files. Unlike zig, C & C++ don’t have a mechanism for the compiler to determine what code is and isn’t used, so by listing them individually:
It makes it easy for other people reading your project to see what it’s doing.
Your build won’t fail because of a compile error in code you don’t use.