commit 1042cbe0100ba0fbd8265f975c49356d31e4bd91 (tree)
parent be07f95cd7e543abdcc06292892eb57ee1b83153
Author: Ryan Liptak <squeek502@hotmail.com>
Date: Sun, 7 Jun 2026 20:58:45 -0700
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
Diffstat:
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/lib/std/Build.zig b/lib/std/Build.zig
@@ -1836,10 +1836,14 @@ fn tryFindProgram(b: *Build, full_path: []const u8) ?[]const u8 {
if (b.graph.environ_map.get("PATHEXT")) |PATHEXT| {
var it = mem.tokenizeScalar(u8, PATHEXT, fs.path.delimiter);
+ const extended_path_buf = arena.alloc(u8, full_path.len + 1 + std.process.WindowsExtension.max_len) catch @panic("OOM");
+ @memcpy(extended_path_buf[0..full_path.len], full_path);
+
while (it.next()) |ext| {
if (!supportedWindowsProgramExtension(ext)) continue;
- const extended_path = try mem.concat(arena, u8, &.{ full_path, ext });
+ @memcpy(extended_path_buf[full_path.len..][0..ext.len], ext);
+ const extended_path = extended_path_buf[0 .. full_path.len + ext.len];
if (Io.Dir.cwd().access(io, extended_path, .{ .execute = true })) |_| {
return extended_path;
@@ -2708,4 +2712,5 @@ test {
_ = Cache;
_ = Step;
_ = Configuration;
+ _ = &findProgram;
}
diff --git a/lib/std/process.zig b/lib/std/process.zig
@@ -315,7 +315,15 @@ pub fn replacePath(io: Io, dir: Io.Dir, options: ReplaceOptions) ReplaceError {
pub const ArgExpansion = enum { expand, no_expand };
/// File name extensions supported natively by `CreateProcess()` on Windows.
-pub const WindowsExtension = enum { bat, cmd, com, exe };
+pub const WindowsExtension = enum {
+ bat,
+ cmd,
+ com,
+ exe,
+
+ /// Length of the longest supported extension (in ASCII characters)
+ pub const max_len = 3;
+};
pub const SpawnError = error{
/// The operating system does not support creating child processes.