#Is there a way to have zig build print the stderr of failed run steps?

1 messages · Page 1 of 1 (latest)

magic valve
#

I have a build.shaders.zig file in my project that runs the sokol-shdc compiler against all my shaders, producing .glsl.zig sources. I have a hot-reload feature that re-runs zig build against this file while the game is running, the reads the .glsl.zig files, pulls the glsl source out, and reloads the shaders. This all works fine, however if there is a compile error I want to display the error in-game.

I'm currently displaying the stderr of the zig build command, and it used to print the stderr of run steps, but this is no longer the case.

I see there is a captureStdErr() function where I can get a lazy path to the captured stderr and then put it somewhere, but is it possible to just output the runstep's stderr to zig build's stderr?

#

Example of the UI in-game - I need to actually run the cmd c:\Users\kcbanner\projects\ion\deps/bin/win32/sokol-shdc.exe -l glsl330 -f sokol_zig -i C:\Users\kcbanner\projects\ion\game\resources\shaders\deferred_shading.glsl -o zig-cache\tmp\1e0b7377068c866d\deferred_shading.glsl.zig to see the glsl compile error.

magic valve
#

Actually, looks like you can't install the stderr file in the failure case as it depends on the command running successfully

weak marlin
#

I see stderr right before the top level step name:

$ cat build.zig
const std = @import("std");
pub fn build(b: *std.Build) void {
    b.default_step.dependOn(&b.addSystemCommand(&.{ "grep", "\\(" }).step);
    b.default_step.dependOn(&b.addRunArtifact(b.addExecutable(.{
        .name = "repro",
        .root_source_file = .{ .path = "repro.zig" },
        .target = b.resolveTargetQuery(.{}),
    })).step);
}
$ cat repro.zig
const std = @import("std");
pub fn main() !void {
    try std.io.getStdErr().writer().writeAll("stderr\n");
    std.os.exit(1);
}
$ zig build --summary all
grep: Unmatched ( or \(
install
└─ run grep failure
error: the following command exited with error code 2:
grep \( 
stderr
install
└─ run repro failure
error: the following command exited with error code 1:
zig-cache/o/a0853fc8d8c4f9140c025b731fa0c8d3/repro 
Build Summary: 1/4 steps succeeded; 2 failed
install transitive failure
├─ run grep failure
└─ run repro failure
   └─ zig build-exe repro Debug native cached 11ms MaxRSS:68M
error: the following build command failed with exit code 1:
zig-cache/o/dd889fb465de3c0074b9d7301a294b63/build zig . repro/zig-cache ~/.cache/zig --seed 0x7345dc41 -Zdd76e9ba6844a9ec --summary all