authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-06-07 20:58:45-07:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-06-07 23:27:01-07:00
log1042cbe0100ba0fbd8265f975c49356d31e4bd91
tree2e57b2320cdaf9764ca85c48a22707c397ecc193
parentbe07f95cd7e543abdcc06292892eb57ee1b83153

Build: fix tryFindProgram on Windows and reintroduce ref in test block

Also reduce the amount of unnecessary allocations, since one buffer can be used for appending all supported PATHEXT extensions Fixes #35668

2 files changed, 15 insertions(+), 2 deletions(-)

lib/std/Build.zig+6-1
......@@ -1836,10 +1836,14 @@ fn tryFindProgram(b: *Build, full_path: []const u8) ?[]const u8 {
18361836 if (b.graph.environ_map.get("PATHEXT")) |PATHEXT| {
18371837 var it = mem.tokenizeScalar(u8, PATHEXT, fs.path.delimiter);
18381838
1839 const extended_path_buf = arena.alloc(u8, full_path.len + 1 + std.process.WindowsExtension.max_len) catch @panic("OOM");
1840 @memcpy(extended_path_buf[0..full_path.len], full_path);
1841
18391842 while (it.next()) |ext| {
18401843 if (!supportedWindowsProgramExtension(ext)) continue;
18411844
1842 const extended_path = try mem.concat(arena, u8, &.{ full_path, ext });
1845 @memcpy(extended_path_buf[full_path.len..][0..ext.len], ext);
1846 const extended_path = extended_path_buf[0 .. full_path.len + ext.len];
18431847
18441848 if (Io.Dir.cwd().access(io, extended_path, .{ .execute = true })) |_| {
18451849 return extended_path;
......@@ -2708,4 +2712,5 @@ test {
27082712 _ = Cache;
27092713 _ = Step;
27102714 _ = Configuration;
2715 _ = &findProgram;
27112716}
lib/std/process.zig+9-1
......@@ -315,7 +315,15 @@ pub fn replacePath(io: Io, dir: Io.Dir, options: ReplaceOptions) ReplaceError {
315315pub const ArgExpansion = enum { expand, no_expand };
316316
317317/// File name extensions supported natively by `CreateProcess()` on Windows.
318pub const WindowsExtension = enum { bat, cmd, com, exe };
318pub const WindowsExtension = enum {
319 bat,
320 cmd,
321 com,
322 exe,
323
324 /// Length of the longest supported extension (in ASCII characters)
325 pub const max_len = 3;
326};
319327
320328pub const SpawnError = error{
321329 /// The operating system does not support creating child processes.