Code Generation in Zig
Zig’s build system is configured by constructing a graph of build steps (std.Build.Step). This allows us a nifty way to compile and run code generators.
pub fn addGenerator(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Step.WriteFile { const gen_exe = b.addExecutable(.{ .name = "gen", .root_source_file = b.path("<file path relative to source root>"), .target = target, .optimize = optimize, }); const run_gen = b.addRunArtifact(gen_exe); run_gen.step.dependOn(&gen_exe.step); run_gen.addFileArg(b.path("<file path relative to source root>")); const output_cache_path = run_gen.
2024-10-01