Martin Cowie
Martin Cowie

Reputation: 2601

How to make Idiomatic calls to C code generator, within `build.zig`

I am feeling my way through a project that combines gSOAP with Zig: starting with 100% C then replacing it piece by piece with Zig.

Central to the project is using the gSOAP WSDL to C code generator. The Makefile paragraph to drive it is:

gen: addition.wsdl
    mkdir -p $@
    wsdl2h ./$< -c  -o $@/addition.h
    soapcpp2 -c -r -dgen/ $@/addition.h

The following piece of Zig is equivalent, but given it is so much larger, and must include code to ensure the order of command execution, I wonder - is there an easier and more idiomatic means of creating a subdirectory and then running two code generators in order?

    // Generate gSOAP artefacts
    {
        const wsdl_input = "addition.wsdl";
        const gen_step = b.step("gen", "Generate gSOAP artefacts");

        const gen_run0 = b.addSystemCommand(&.{ "mkdir", "-p", generated_sources });
        const gen_run1 = b.addSystemCommand(&.{ "wsdl2h", wsdl_input, "-c", "-o", generated_sources ++ "/addition.h" });
        const gen_run2 = b.addSystemCommand(&.{ "soapcpp2", "-c", "-r", "-d" ++ generated_sources, generated_sources ++ "/addition.h" });

        // Ensure the commands run in order .. not a given otherwise
        gen_run1.step.dependOn(&gen_run0.step);
        gen_run2.step.dependOn(&gen_run1.step);
        gen_step.dependOn(&gen_run2.step);

        b.default_step.dependOn(gen_step);
    }

Upvotes: 3

Views: 130

Answers (0)

Related Questions