From 5bf52a6f50a9fa0380499dd38a9826fc39c43f11 Mon Sep 17 00:00:00 2001 From: Carter Snook Date: Tue, 23 Sep 2025 20:12:28 -0500 Subject: [PATCH] std: always allow spawning processes when an env map is explicitly provided (#25092) In a library, the two `builtin.link_libc` and `builtin.output_mode == .Exe` checks could both be false. Thus, you would get a compile error even if you specified an `env_map` at runtime. This change turns the compile error into a runtime panic and updates the documentation to reflect the runtime requirement. --- lib/std/process/Child.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/std/process/Child.zig b/lib/std/process/Child.zig index bbc08ac0c9..02d7fd8d54 100644 --- a/lib/std/process/Child.zig +++ b/lib/std/process/Child.zig @@ -52,6 +52,8 @@ term: ?(SpawnError!Term), argv: []const []const u8, /// Leave as null to use the current env map using the supplied allocator. +/// Required if unable to access the current env map (e.g. building a library on +/// some platforms). env_map: ?*const EnvMap, stdin_behavior: StdIo, @@ -414,6 +416,8 @@ pub fn run(args: struct { argv: []const []const u8, cwd: ?[]const u8 = null, cwd_dir: ?fs.Dir = null, + /// Required if unable to access the current env map (e.g. building a + /// library on some platforms). env_map: ?*const EnvMap = null, max_output_bytes: usize = 50 * 1024, expand_arg0: Arg0Expand = .no_expand, @@ -614,7 +618,7 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void { })).ptr; } else { // TODO come up with a solution for this. - @compileError("missing std lib enhancement: ChildProcess implementation has no way to collect the environment variables to forward to the child process"); + @panic("missing std lib enhancement: ChildProcess implementation has no way to collect the environment variables to forward to the child process"); } };