authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-03 03:17:01-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-04 00:27:09-08:00
loge2c04a46518f1c75076e642f56ae9d5bae3da3f3
tree8c2c5bd3a71aa4a0c06eda4d0ef9e78173d4eabe
parent2fee64ceb08328ccc9f98879a544eae971248493

fix some windows compilation errors


10 files changed, 41 insertions(+), 52 deletions(-)

lib/compiler/resinator/main.zig+1-1
......@@ -633,7 +633,7 @@ fn getIncludePaths(
633633 };
634634 const target = std.zig.resolveTargetQueryOrFatal(io, target_query);
635635 const is_native_abi = target_query.isNativeAbi();
636 const detected_libc = std.zig.LibCDirs.detect(arena, io, zig_lib_dir, &target, is_native_abi, true, null) catch {
636 const detected_libc = std.zig.LibCDirs.detect(arena, io, zig_lib_dir, &target, is_native_abi, true, null, environ_map) catch {
637637 if (includes == .any) {
638638 // fall back to mingw
639639 includes = .gnu;
lib/std/process/Environ.zig+5-2
......@@ -542,14 +542,17 @@ pub fn getPosix(environ: Environ, key: []const u8) ?[:0]const u8 {
542542/// * `contains`
543543pub fn getWindows(environ: Environ, key: [*:0]const u16) ?[:0]const u16 {
544544 comptime assert(native_os == .windows);
545 comptime assert(@TypeOf(environ.block) == void);
545546
546547 // '=' anywhere but the start makes this an invalid environment variable name.
547548 const key_slice = mem.sliceTo(key, 0);
548549 if (key_slice.len > 0 and mem.findScalar(u16, key_slice[1..], '=') != null) return null;
549550
551 const ptr = std.os.windows.peb().ProcessParameters.Environment;
552
550553 var i: usize = 0;
551 while (environ.block[i] != 0) {
552 const key_value = mem.sliceTo(environ.block[i..], 0);
554 while (ptr[i] != 0) {
555 const key_value = mem.sliceTo(ptr[i..], 0);
553556
554557 // There are some special environment variables that start with =,
555558 // so we need a special case to not treat = as a key/value separator
test/standalone/windows_argv/fuzz.zig+10-14
......@@ -3,19 +3,15 @@ const builtin = @import("builtin");
33const windows = std.os.windows;
44const Allocator = std.mem.Allocator;
55
6pub fn main() !void {
7 var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
8 defer std.debug.assert(gpa.deinit() == .ok);
9 const allocator = gpa.allocator();
10
11 const args = try std.process.argsAlloc(allocator);
12 defer std.process.argsFree(allocator, args);
6pub fn main(init: std.process.Init) !void {
7 const gpa = init.gpa;
8 const args = try init.minimal.args.toSlice(init.arena.allocator());
139
1410 if (args.len < 2) return error.MissingArgs;
1511
1612 const verify_path_wtf8 = args[1];
17 const verify_path_w = try std.unicode.wtf8ToWtf16LeAllocZ(allocator, verify_path_wtf8);
18 defer allocator.free(verify_path_w);
13 const verify_path_w = try std.unicode.wtf8ToWtf16LeAllocZ(gpa, verify_path_wtf8);
14 defer gpa.free(verify_path_w);
1915
2016 const iterations: u64 = iterations: {
2117 if (args.len < 3) break :iterations 0;
......@@ -41,14 +37,14 @@ pub fn main() !void {
4137 std.debug.print("rand seed: {}\n", .{seed});
4238 }
4339
44 var cmd_line_w_buf = std.array_list.Managed(u16).init(allocator);
40 var cmd_line_w_buf = std.array_list.Managed(u16).init(gpa);
4541 defer cmd_line_w_buf.deinit();
4642
4743 var i: u64 = 0;
4844 var errors: u64 = 0;
4945 while (iterations == 0 or i < iterations) {
50 const cmd_line_w = try randomCommandLineW(allocator, rand);
51 defer allocator.free(cmd_line_w);
46 const cmd_line_w = try randomCommandLineW(gpa, rand);
47 defer gpa.free(cmd_line_w);
5248
5349 // avoid known difference for 0-length command lines
5450 if (cmd_line_w.len == 0 or cmd_line_w[0] == '\x00') continue;
......@@ -56,8 +52,8 @@ pub fn main() !void {
5652 const exit_code = try spawnVerify(verify_path_w, cmd_line_w);
5753 if (exit_code != 0) {
5854 std.debug.print(">>> found discrepancy <<<\n", .{});
59 const cmd_line_wtf8 = try std.unicode.wtf16LeToWtf8Alloc(allocator, cmd_line_w);
60 defer allocator.free(cmd_line_wtf8);
55 const cmd_line_wtf8 = try std.unicode.wtf16LeToWtf8Alloc(gpa, cmd_line_w);
56 defer gpa.free(cmd_line_wtf8);
6157 std.debug.print("\"{f}\"\n\n", .{std.zig.fmtString(cmd_line_wtf8)});
6258
6359 errors += 1;
test/standalone/windows_argv/lib.zig+5-2
......@@ -5,7 +5,7 @@ export fn verify(argc: c_int, argv: [*]const [*:0]const u16) c_int {
55 const argv_slice = argv[0..@intCast(argc)];
66 testArgv(argv_slice) catch |err| switch (err) {
77 error.OutOfMemory => @panic("oom"),
8 error.Overflow => @panic("bytes needed to contain args would overflow usize"),
8 error.Unexpected => @panic("unexpected error"),
99 error.ArgvMismatch => return 0,
1010 };
1111 return 1;
......@@ -16,7 +16,10 @@ fn testArgv(expected_args: []const [*:0]const u16) !void {
1616 defer arena_state.deinit();
1717 const allocator = arena_state.allocator();
1818
19 const args = try std.process.argsAlloc(allocator);
19 const cmd_line = std.os.windows.peb().ProcessParameters.CommandLine;
20 const cmd_line_w = cmd_line.Buffer.?[0..@divExact(cmd_line.Length, 2)];
21 const raw_args: std.process.Args = .{ .vector = cmd_line_w };
22 const args = try raw_args.toSlice(allocator);
2023 var wtf8_buf = std.array_list.Managed(u8).init(allocator);
2124
2225 var eql = true;
test/standalone/windows_bat_args/echo-args.zig+4-7
......@@ -1,15 +1,12 @@
11const std = @import("std");
22
3pub fn main() !void {
4 var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator);
5 defer arena_state.deinit();
6 const arena = arena_state.allocator();
7
8 const io = std.Options.debug_io;
3pub fn main(init: std.process.Init) !void {
4 const arena = init.arena.allocator();
5 const io = init.io;
6 const args = try init.minimal.args.toSlice(arena);
97
108 var stdout_writer = std.Io.File.stdout().writerStreaming(io, &.{});
119 const stdout = &stdout_writer.interface;
12 var args = try std.process.argsAlloc(arena);
1310 for (args[1..], 1..) |arg, i| {
1411 try stdout.writeAll(arg);
1512 if (i != args.len - 1) try stdout.writeByte('\x00');
test/standalone/windows_bat_args/fuzz.zig+1-1
......@@ -8,7 +8,7 @@ pub fn main(init: std.process.Init) !void {
88 const gpa = init.gpa;
99 const io = init.io;
1010
11 var it = try init.minimal.argsAllocator(gpa);
11 var it = try init.minimal.args.iterateAllocator(gpa);
1212 defer it.deinit();
1313 _ = it.next() orelse unreachable; // skip binary name
1414 const child_exe_path_orig = it.next() orelse unreachable;
test/standalone/windows_bat_args/test.zig+2-2
......@@ -6,7 +6,7 @@ pub fn main(init: std.process.Init) !void {
66 const gpa = init.gpa;
77 const io = init.io;
88
9 var it = try init.minimal.argsAllocator(gpa);
9 var it = try init.minimal.args.iterateAllocator(gpa);
1010 defer it.deinit();
1111 _ = it.next() orelse unreachable; // skip binary name
1212 const child_exe_path_orig = it.next() orelse unreachable;
......@@ -105,7 +105,7 @@ pub fn main(init: std.process.Init) !void {
105105 try std.testing.expectError(error.FileNotFound, testExecBat(gpa, io, absolute_with_trailing, &.{"abc"}, null));
106106
107107 var env = env: {
108 var env = try std.process.getEnvMap(gpa);
108 var env = try init.environ_map.clone(gpa);
109109 errdefer env.deinit();
110110 // No escaping
111111 try env.put("FOO", "123");
test/standalone/windows_paths/relative.zig+6-13
......@@ -1,21 +1,14 @@
11const std = @import("std");
22
3pub fn main() !void {
4 var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
5 defer std.debug.assert(gpa.deinit() == .ok);
6 const allocator = gpa.allocator();
7
8 const args = try std.process.argsAlloc(allocator);
9 defer std.process.argsFree(allocator, args);
3pub fn main(init: std.process.Init) !void {
4 const arena = init.arena.allocator();
5 const args = try init.minimal.args.toSlice(arena);
6 const io = init.io;
7 const cwd_path = try std.process.getCwdAlloc(arena);
108
119 if (args.len < 3) return error.MissingArgs;
1210
13 var threaded: std.Io.Threaded = .init(allocator, .{});
14 defer threaded.deinit();
15 const io = threaded.io();
16
17 const relative = try std.fs.path.relative(allocator, args[1], args[2]);
18 defer allocator.free(relative);
11 const relative = try std.fs.path.relative(arena, cwd_path, init.environ_map, args[1], args[2]);
1912
2013 var stdout_writer = std.Io.File.stdout().writerStreaming(io, &.{});
2114 const stdout = &stdout_writer.interface;
test/standalone/windows_paths/test.zig+4-8
......@@ -1,17 +1,13 @@
11const std = @import("std");
22const Io = std.Io;
33
4pub fn main() anyerror!void {
5 var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator);
6 defer arena_state.deinit();
7 const arena = arena_state.allocator();
8
9 const args = try std.process.argsAlloc(arena);
4pub fn main(init: std.process.Init) !void {
5 const arena = init.arena.allocator();
6 const args = try init.minimal.args.toSlice(arena);
7 const io = init.io;
108
119 if (args.len < 2) return error.MissingArgs;
1210
13 const io = std.Io.Threaded.global_single_threaded.ioBasic();
14
1511 const exe_path = args[1];
1612
1713 const cwd_path = try std.process.getCwdAlloc(arena);
test/standalone/windows_spawn/main.zig+3-2
......@@ -8,8 +8,9 @@ const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral;
88pub fn main(init: std.process.Init) !void {
99 const gpa = init.gpa;
1010 const io = init.io;
11 const process_cwd_path = try std.process.getCwdAlloc(init.arena.allocator());
1112
12 var it = try init.minimal.argsAllocator(gpa);
13 var it = try init.minimal.args.iterateAllocator(gpa);
1314 defer it.deinit();
1415 _ = it.next() orelse unreachable; // skip binary name
1516 const hello_exe_cache_path = it.next() orelse unreachable;
......@@ -23,7 +24,7 @@ pub fn main(init: std.process.Init) !void {
2324 defer gpa.free(tmp_absolute_path_w);
2425 const cwd_absolute_path = try Io.Dir.cwd().realPathFileAlloc(io, ".", gpa);
2526 defer gpa.free(cwd_absolute_path);
26 const tmp_relative_path = try std.fs.path.relative(gpa, cwd_absolute_path, tmp_absolute_path);
27 const tmp_relative_path = try std.fs.path.relative(gpa, process_cwd_path, init.environ_map, cwd_absolute_path, tmp_absolute_path);
2728 defer gpa.free(tmp_relative_path);
2829
2930 // Clear PATH