authorgravatar for cartersnook04@gmail.comCarter Snook <cartersnook04@gmail.com> 2025-09-23 20:12:28-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-09-24 03:12:28+02:00
log5bf52a6f50a9fa0380499dd38a9826fc39c43f11
treedabb61650c578de79f2fa07128e5a80b334ae5b1
parentbc512648dbb27d895e69857202b22bc34d27f122
signaturebadge-check Signed by PGP key B5690EEEBB952194

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),
5252argv: []const []const u8,
5353
5454/// 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).
5557env_map: ?*const EnvMap,
5658
5759stdin_behavior: StdIo,
......@@ -414,6 +416,8 @@ pub fn run(args: struct {
414416 argv: []const []const u8,
415417 cwd: ?[]const u8 = null,
416418 cwd_dir: ?fs.Dir = null,
419 /// Required if unable to access the current env map (e.g. building a
420 /// library on some platforms).
417421 env_map: ?*const EnvMap = null,
418422 max_output_bytes: usize = 50 * 1024,
419423 expand_arg0: Arg0Expand = .no_expand,
......@@ -614,7 +618,7 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
614618 })).ptr;
615619 } else {
616620 // 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");
618622 }
619623 };
620624