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 {...@@ -1836,10 +1836,14 @@ fn tryFindProgram(b: *Build, full_path: []const u8) ?[]const u8 {
1836 if (b.graph.environ_map.get("PATHEXT")) |PATHEXT| {1836 if (b.graph.environ_map.get("PATHEXT")) |PATHEXT| {
1837 var it = mem.tokenizeScalar(u8, PATHEXT, fs.path.delimiter);1837 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
1839 while (it.next()) |ext| {1842 while (it.next()) |ext| {
1840 if (!supportedWindowsProgramExtension(ext)) continue;1843 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
1844 if (Io.Dir.cwd().access(io, extended_path, .{ .execute = true })) |_| {1848 if (Io.Dir.cwd().access(io, extended_path, .{ .execute = true })) |_| {
1845 return extended_path;1849 return extended_path;
...@@ -2708,4 +2712,5 @@ test {...@@ -2708,4 +2712,5 @@ test {
2708 _ = Cache;2712 _ = Cache;
2709 _ = Step;2713 _ = Step;
2710 _ = Configuration;2714 _ = Configuration;
2715 _ = &findProgram;
2711}2716}
lib/std/process.zig+9-1
...@@ -315,7 +315,15 @@ pub fn replacePath(io: Io, dir: Io.Dir, options: ReplaceOptions) ReplaceError {...@@ -315,7 +315,15 @@ pub fn replacePath(io: Io, dir: Io.Dir, options: ReplaceOptions) ReplaceError {
315pub const ArgExpansion = enum { expand, no_expand };315pub const ArgExpansion = enum { expand, no_expand };
316316
317/// File name extensions supported natively by `CreateProcess()` on Windows.317/// 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
320pub const SpawnError = error{328pub const SpawnError = error{
321 /// The operating system does not support creating child processes.329 /// The operating system does not support creating child processes.