authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-02 18:46:25-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-04 00:27:08-08:00
log4afed3e9ef83724bdfddd1d06b7727acda55e642
tree5b208954088cea6efd753ac4c6b4dd110b916487
parente149c0e2aa9e35ce90760ebef158bb05f3a74d0d

test-standalone: update the rest of the cases to new API


8 files changed, 53 insertions(+), 66 deletions(-)

lib/compiler/objcopy.zig+4-14
......@@ -17,20 +17,10 @@ var stdout_buffer: [1024]u8 = undefined;
1717var input_buffer: [1024]u8 = undefined;
1818var output_buffer: [1024]u8 = undefined;
1919
20pub fn main() !void {
21 var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
22 defer arena_instance.deinit();
23 const arena = arena_instance.allocator();
24
25 var general_purpose_allocator: std.heap.GeneralPurposeAllocator(.{}) = .init;
26 const gpa = general_purpose_allocator.allocator();
27
28 var threaded: std.Io.Threaded = .init(gpa, .{});
29 defer threaded.deinit();
30 const io = threaded.io();
31
32 const args = try std.process.argsAlloc(arena);
33 return cmdObjCopy(arena, io, args[1..]);
20pub fn main(init: std.process.Init) !void {
21 const arena = init.arena.allocator();
22 const args = try init.minimal.args.toSlice(arena);
23 return cmdObjCopy(arena, init.io, args[1..]);
3424}
3525
3626fn cmdObjCopy(arena: Allocator, io: Io, args: []const []const u8) !void {
test/standalone/child_process/main.zig+8-2
......@@ -9,6 +9,12 @@ pub fn main(init: std.process.Init.Minimal) !void {
99 };
1010 const gpa = gpa_state.allocator();
1111
12 const process_cwd_path = try std.process.getCwdAlloc(gpa);
13 defer gpa.free(process_cwd_path);
14
15 var env_map = try init.environ.createMap(gpa);
16 defer env_map.deinit();
17
1218 var it = try init.args.iterateAllocator(gpa);
1319 defer it.deinit();
1420 _ = it.next() orelse unreachable; // skip binary name
......@@ -17,7 +23,7 @@ pub fn main(init: std.process.Init.Minimal) !void {
1723 const cwd_path = it.next() orelse break :child_path .{ child_path, false };
1824 // If there is a third argument, it is the current CWD somewhere within the cache directory.
1925 // In that case, modify the child path in order to test spawning a path with a leading `..` component.
20 break :child_path .{ try std.fs.path.relative(gpa, cwd_path, child_path), true };
26 break :child_path .{ try std.fs.path.relative(gpa, process_cwd_path, &env_map, cwd_path, child_path), true };
2127 };
2228 defer if (needs_free) gpa.free(child_path);
2329
......@@ -28,7 +34,7 @@ pub fn main(init: std.process.Init.Minimal) !void {
2834 defer threaded.deinit();
2935 const io = threaded.io();
3036
31 var child = try std.process.spawn(.{
37 var child = try std.process.spawn(io, .{
3238 .argv = &.{ child_path, "hello arg" },
3339 .stdin = .pipe,
3440 .stdout = .pipe,
test/standalone/empty_env/main.zig+1-1
......@@ -1,5 +1,5 @@
11const std = @import("std");
22
33pub fn main(init: std.process.Init) !void {
4 try std.testing.expect(init.env_map.count() == 0);
4 try std.testing.expectEqual(0, init.env_map.count());
55}
test/standalone/env_vars/main.zig+5-5
......@@ -104,20 +104,20 @@ pub fn main(init: std.process.Init) !void {
104104 // getAlloc
105105 {
106106 try std.testing.expectEqualSlices(u8, "123", try environ.getAlloc(arena, "FOO"));
107 try std.testing.expectError(error.EnvironmentVariableNotFound, environ.getAlloc(arena, "FOO="));
108 try std.testing.expectError(error.EnvironmentVariableNotFound, environ.getAlloc(arena, "FO"));
109 try std.testing.expectError(error.EnvironmentVariableNotFound, environ.getAlloc(arena, "FOOO"));
107 try std.testing.expectError(error.EnvironmentVariableMissing, environ.getAlloc(arena, "FOO="));
108 try std.testing.expectError(error.EnvironmentVariableMissing, environ.getAlloc(arena, "FO"));
109 try std.testing.expectError(error.EnvironmentVariableMissing, environ.getAlloc(arena, "FOOO"));
110110 if (builtin.os.tag == .windows) {
111111 try std.testing.expectEqualSlices(u8, "123", try environ.getAlloc(arena, "foo"));
112112 }
113113 try std.testing.expectEqualSlices(u8, "ABC=123", try environ.getAlloc(arena, "EQUALS"));
114 try std.testing.expectError(error.EnvironmentVariableNotFound, environ.getAlloc(arena, "EQUALS=ABC"));
114 try std.testing.expectError(error.EnvironmentVariableMissing, environ.getAlloc(arena, "EQUALS=ABC"));
115115 try std.testing.expectEqualSlices(u8, "non-ascii አማርኛ \u{10FFFF}", try environ.getAlloc(arena, "КИРиллИЦА"));
116116 if (builtin.os.tag == .windows) {
117117 try std.testing.expectEqualSlices(u8, "non-ascii አማርኛ \u{10FFFF}", try environ.getAlloc(arena, "кирИЛЛица"));
118118 }
119119 try std.testing.expectEqualSlices(u8, "", try environ.getAlloc(arena, "NO_VALUE"));
120 try std.testing.expectError(error.EnvironmentVariableNotFound, environ.getAlloc(arena, "NOT_SET"));
120 try std.testing.expectError(error.EnvironmentVariableMissing, environ.getAlloc(arena, "NOT_SET"));
121121 if (builtin.os.tag == .windows) {
122122 try std.testing.expectEqualSlices(u8, "hi", try environ.getAlloc(arena, "=HIDDEN"));
123123 try std.testing.expectEqualSlices(u8, "\xed\xa0\x80", try environ.getAlloc(arena, "INVALID_UTF16_\xed\xa0\x80"));
test/standalone/self_exe_symlink/create-symlink.zig+1-1
......@@ -9,7 +9,7 @@ pub fn main(init: std.process.Init) !void {
99 const exe_path = it.next() orelse unreachable;
1010 const symlink_path = it.next() orelse unreachable;
1111
12 const cwd = std.process.getCwdAlloc(init.arena.allocator());
12 const cwd = try std.process.getCwdAlloc(init.arena.allocator());
1313
1414 // If `exe_path` is relative to our cwd, we need to convert it to be relative to the dirname of `symlink_path`.
1515 const exe_rel_path = try std.fs.path.relative(gpa, cwd, init.env_map, std.fs.path.dirname(symlink_path) orelse ".", exe_path);
tools/fetch_them_macos_headers.zig+9-16
......@@ -6,13 +6,9 @@ const process = std.process;
66const assert = std.debug.assert;
77const fatal = std.process.fatal;
88const info = std.log.info;
9
10const Allocator = mem.Allocator;
9const Allocator = std.mem.Allocator;
1110const OsTag = std.Target.Os.Tag;
1211
13var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
14const gpa = general_purpose_allocator.allocator();
15
1612const Arch = enum {
1713 aarch64,
1814 x86_64,
......@@ -67,10 +63,11 @@ const usage =
6763;
6864
6965pub fn main(init: std.process.Init) !void {
70 const allocator = init.arena;
71 const args = try init.minimal.args.toSlice(allocator);
66 const io = init.io;
67 const arena = init.arena.allocator();
68 const args = try init.minimal.args.toSlice(arena);
7269
73 var argv = std.array_list.Managed([]const u8).init(allocator);
70 var argv = std.array_list.Managed([]const u8).init(arena);
7471 var sysroot: ?[]const u8 = null;
7572
7673 var args_iter = ArgsIterator{ .args = args[1..] };
......@@ -82,23 +79,19 @@ pub fn main(init: std.process.Init) !void {
8279 } else try argv.append(arg);
8380 }
8481
85 var threaded: Io.Threaded = .init(gpa, .{});
86 defer threaded.deinit();
87 const io = threaded.io();
88
8982 const sysroot_path = sysroot orelse blk: {
9083 const target = try std.zig.system.resolveTargetQuery(io, .{});
91 break :blk std.zig.system.darwin.getSdk(allocator, io, &target) orelse
84 break :blk std.zig.system.darwin.getSdk(arena, io, &target) orelse
9285 fatal("no SDK found; you can provide one explicitly with '--sysroot' flag", .{});
9386 };
9487
9588 var sdk_dir = try Dir.cwd().openDir(io, sysroot_path, .{});
9689 defer sdk_dir.close(io);
97 const sdk_info = try sdk_dir.readFileAlloc(io, "SDKSettings.json", allocator, .limited(std.math.maxInt(u32)));
90 const sdk_info = try sdk_dir.readFileAlloc(io, "SDKSettings.json", arena, .limited(std.math.maxInt(u32)));
9891
9992 const parsed_json = try std.json.parseFromSlice(struct {
10093 DefaultProperties: struct { MACOSX_DEPLOYMENT_TARGET: []const u8 },
101 }, allocator, sdk_info, .{ .ignore_unknown_fields = true });
94 }, arena, sdk_info, .{ .ignore_unknown_fields = true });
10295
10396 const version = Version.parse(parsed_json.value.DefaultProperties.MACOSX_DEPLOYMENT_TARGET) orelse
10497 fatal("don't know how to parse SDK version: {s}", .{
......@@ -114,7 +107,7 @@ pub fn main(init: std.process.Init) !void {
114107 .arch = arch,
115108 .os_ver = os_ver,
116109 };
117 try fetchTarget(allocator, io, argv.items, sysroot_path, target, version, tmp_dir);
110 try fetchTarget(arena, io, argv.items, sysroot_path, target, version, tmp_dir);
118111 }
119112}
120113
tools/gen_macos_headers_c.zig+1-1
......@@ -14,7 +14,7 @@ const usage =
1414;
1515
1616pub fn main(init: std.process.Init) !void {
17 const arena = init.arena;
17 const arena = init.arena.allocator();
1818 const io = init.io;
1919 const args = try init.minimal.args.toSlice(arena);
2020
tools/process_headers.zig+24-26
......@@ -127,16 +127,14 @@ const LibCVendor = enum {
127127 netbsd,
128128};
129129
130pub fn main() !void {
131 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
132 const allocator = arena.allocator();
133
134 var threaded: Io.Threaded = .init(allocator, .{});
135 defer threaded.deinit();
136 const io = threaded.io();
137
138 const args = try std.process.argsAlloc(allocator);
139 var search_paths = std.array_list.Managed([]const u8).init(allocator);
130pub fn main(init: std.process.Init) !void {
131 const arena = init.arena.allocator();
132 const io = init.io;
133 const args = try init.minimal.args.toSlice(arena);
134 const cwd_path = try std.process.getCwdAlloc(arena);
135 const env_map = init.env_map;
136
137 var search_paths = std.array_list.Managed([]const u8).init(arena);
140138 var opt_out_dir: ?[]const u8 = null;
141139 var opt_abi: ?[]const u8 = null;
142140
......@@ -172,7 +170,7 @@ pub fn main() !void {
172170 usageAndExit(args[0]);
173171 };
174172
175 const generic_name = try std.fmt.allocPrint(allocator, "generic-{s}", .{abi_name});
173 const generic_name = try std.fmt.allocPrint(arena, "generic-{s}", .{abi_name});
176174 const libc_targets = switch (vendor) {
177175 .glibc => &glibc_targets,
178176 .musl => &musl_targets,
......@@ -180,8 +178,8 @@ pub fn main() !void {
180178 .netbsd => &netbsd_targets,
181179 };
182180
183 var path_table = PathTable.init(allocator);
184 var hash_to_contents = HashToContents.init(allocator);
181 var path_table = PathTable.init(arena);
182 var hash_to_contents = HashToContents.init(arena);
185183 var max_bytes_saved: usize = 0;
186184 var total_bytes: usize = 0;
187185
......@@ -189,7 +187,7 @@ pub fn main() !void {
189187
190188 for (libc_targets) |libc_target| {
191189 const libc_dir = switch (vendor) {
192 .glibc => try std.zig.target.glibcRuntimeTriple(allocator, libc_target.arch, .linux, libc_target.abi),
190 .glibc => try std.zig.target.glibcRuntimeTriple(arena, libc_target.arch, .linux, libc_target.abi),
193191 .musl => std.zig.target.muslArchName(libc_target.arch, libc_target.abi),
194192 .freebsd => switch (libc_target.arch) {
195193 .arm => "armv7",
......@@ -221,7 +219,7 @@ pub fn main() !void {
221219 },
222220 };
223221
224 const dest_target = if (libc_target.dest) |dest| dest else try std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{
222 const dest_target = if (libc_target.dest) |dest| dest else try std.fmt.allocPrint(arena, "{s}-{s}-{s}", .{
225223 @tagName(libc_target.arch),
226224 switch (vendor) {
227225 .musl, .glibc => "linux",
......@@ -239,8 +237,8 @@ pub fn main() !void {
239237 => &[_][]const u8{ search_path, libc_dir, "usr", "include" },
240238 .musl => &[_][]const u8{ search_path, libc_dir, "usr", "local", "musl", "include" },
241239 };
242 const target_include_dir = try Dir.path.join(allocator, sub_path);
243 var dir_stack = std.array_list.Managed([]const u8).init(allocator);
240 const target_include_dir = try Dir.path.join(arena, sub_path);
241 var dir_stack = std.array_list.Managed([]const u8).init(arena);
244242 try dir_stack.append(target_include_dir);
245243
246244 while (dir_stack.pop()) |full_dir_name| {
......@@ -254,16 +252,16 @@ pub fn main() !void {
254252 var dir_it = dir.iterate();
255253
256254 while (try dir_it.next(io)) |entry| {
257 const full_path = try Dir.path.join(allocator, &[_][]const u8{ full_dir_name, entry.name });
255 const full_path = try Dir.path.join(arena, &[_][]const u8{ full_dir_name, entry.name });
258256 switch (entry.kind) {
259257 .directory => try dir_stack.append(full_path),
260258 .file, .sym_link => {
261 const rel_path = try Dir.path.relative(allocator, target_include_dir, full_path);
259 const rel_path = try Dir.path.relative(arena, cwd_path, env_map, target_include_dir, full_path);
262260 const max_size = 2 * 1024 * 1024 * 1024;
263 const raw_bytes = try Dir.cwd().readFileAlloc(io, full_path, allocator, .limited(max_size));
261 const raw_bytes = try Dir.cwd().readFileAlloc(io, full_path, arena, .limited(max_size));
264262 const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t");
265263 total_bytes += raw_bytes.len;
266 const hash = try allocator.alloc(u8, 32);
264 const hash = try arena.alloc(u8, 32);
267265 hasher = Blake3.init(.{});
268266 hasher.update(rel_path);
269267 hasher.update(trimmed);
......@@ -285,8 +283,8 @@ pub fn main() !void {
285283 }
286284 const path_gop = try path_table.getOrPut(rel_path);
287285 const target_to_hash = if (path_gop.found_existing) path_gop.value_ptr.* else blk: {
288 const ptr = try allocator.create(TargetToHash);
289 ptr.* = TargetToHash.init(allocator);
286 const ptr = try arena.create(TargetToHash);
287 ptr.* = TargetToHash.init(arena);
290288 path_gop.value_ptr.* = ptr;
291289 break :blk ptr;
292290 };
......@@ -327,7 +325,7 @@ pub fn main() !void {
327325 // gets their header in a separate arch directory.
328326 var path_it = path_table.iterator();
329327 while (path_it.next()) |path_kv| {
330 var contents_list = std.array_list.Managed(*Contents).init(allocator);
328 var contents_list = std.array_list.Managed(*Contents).init(arena);
331329 {
332330 var hash_it = path_kv.value_ptr.*.iterator();
333331 while (hash_it.next()) |hash_kv| {
......@@ -339,7 +337,7 @@ pub fn main() !void {
339337 const best_contents = contents_list.pop().?;
340338 if (best_contents.hit_count > 1) {
341339 // worth it to make it generic
342 const full_path = try Dir.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* });
340 const full_path = try Dir.path.join(arena, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* });
343341 try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?);
344342 try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = best_contents.bytes });
345343 best_contents.is_generic = true;
......@@ -360,7 +358,7 @@ pub fn main() !void {
360358 if (contents.is_generic) continue;
361359
362360 const dest_target = hash_kv.key_ptr.*;
363 const full_path = try Dir.path.join(allocator, &[_][]const u8{ out_dir, dest_target, path_kv.key_ptr.* });
361 const full_path = try Dir.path.join(arena, &[_][]const u8{ out_dir, dest_target, path_kv.key_ptr.* });
364362 try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?);
365363 try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = contents.bytes });
366364 }