authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-01 20:20:58-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-04 00:27:08-08:00
logf28802a9c6c3bd36368101981243aab7cf4f453f
treeb8a360cce73dae4e14bfa7f8ae23eae909ebb539
parent960c512efd71ab4b658952fe8761453128cc8292

zig libc: fix subcommand

This branch regressed the child process "run" mechanism because it didn't pass the correct stdin, stdout, stderr values to process.spawn Fixed now.

23 files changed, 167 insertions(+), 199 deletions(-)

lib/compiler/aro/main.zig+2-2
......@@ -18,7 +18,7 @@ var debug_allocator: std.heap.DebugAllocator(.{
1818 .canary = @truncate(0xc647026dc6875134),
1919}) = .{};
2020
21pub fn main() u8 {
21pub fn main(init: std.process.Init.Minimal) u8 {
2222 const gpa = if (@import("builtin").link_libc)
2323 std.heap.c_allocator
2424 else
......@@ -37,7 +37,7 @@ pub fn main() u8 {
3737
3838 const fast_exit = @import("builtin").mode != .Debug;
3939
40 const args = process.argsAlloc(arena) catch {
40 const args = init.args.toSlice(arena) catch {
4141 std.debug.print("out of memory\n", .{});
4242 if (fast_exit) process.exit(1);
4343 return 1;
lib/compiler/libc.zig+12-13
......@@ -24,23 +24,19 @@ const usage_libc =
2424
2525var stdout_buffer: [4096]u8 = undefined;
2626
27pub fn main() !void {
28 var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
29 defer arena_instance.deinit();
30 const arena = arena_instance.allocator();
31 const gpa = arena;
27pub fn main(init: std.process.Init) !void {
28 const arena = init.arena.allocator();
29 const gpa = init.gpa;
30 const io = init.io;
31 const args = try init.minimal.args.toSlice(arena);
32 const env_map = init.env_map;
3233
33 var threaded: std.Io.Threaded = .init(gpa, .{});
34 defer threaded.deinit();
35 const io = threaded.io();
36
37 const args = try std.process.argsAlloc(arena);
3834 const zig_lib_directory = args[1];
3935
4036 var input_file: ?[]const u8 = null;
4137 var target_arch_os_abi: []const u8 = "native";
4238 var print_includes: bool = false;
43 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
39 var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
4440 const stdout = &stdout_writer.interface;
4541 {
4642 var i: usize = 2;
......@@ -77,7 +73,7 @@ pub fn main() !void {
7773 const libc_installation: ?*LibCInstallation = libc: {
7874 if (input_file) |libc_file| {
7975 const libc = try arena.create(LibCInstallation);
80 libc.* = LibCInstallation.parse(arena, libc_file, &target) catch |err| {
76 libc.* = LibCInstallation.parse(arena, io, libc_file, &target) catch |err| {
8177 fatal("unable to parse libc file at path {s}: {t}", .{ libc_file, err });
8278 };
8379 break :libc libc;
......@@ -90,11 +86,13 @@ pub fn main() !void {
9086
9187 const libc_dirs = std.zig.LibCDirs.detect(
9288 arena,
89 io,
9390 zig_lib_directory,
9491 &target,
9592 is_native_abi,
9693 true,
9794 libc_installation,
95 env_map,
9896 ) catch |err| {
9997 const zig_target = try target.zigTriple(arena);
10098 fatal("unable to detect libc for target {s}: {t}", .{ zig_target, err });
......@@ -114,7 +112,7 @@ pub fn main() !void {
114112 }
115113
116114 if (input_file) |libc_file| {
117 var libc = LibCInstallation.parse(gpa, libc_file, &target) catch |err| {
115 var libc = LibCInstallation.parse(gpa, io, libc_file, &target) catch |err| {
118116 fatal("unable to parse libc file at path {s}: {t}", .{ libc_file, err });
119117 };
120118 defer libc.deinit(gpa);
......@@ -125,6 +123,7 @@ pub fn main() !void {
125123 var libc = LibCInstallation.findNative(gpa, io, .{
126124 .verbose = true,
127125 .target = &target,
126 .env_map = env_map,
128127 }) catch |err| {
129128 fatal("unable to detect native libc: {t}", .{err});
130129 };
lib/compiler/reduce.zig+17-24
......@@ -47,19 +47,11 @@ const Interestingness = enum { interesting, unknown, boring };
4747// - reduce flags sent to the compiler
4848// - integrate with the build system?
4949
50pub fn main() !void {
51 var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
52 defer arena_instance.deinit();
53 const arena = arena_instance.allocator();
54
55 var general_purpose_allocator: std.heap.GeneralPurposeAllocator(.{}) = .init;
56 const gpa = general_purpose_allocator.allocator();
57
58 var threaded: std.Io.Threaded = .init(gpa, .{});
59 defer threaded.deinit();
60 const io = threaded.io();
61
62 const args = try std.process.argsAlloc(arena);
50pub fn main(init: std.process.Init) !void {
51 const arena = init.arena.allocator();
52 const gpa = init.gpa;
53 const io = init.io;
54 const args = try init.minimal.args.toSlice(arena);
6355
6456 var opt_checker_path: ?[]const u8 = null;
6557 var opt_root_source_file_path: ?[]const u8 = null;
......@@ -73,8 +65,7 @@ pub fn main() !void {
7365 const arg = args[i];
7466 if (mem.startsWith(u8, arg, "-")) {
7567 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
76 const stdout = Io.File.stdout();
77 try stdout.writeAll(usage);
68 try Io.File.stdout().writeStreamingAll(io, usage);
7869 return std.process.cleanExit(io);
7970 } else if (mem.eql(u8, arg, "--")) {
8071 argv = args[i + 1 ..];
......@@ -131,12 +122,10 @@ pub fn main() !void {
131122
132123 if (!skip_smoke_test) {
133124 std.debug.print("smoke testing the interestingness check...\n", .{});
134 switch (try runCheck(arena, interestingness_argv.items)) {
125 switch (try runCheck(arena, io, interestingness_argv.items)) {
135126 .interesting => {},
136127 .boring, .unknown => |t| {
137 fatal("interestingness check returned {s} for unmodified input\n", .{
138 @tagName(t),
139 });
128 fatal("interestingness check returned {t} for unmodified input\n", .{t});
140129 },
141130 }
142131 }
......@@ -238,7 +227,7 @@ pub fn main() !void {
238227 try Io.Dir.cwd().writeFile(io, .{ .sub_path = root_source_file_path, .data = rendered.written() });
239228 // std.debug.print("trying this code:\n{s}\n", .{rendered.items});
240229
241 const interestingness = try runCheck(arena, interestingness_argv.items);
230 const interestingness = try runCheck(arena, io, interestingness_argv.items);
242231 std.debug.print("{d} random transformations: {t}. {d}/{d}\n", .{
243232 subset_size, interestingness, start_index, transformations.items.len,
244233 });
......@@ -293,20 +282,24 @@ fn sortTransformations(transformations: []Walk.Transformation, rng: std.Random)
293282
294283fn termToInteresting(term: std.process.Child.Term) Interestingness {
295284 return switch (term) {
296 .Exited => |code| switch (code) {
285 .exited => |code| switch (code) {
297286 0 => .interesting,
298287 1 => .unknown,
299288 else => .boring,
300289 },
301 else => b: {
290 .signal => |sig| {
291 std.debug.print("interestingness check terminated with signal {t}\n", .{sig});
292 return .boring;
293 },
294 else => {
302295 std.debug.print("interestingness check aborted unexpectedly\n", .{});
303 break :b .boring;
296 return .boring;
304297 },
305298 };
306299}
307300
308301fn runCheck(arena: Allocator, io: Io, argv: []const []const u8) !Interestingness {
309 const result = try std.process.run(arena, io, .{ .spawn_options = .{ .argv = argv } });
302 const result = try std.process.run(arena, io, .{ .argv = argv });
310303 if (result.stderr.len != 0)
311304 std.debug.print("{s}", .{result.stderr});
312305 return termToInteresting(result.term);
lib/compiler/resinator/main.zig+2-2
......@@ -19,7 +19,7 @@ const fmtResourceType = @import("res.zig").NameOrOrdinal.fmtResourceType;
1919const aro = @import("aro");
2020const compiler_util = @import("../util.zig");
2121
22pub fn main() !void {
22pub fn main(init: std.process.Init.Minimal) !void {
2323 var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
2424 defer std.debug.assert(debug_allocator.deinit() == .ok);
2525 const gpa = debug_allocator.allocator();
......@@ -32,7 +32,7 @@ pub fn main() !void {
3232 defer arena_state.deinit();
3333 const arena = arena_state.allocator();
3434
35 const args = try std.process.argsAlloc(arena);
35 const args = try init.args.toSlice(arena);
3636
3737 if (args.len < 2) {
3838 const stderr = try io.lockStderr(&.{}, null);
lib/compiler/translate-c/main.zig+1-1
......@@ -14,7 +14,7 @@ pub fn main(init: std.process.Init) u8 {
1414 const arena = init.arena.allocator();
1515 const io = init.io;
1616
17 const args = process.argsAlloc(arena) catch {
17 const args = init.minimal.args.toSlice(arena) catch {
1818 std.debug.print("ran out of memory allocating arguments\n", .{});
1919 if (fast_exit) process.exit(1);
2020 return 1;
lib/std/Build/Step.zig+2-2
......@@ -360,11 +360,11 @@ pub fn captureChildProcess(
360360 try handleChildProcUnsupported(s);
361361 try handleVerbose(s.owner, null, argv);
362362
363 const result = std.process.run(arena, io, .{ .spawn_options = .{
363 const result = std.process.run(arena, io, .{
364364 .argv = argv,
365365 .env_map = &graph.env_map,
366366 .progress_node = progress_node,
367 } }) catch |err| return s.fail("failed to run {s}: {t}", .{ argv[0], err });
367 }) catch |err| return s.fail("failed to run {s}: {t}", .{ argv[0], err });
368368
369369 if (result.stderr.len > 0) {
370370 try s.result_error_msgs.append(arena, result.stderr);
lib/std/Random/benchmark.zig+6-5
......@@ -123,14 +123,15 @@ fn mode(comptime x: comptime_int) comptime_int {
123123 return if (builtin.mode == .Debug) x / 64 else x;
124124}
125125
126pub fn main() !void {
126pub fn main(init: std.process.Init) !void {
127 const io = init.io;
128 const arena = init.arena.allocator();
129
127130 var stdout_buffer: [0x100]u8 = undefined;
128 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
131 var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
129132 const stdout = &stdout_writer.interface;
130133
131 var buffer: [1024]u8 = undefined;
132 var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
133 const args = try std.process.argsAlloc(fixed.allocator());
134 const args = try init.minimal.args.toSlice(arena);
134135
135136 var filter: ?[]u8 = "";
136137 var count: usize = mode(128 * MiB);
lib/std/crypto/benchmark.zig+8-12
......@@ -503,16 +503,16 @@ fn mode(comptime x: comptime_int) comptime_int {
503503 return if (builtin.mode == .Debug) x / 64 else x;
504504}
505505
506pub fn main() !void {
506pub fn main(init: std.process.Init) !void {
507 const io = init.io;
508 const arena = init.arena.allocator();
509
507510 // Size of buffer is about size of printed message.
508511 var stdout_buffer: [0x100]u8 = undefined;
509 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
512 var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
510513 const stdout = &stdout_writer.interface;
511514
512 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
513 defer arena.deinit();
514 const arena_allocator = arena.allocator();
515 const args = try std.process.argsAlloc(arena_allocator);
515 const args = try init.minimal.args.toSlice(arena);
516516
517517 var filter: ?[]u8 = "";
518518
......@@ -556,13 +556,9 @@ pub fn main() !void {
556556 }
557557 }
558558
559 var io_threaded = std.Io.Threaded.init(arena_allocator, .{});
560 defer io_threaded.deinit();
561 const io = io_threaded.io();
562
563559 inline for (parallel_hashes) |H| {
564560 if (filter == null or std.mem.find(u8, H.name, filter.?) != null) {
565 const throughput = try benchmarkHashParallel(H.ty, mode(128 * MiB), arena_allocator, io);
561 const throughput = try benchmarkHashParallel(H.ty, mode(128 * MiB), arena, io);
566562 try stdout.print("{s:>17}: {:10} MiB/s\n", .{ H.name, throughput / (1 * MiB) });
567563 try stdout.flush();
568564 }
......@@ -634,7 +630,7 @@ pub fn main() !void {
634630
635631 inline for (pwhashes) |H| {
636632 if (filter == null or std.mem.find(u8, H.name, filter.?) != null) {
637 const throughput = try benchmarkPwhash(arena_allocator, H.ty, H.params, mode(64), io);
633 const throughput = try benchmarkPwhash(arena, H.ty, H.params, mode(64), io);
638634 try stdout.print("{s:>17}: {d:10.3} s/ops\n", .{ H.name, throughput });
639635 try stdout.flush();
640636 }
lib/std/hash/benchmark.zig+6-5
......@@ -353,14 +353,15 @@ fn mode(comptime x: comptime_int) comptime_int {
353353 return if (builtin.mode == .Debug) x / 64 else x;
354354}
355355
356pub fn main() !void {
356pub fn main(init: std.process.Init) !void {
357 const io = init.io;
358 const arena = init.arena.allocator();
359
357360 var stdout_buffer: [0x100]u8 = undefined;
358 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
361 var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
359362 const stdout = &stdout_writer.interface;
360363
361 var buffer: [1024]u8 = undefined;
362 var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
363 const args = try std.process.argsAlloc(fixed.allocator());
364 const args = try init.minimal.args.toSlice(arena);
364365
365366 var filter: ?[]u8 = "";
366367 var count: usize = mode(128 * MiB);
lib/std/process.zig+40-2
......@@ -463,8 +463,33 @@ pub const RunError = posix.GetCwdError || posix.ReadError || SpawnError || posix
463463};
464464
465465pub const RunOptions = struct {
466 spawn_options: SpawnOptions,
466 argv: []const []const u8,
467467 max_output_bytes: usize = 50 * 1024,
468
469 /// Set to change the current working directory when spawning the child process.
470 cwd: ?[]const u8 = null,
471 /// Set to change the current working directory when spawning the child process.
472 /// This is not yet implemented for Windows. See https://github.com/ziglang/zig/issues/5190
473 /// Once that is done, `cwd` will be deprecated in favor of this field.
474 cwd_dir: ?Io.Dir = null,
475 /// Replaces the child environment when provided. The PATH value from here
476 /// is not used to resolve `argv[0]`; that resolution always uses parent
477 /// environment.
478 env_map: ?*const Environ.Map = null,
479 expand_arg0: ArgExpansion = .no_expand,
480 /// When populated, a pipe will be created for the child process to
481 /// communicate progress back to the parent. The file descriptor of the
482 /// write end of the pipe will be specified in the `ZIG_PROGRESS`
483 /// environment variable inside the child process. The progress reported by
484 /// the child will be attached to this progress node in the parent process.
485 ///
486 /// The child's progress tree will be grafted into the parent's progress tree,
487 /// by substituting this node with the child's root node.
488 progress_node: std.Progress.Node = std.Progress.Node.none,
489 /// Windows-only. Sets the CREATE_NO_WINDOW flag in CreateProcess.
490 create_no_window: bool = true,
491 /// Darwin-only. Disable ASLR for the child process.
492 disable_aslr: bool = false,
468493};
469494
470495pub const RunResult = struct {
......@@ -476,7 +501,20 @@ pub const RunResult = struct {
476501/// Spawns a child process, waits for it, collecting stdout and stderr, and then returns.
477502/// If it succeeds, the caller owns result.stdout and result.stderr memory.
478503pub fn run(gpa: Allocator, io: Io, options: RunOptions) RunError!RunResult {
479 var child = try spawn(io, options.spawn_options);
504 var child = try spawn(io, .{
505 .argv = options.argv,
506 .cwd = options.cwd,
507 .cwd_dir = options.cwd_dir,
508 .env_map = options.env_map,
509 .expand_arg0 = options.expand_arg0,
510 .progress_node = options.progress_node,
511 .create_no_window = options.create_no_window,
512 .disable_aslr = options.disable_aslr,
513
514 .stdin = .ignore,
515 .stdout = .pipe,
516 .stderr = .pipe,
517 });
480518 defer child.kill(io);
481519
482520 var stdout: std.ArrayList(u8) = .empty;
lib/std/zig/LibCInstallation.zig+24-28
......@@ -208,16 +208,16 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib
208208 } else if (is_haiku) {
209209 try self.findNativeIncludeDirPosix(gpa, io, args);
210210 try self.findNativeGccDirHaiku(gpa, io, args);
211 self.crt_dir = try gpa.dupeZ(u8, "/system/develop/lib");
211 self.crt_dir = try gpa.dupe(u8, "/system/develop/lib");
212212 } else if (builtin.target.os.tag == .illumos) {
213213 // There is only one libc, and its headers/libraries are always in the same spot.
214 self.include_dir = try gpa.dupeZ(u8, "/usr/include");
215 self.sys_include_dir = try gpa.dupeZ(u8, "/usr/include");
216 self.crt_dir = try gpa.dupeZ(u8, "/usr/lib/64");
214 self.include_dir = try gpa.dupe(u8, "/usr/include");
215 self.sys_include_dir = try gpa.dupe(u8, "/usr/include");
216 self.crt_dir = try gpa.dupe(u8, "/usr/lib/64");
217217 } else if (std.process.can_spawn) {
218218 try self.findNativeIncludeDirPosix(gpa, io, args);
219219 switch (builtin.target.os.tag) {
220 .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try gpa.dupeZ(u8, "/usr/lib"),
220 .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try gpa.dupe(u8, "/usr/lib"),
221221 .linux => try self.findNativeCrtDirPosix(gpa, io, args),
222222 else => {},
223223 }
......@@ -269,15 +269,13 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, ar
269269
270270 const run_res = std.process.run(gpa, io, .{
271271 .max_output_bytes = 1024 * 1024,
272 .spawn_options = .{
273 .argv = argv.items,
274 .env_map = &env_map,
275 // Some C compilers, such as Clang, are known to rely on argv[0] to find the path
276 // to their own executable, without even bothering to resolve PATH. This results in the message:
277 // error: unable to execute command: Executable "" doesn't exist!
278 // So we use the expandArg0 variant of ChildProcess to give them a helping hand.
279 .expand_arg0 = .expand,
280 },
272 .argv = argv.items,
273 .env_map = &env_map,
274 // Some C compilers, such as Clang, are known to rely on argv[0] to find the path
275 // to their own executable, without even bothering to resolve PATH. This results in the message:
276 // error: unable to execute command: Executable "" doesn't exist!
277 // So we use the expandArg0 variant of ChildProcess to give them a helping hand.
278 .expand_arg0 = .expand,
281279 }) catch |err| switch (err) {
282280 error.OutOfMemory => return error.OutOfMemory,
283281 else => {
......@@ -337,7 +335,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, ar
337335
338336 if (self.include_dir == null) {
339337 if (search_dir.access(io, include_dir_example_file, .{})) |_| {
340 self.include_dir = try gpa.dupeZ(u8, search_path);
338 self.include_dir = try gpa.dupe(u8, search_path);
341339 } else |err| switch (err) {
342340 error.FileNotFound => {},
343341 else => return error.FileSystem,
......@@ -346,7 +344,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, ar
346344
347345 if (self.sys_include_dir == null) {
348346 if (search_dir.access(io, sys_include_dir_example_file, .{})) |_| {
349 self.sys_include_dir = try gpa.dupeZ(u8, search_path);
347 self.sys_include_dir = try gpa.dupe(u8, search_path);
350348 } else |err| switch (err) {
351349 error.FileNotFound => {},
352350 else => return error.FileSystem,
......@@ -560,7 +558,7 @@ pub const CCPrintFileNameOptions = struct {
560558};
561559
562560/// caller owns returned memory
563fn ccPrintFileName(gpa: Allocator, io: Io, args: CCPrintFileNameOptions) ![:0]u8 {
561fn ccPrintFileName(gpa: Allocator, io: Io, args: CCPrintFileNameOptions) ![]u8 {
564562 // Detect infinite loops.
565563 var env_map = try args.env_map.clone(gpa);
566564 defer env_map.deinit();
......@@ -587,15 +585,13 @@ fn ccPrintFileName(gpa: Allocator, io: Io, args: CCPrintFileNameOptions) ![:0]u8
587585
588586 const run_res = std.process.run(gpa, io, .{
589587 .max_output_bytes = 1024 * 1024,
590 .spawn_options = .{
591 .argv = argv.items,
592 .env_map = &env_map,
593 // Some C compilers, such as Clang, are known to rely on argv[0] to find the path
594 // to their own executable, without even bothering to resolve PATH. This results in the message:
595 // error: unable to execute command: Executable "" doesn't exist!
596 // So we use the expandArg0 variant of ChildProcess to give them a helping hand.
597 .expand_arg0 = .expand,
598 },
588 .argv = argv.items,
589 .env_map = &env_map,
590 // Some C compilers, such as Clang, are known to rely on argv[0] to find the path
591 // to their own executable, without even bothering to resolve PATH. This results in the message:
592 // error: unable to execute command: Executable "" doesn't exist!
593 // So we use the expandArg0 variant of ChildProcess to give them a helping hand.
594 .expand_arg0 = .expand,
599595 }) catch |err| switch (err) {
600596 error.OutOfMemory => return error.OutOfMemory,
601597 else => return error.UnableToSpawnCCompiler,
......@@ -621,10 +617,10 @@ fn ccPrintFileName(gpa: Allocator, io: Io, args: CCPrintFileNameOptions) ![:0]u8
621617 // So we detect failure by checking if the output matches exactly the input.
622618 if (std.mem.eql(u8, line, args.search_basename)) return error.LibCRuntimeNotFound;
623619 switch (args.want_dirname) {
624 .full_path => return gpa.dupeZ(u8, line),
620 .full_path => return gpa.dupe(u8, line),
625621 .only_dir => {
626622 const dirname = fs.path.dirname(line) orelse return error.LibCRuntimeNotFound;
627 return gpa.dupeZ(u8, dirname);
623 return gpa.dupe(u8, dirname);
628624 },
629625 }
630626}
lib/std/zig/system/darwin.zig+3-3
......@@ -17,9 +17,9 @@ pub const macos = @import("darwin/macos.zig");
1717///
1818/// If error.OutOfMemory occurs in Allocator, this function returns null.
1919pub fn isSdkInstalled(gpa: Allocator, io: Io) bool {
20 const result = std.process.run(gpa, io, .{ .spawn_options = .{
20 const result = std.process.run(gpa, io, .{
2121 .argv = &.{ "xcode-select", "--print-path" },
22 } }) catch return false;
22 }) catch return false;
2323 defer {
2424 gpa.free(result.stderr);
2525 gpa.free(result.stdout);
......@@ -47,7 +47,7 @@ pub fn getSdk(gpa: Allocator, io: Io, target: *const Target) ?[]const u8 {
4747 else => return null,
4848 };
4949 const argv = &[_][]const u8{ "xcrun", "--sdk", sdk, "--show-sdk-path" };
50 const result = std.process.run(gpa, io, .{ .spawn_options = .{ .argv = argv } }) catch return null;
50 const result = std.process.run(gpa, io, .{ .argv = argv }) catch return null;
5151 defer {
5252 gpa.free(result.stderr);
5353 gpa.free(result.stdout);
test/standalone/child_process/child.zig+8-16
......@@ -4,31 +4,23 @@ const Io = std.Io;
44// 42 is expected by parent; other values result in test failure
55var exit_code: u8 = 42;
66
7pub fn main() !void {
8 var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator);
9 const arena = arena_state.allocator();
10
11 var threaded: std.Io.Threaded = .init(arena, .{});
12 defer threaded.deinit();
13 const io = threaded.io();
14
15 try run(arena, io);
16 arena_state.deinit();
7pub fn main(init: std.process.Init) !void {
8 try run(init.arena.allocator(), init.io, init.minimal.args);
179 std.process.exit(exit_code);
1810}
1911
20fn run(allocator: std.mem.Allocator, io: Io) !void {
21 var args = try std.process.argsWithAllocator(allocator);
22 defer args.deinit();
23 _ = args.next() orelse unreachable; // skip binary name
12fn run(arena: std.mem.Allocator, io: Io, args: std.process.Args) !void {
13 var it = try args.iterateAllocator(arena);
14 defer it.deinit();
15 _ = it.next() orelse unreachable; // skip binary name
2416
2517 // test cmd args
2618 const hello_arg = "hello arg";
27 const a1 = args.next() orelse unreachable;
19 const a1 = it.next() orelse unreachable;
2820 if (!std.mem.eql(u8, a1, hello_arg)) {
2921 testError(io, "first arg: '{s}'; want '{s}'", .{ a1, hello_arg });
3022 }
31 if (args.next()) |a2| {
23 if (it.next()) |a2| {
3224 testError(io, "expected only one arg; got more: {s}", .{a2});
3325 }
3426
test/standalone/install_headers/check_exists.zig+4-8
......@@ -2,17 +2,13 @@ const std = @import("std");
22
33/// Checks the existence of files relative to cwd.
44/// A path starting with ! should not exist.
5pub fn main() !void {
6 var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator);
7 defer arena_state.deinit();
5pub fn main(init: std.process.Init) !void {
6 const arena = init.arena.allocator();
7 const io = init.io;
88
9 const arena = arena_state.allocator();
10
11 var arg_it = try std.process.argsWithAllocator(arena);
9 var arg_it = try init.minimal.args.iterateAllocator(arena);
1210 _ = arg_it.next();
1311
14 const io = std.Io.Threaded.global_single_threaded.ioBasic();
15
1612 const cwd = std.Io.Dir.cwd();
1713 const cwd_realpath = try cwd.realPathFileAlloc(io, ".", arena);
1814
test/standalone/libfuzzer/main.zig+4-9
......@@ -6,19 +6,14 @@ fn testOne(in: abi.Slice) callconv(.c) void {
66 std.debug.assertReadable(in.toSlice());
77}
88
9pub fn main() !void {
10 var debug_gpa_ctx: std.heap.DebugAllocator(.{}) = .init;
11 defer _ = debug_gpa_ctx.deinit();
12 const gpa = debug_gpa_ctx.allocator();
9pub fn main(init: std.process.Init) !void {
10 const gpa = init.gpa;
11 const io = init.io;
1312
14 var args = try std.process.argsWithAllocator(gpa);
13 var args = try init.minimal.args.iterateAllocator(gpa);
1514 defer args.deinit();
1615 _ = args.skip(); // executable name
1716
18 var threaded: std.Io.Threaded = .init(gpa, .{});
19 defer threaded.deinit();
20 const io = threaded.io();
21
2217 const cache_dir_path = args.next() orelse @panic("expected cache directory path argument");
2318 var cache_dir = try std.Io.Dir.cwd().openDir(io, cache_dir_path, .{});
2419 defer cache_dir.close(io);
test/standalone/run_output_caching/main.zig+3-3
......@@ -1,8 +1,8 @@
11const std = @import("std");
22
3pub fn main() !void {
4 const io = std.Io.Threaded.global_single_threaded.ioBasic();
5 var args = try std.process.argsWithAllocator(std.heap.page_allocator);
3pub fn main(init: std.process.Init) !void {
4 const io = init.io;
5 var args = try init.minimal.argsAllocator(init.arena.allocator());
66 _ = args.skip();
77 const filename = args.next().?;
88 const file = try std.Io.Dir.cwd().createFile(io, filename, .{});
test/standalone/windows_bat_args/fuzz.zig+4-9
......@@ -4,16 +4,11 @@ const std = @import("std");
44const Io = std.Io;
55const Allocator = std.mem.Allocator;
66
7pub fn main() anyerror!void {
8 var debug_alloc_inst: std.heap.DebugAllocator(.{}) = .init;
9 defer std.debug.assert(debug_alloc_inst.deinit() == .ok);
10 const gpa = debug_alloc_inst.allocator();
7pub fn main(init: std.process.Init) !void {
8 const gpa = init.gpa;
9 const io = init.io;
1110
12 var threaded: Io.Threaded = .init(gpa, .{});
13 defer threaded.deinit();
14 const io = threaded.io();
15
16 var it = try std.process.argsWithAllocator(gpa);
11 var it = try init.minimal.argsAllocator(gpa);
1712 defer it.deinit();
1813 _ = it.next() orelse unreachable; // skip binary name
1914 const child_exe_path_orig = it.next() orelse unreachable;
test/standalone/windows_bat_args/test.zig+4-8
......@@ -2,15 +2,11 @@ const std = @import("std");
22const Io = std.Io;
33const Allocator = std.mem.Allocator;
44
5pub fn main() anyerror!void {
6 var debug_alloc_inst: std.heap.DebugAllocator(.{}) = .init;
7 defer std.debug.assert(debug_alloc_inst.deinit() == .ok);
8 const gpa = debug_alloc_inst.allocator();
5pub fn main(init: std.process.Init) !void {
6 const gpa = init.gpa;
7 const io = init.io;
98
10 var threaded: Io.Threaded = .init(gpa, .{});
11 const io = threaded.io();
12
13 var it = try std.process.argsWithAllocator(gpa);
9 var it = try init.minimal.argsAllocator(gpa);
1410 defer it.deinit();
1511 _ = it.next() orelse unreachable; // skip binary name
1612 const child_exe_path_orig = it.next() orelse unreachable;
test/standalone/windows_spawn/main.zig+4-9
......@@ -5,16 +5,11 @@ const Allocator = std.mem.Allocator;
55const windows = std.os.windows;
66const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral;
77
8pub fn main() anyerror!void {
9 var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
10 defer if (debug_allocator.deinit() == .leak) @panic("found memory leaks");
11 const gpa = debug_allocator.allocator();
8pub fn main(init: std.process.Init) !void {
9 const gpa = init.gpa;
10 const io = init.io;
1211
13 var threaded: std.Io.Threaded = .init(gpa, .{});
14 defer threaded.deinit();
15 const io = threaded.io();
16
17 var it = try std.process.argsWithAllocator(gpa);
12 var it = try init.minimal.argsAllocator(gpa);
1813 defer it.deinit();
1914 _ = it.next() orelse unreachable; // skip binary name
2015 const hello_exe_cache_path = it.next() orelse unreachable;
tools/docgen.zig+4-12
......@@ -28,21 +28,13 @@ const usage =
2828 \\
2929;
3030
31pub fn main() !void {
32 var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
33 defer arena_instance.deinit();
31pub fn main(init: std.process.Init) !void {
32 const arena = init.arena.allocator();
33 const io = init.io;
3434
35 const arena = arena_instance.allocator();
36
37 var args_it = try process.argsWithAllocator(arena);
35 var args_it = try init.minimal.args.iterateAllocator(arena);
3836 if (!args_it.skip()) @panic("expected self arg");
3937
40 const gpa = arena;
41
42 var threaded: std.Io.Threaded = .init(gpa, .{});
43 defer threaded.deinit();
44 const io = threaded.io();
45
4638 var opt_code_dir: ?[]const u8 = null;
4739 var opt_input: ?[]const u8 = null;
4840 var opt_output: ?[]const u8 = null;
tools/doctest.zig+4-12
......@@ -29,21 +29,13 @@ const usage =
2929 \\
3030;
3131
32pub fn main() !void {
33 var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
34 defer arena_instance.deinit();
32pub fn main(init: std.process.Init) !void {
33 const arena = init.arena.allocator();
34 const io = init.io;
3535
36 const arena = arena_instance.allocator();
37
38 var args_it = try process.argsWithAllocator(arena);
36 var args_it = try init.minimal.args.iterateAllocator(arena);
3937 if (!args_it.skip()) fatal("missing argv[0]", .{});
4038
41 const gpa = arena;
42
43 var threaded: std.Io.Threaded = .init(gpa, .{});
44 defer threaded.deinit();
45 const io = threaded.io();
46
4739 var opt_input: ?[]const u8 = null;
4840 var opt_output: ?[]const u8 = null;
4941 var opt_zig: ?[]const u8 = null;
tools/incr-check.zig+1-1
......@@ -44,7 +44,7 @@ pub fn main(init: std.process.Init) !void {
4444
4545 var debug_log_args: std.ArrayList([]const u8) = .empty;
4646
47 var arg_it = try std.process.argsWithAllocator(arena);
47 var arg_it = try init.minimal.argsIterator(arena);
4848 _ = arg_it.skip();
4949 while (arg_it.next()) |arg| {
5050 if (arg.len > 0 and arg[0] == '-') {
tools/update_cpu_features.zig+4-13
......@@ -1883,20 +1883,11 @@ const targets = [_]ArchTarget{
18831883 },
18841884};
18851885
1886pub fn main() anyerror!void {
1887 var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
1888 defer _ = debug_allocator.deinit();
1889 const gpa = debug_allocator.allocator();
1886pub fn main(init: std.process.Init) !void {
1887 const arena = init.arena_allocator.allocator();
1888 const io = init.io;
18901889
1891 var arena_state: std.heap.ArenaAllocator = .init(gpa);
1892 defer arena_state.deinit();
1893 const arena = arena_state.allocator();
1894
1895 var threaded: std.Io.Threaded = .init(gpa, .{});
1896 defer threaded.deinit();
1897 const io = threaded.io();
1898
1899 var args = try std.process.argsWithAllocator(arena);
1890 var args = try init.minimal.args.iterateAllocator(arena);
19001891 const args0 = args.next().?;
19011892
19021893 const llvm_tblgen_exe = args.next() orelse