ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.47k stars 2.52k forks source link

std.process.Child.run failing depending on Release options #21756

Open SHIPWECK opened 3 hours ago

SHIPWECK commented 3 hours ago

Zig Version

0.14.0-dev.719+f21928657

Steps to Reproduce and Observed Behavior

Create a file bug.zig and paste the following code:

const std = @import("std");

pub fn main() !void {
    var alloc = std.heap.page_allocator;

    const run_result = try std.process.Child.run(.{
        .allocator = alloc,
        .argv = &.{ "zig", "version" },
    });

    defer {
        alloc.free(run_result.stderr);
        alloc.free(run_result.stdout);
    }

    std.debug.print("{s}", .{run_result.stdout});
}

test "Child.run" {
    var alloc = std.heap.page_allocator;

    const run_result = try std.process.Child.run(.{
        .allocator = alloc,
        .argv = &.{ "zig", "version" },
    });

    defer {
        alloc.free(run_result.stderr);
        alloc.free(run_result.stdout);
    }

    try std.testing.expectEqualStrings(
        "0.14.0-dev.719+f21928657\n",
        run_result.stdout,
    );
}

Commands and output are listed below:

PS> zig run bug.zig -ODebug
0.14.0-dev.719+f21928657
PS> zig run bug.zig -OReleaseSafe
0.14.0-dev.719+f21928657
PS> zig run bug.zig -OReleaseSmall
error:
PS> zig run bug.zig -OReleaseFast
error:
PS> zig test bug.zig -ODebug
All 1 tests passed.
PS> zig test bug.zig -OReleaseSafe
All 1 tests passed.
PS> zig test bug.zig -OReleaseSmall
All 1 tests passed.
PS> zig test bug.zig -OReleaseFast
1/1 bug.test.Child.run...FAIL ()
0 passed; 0 skipped; 1 failed.
error: the following test command failed with exit code 1:
C:\Users\____\AppData\Local\zig\o\f08007e9b8d201450c8ddf23221d5620\test.exe --seed=0x21fb9850

Expected Behavior

Identical output on all release modes on which should be the zig version: 0.14.0-dev.719+f21928657.

rohlem commented 2 hours ago

What windows version (and CPU architecture) did you test this on?

I ran the test on Windows 11 Home Version 21H2. Using zig version 0.14.0-dev.1924+bdd3bc056, after adjusting the hardcoded version string, the only error I could reproduce was the empty error: output using zig run -OReleaseSmall. All other combinations/commands worked without issue.

Can you maybe check with a newer nightly build whether other configurations still fail on your system?