Port a make rule to build.zig (wayland codegen)

i have a script gen.py that accepts xml files and outputs zig code

so a make rule for that would be:

wp.zig: gen.py $(WAYLAND_PROTOCOLS)
    ./gen.py $(WAYLAND_PROTOCOLS) >wp.zig

how can i write that in build.zig?

Assuming gen.py ouputs source code to stdout.

const gen_py = b.addSystemCommand(&.{"./gen.py"});
gen_py.addFileArg(.{ .path = "one.xml" });
gen_py.addFileArg(.{ .path = "two.xml" });
// ...
const wp_zig = gen_py.captureStdOut();

const some_module_or_whatever = b.addModule("wp", .{
    .root_source_file = wp_zig,

thank you!! just wondering if @import("wl.zig") inside wp.zig wouldn’t break here?

Yes, that would break. You would need to expose wl as a module and have the wp module import it using @import("wl"), i.e.

// ...
const wp_mod = b.addModule("wp", .{
    .root_source_file = wp_zig,

const wl_mod = b.addModule("wl", .{
    .root_source_file = .{ .path = "wl.zig" },
wp_mod.addImport("wl", wl_mod);