diff --git a/lib/std/Build.zig b/lib/std/Build.zig index ec552b98ed2bed478aef81c77c0549a12d6075aa..798729533c70421c8c5126a22540341f3129091d 100644 --- 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 index bcee558a65eef07afab17b484cc012326bb5004c..f3ef291763d642426770883e886c8a5a50aeae41 100644 --- 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.