I’m looking for a way to record which options were used to build an executable so I can print it out in debug logs. That way it’ll be easier to replicate builds from bug reports. The reporter can attach a log, and it would document how the build was done. I’m also going to capture the git hash, but I think that’s fairly easy to do from within build.zig by calling out to git if available.
What I’m thinking is something which would record zig build’s command line. I tried to read argv, but the process whilst performing the build isn’t the zig build process I started from the command line. It’s a child of it, and so doesn’t have the relevant information.
Is there something else I could use to get this information?
My current build.zig is simple enough. It’s below, with a lot of options removed just to cut down on size.
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const threads = b.option(u16, "THREADS", "How many threads to use") orelse 1;
const debug = b.option(bool, "DEBUG", "Enable debug output") orelse false;
const options = b.addOptions();
options.addOption(u16, "threads", threads);
options.addOption(bool, "debug", debug);
options.addOption([] const u8, "buildString", ???????); // What to pass in here.
const exe = b.addExecutable(.{
.name = "blah",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
.use_llvm = true,
});
exe.root_module.addOptions("config", options);
b.installArtifact(exe);
}