Ok, that helps me get the picture, thanks.
What about something like this?
_ = b.addNamespaceModule("build_helper", .{
.target = target,
.optimize = .optimize,
.root_namespace = build_helpers,
});
Then outside of the build function itself:
const build_helpers = struct {
// Put the build module namespace here
};
Kind of hand-wavey, but this could be imported in anyone else’s build.zig
and do things.
My problem every time I try to do something non-trivial with the build system is the near total lack of documentation. I end up spending a lot of time reviewing the doc comments and source code just to figure out what’s even potentially possible, and that has limits. Much of what I’ve figured out how to do is just cargo-culted from other people’s build files.
For instance, I don’t understand how you’re able to @import("sokol")
within build.zig
in that first link. Does the build system just let you do an import of anything in the build.zig.zon
, as a treat?
How is someone supposed to figure that out? Is it line 2541 of Build.zig
where you discover that? Because it isn’t the documentation.
I just figured out that I can export a lazy path from a dependency, which is handy, I was able to update ZTAP so that users can import the sample test runner from there and don’t have to make a separate source file in their own repos. I found that little affordance at random, while researching something else (a something else I was not able to find a way to do, btw).
But it sure would be nice if there were some documents available. The official docs don’t even cover importing dependencies, which is, frankly, pathetic.