zig icon indicating copy to clipboard operation
zig copied to clipboard

fix(std.build.RunStep.addArgs): ignore empty arguments

Open wooster0 opened this issue 1 year ago • 0 comments

A primary use case for this is that I can easily conditionally not add an argument. This demonstrates roughly what I want to do in my build.zig:

    b.getInstallStep().dependOn(
        &b.addSystemCommand(
            &[_][]const u8{
                "zig",
                "build-exe",
                "x.zig",
                if (exe.build_mode == .Debug) "" else "-Drelease-fast",
            },
        ).step,
    );

This currently results in this:

error: unrecognized file extension of parameter ''
The following command exited with error code 1 (expected 0):

While this looks somewhat readable, I've had cases where the error was quite consfusing. I would expect an empty argument to not do or add anything, which is now the case, so the above works as expected.

While we could also use optionals for this, I think it's easier to just assign meaning to empty strings.

wooster0 avatar Oct 23 '22 15:10 wooster0