authorgravatar for cartersnook04@gmail.comCarter Snook <cartersnook04@gmail.com> 2025-09-23 20:12:28-05:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-09-24 03:50:16+02:00
log6069f908e9f1f8655af3faca3bd6de99de58af16
tree1495145c3edf2e55d014858ccc16ee7780459b81
parente526d65f5e11df3093cc2000611c9a6438f847fe
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

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.

1 files changed, 5 insertions(+), 1 deletions(-)

lib/std/process/Child.zig+5-1
...@@ -52,6 +52,8 @@ term: ?(SpawnError!Term),...@@ -52,6 +52,8 @@ term: ?(SpawnError!Term),
52argv: []const []const u8,52argv: []const []const u8,
5353
54/// Leave as null to use the current env map using the supplied allocator.54/// Leave as null to use the current env map using the supplied allocator.
55/// Required if unable to access the current env map (e.g. building a library on
56/// some platforms).
55env_map: ?*const EnvMap,57env_map: ?*const EnvMap,
5658
57stdin_behavior: StdIo,59stdin_behavior: StdIo,
...@@ -414,6 +416,8 @@ pub fn run(args: struct {...@@ -414,6 +416,8 @@ pub fn run(args: struct {
414 argv: []const []const u8,416 argv: []const []const u8,
415 cwd: ?[]const u8 = null,417 cwd: ?[]const u8 = null,
416 cwd_dir: ?fs.Dir = null,418 cwd_dir: ?fs.Dir = null,
419 /// Required if unable to access the current env map (e.g. building a
420 /// library on some platforms).
417 env_map: ?*const EnvMap = null,421 env_map: ?*const EnvMap = null,
418 max_output_bytes: usize = 50 * 1024,422 max_output_bytes: usize = 50 * 1024,
419 expand_arg0: Arg0Expand = .no_expand,423 expand_arg0: Arg0Expand = .no_expand,
...@@ -614,7 +618,7 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {...@@ -614,7 +618,7 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
614 })).ptr;618 })).ptr;
615 } else {619 } else {
616 // TODO come up with a solution for this.620 // TODO come up with a solution for this.
617 @compileError("missing std lib enhancement: ChildProcess implementation has no way to collect the environment variables to forward to the child process");621 @panic("missing std lib enhancement: ChildProcess implementation has no way to collect the environment variables to forward to the child process");
618 }622 }
619 };623 };
620624