authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-01 19:40:18-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-04 00:27:08-08:00
log960c512efd71ab4b658952fe8761453128cc8292
tree5a519f99451bb6ad896dcfa438d8ebed77f2c03e
parenta6f519c20f105a60c2ac51530354f9ac7c3e1fd9

compiler: update std lib API usage


14 files changed, 126 insertions(+), 119 deletions(-)

lib/compiler/std-docs.zig+36-33
......@@ -21,19 +21,12 @@ fn usage(io: Io) noreturn {
2121 std.process.exit(1);
2222}
2323
24pub fn main() !void {
25 var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
26 defer arena_instance.deinit();
27 const arena = arena_instance.allocator();
28
29 var general_purpose_allocator: std.heap.GeneralPurposeAllocator(.{}) = .init;
30 const gpa = general_purpose_allocator.allocator();
24pub fn main(init: std.process.Init) !void {
25 const arena = init.arena.allocator();
26 const gpa = init.gpa;
27 const io = init.io;
3128
32 var threaded: Io.Threaded = .init(gpa, .{});
33 defer threaded.deinit();
34 const io = threaded.io();
35
36 var argv = try std.process.argsWithAllocator(arena);
29 var argv = try init.minimal.args.iterateAllocator(arena);
3730 defer argv.deinit();
3831 assert(argv.skip());
3932 const zig_lib_directory = argv.next().?;
......@@ -72,7 +65,7 @@ pub fn main() !void {
7265 const url_with_newline = try std.fmt.allocPrint(arena, "http://127.0.0.1:{d}/\n", .{port});
7366 Io.File.stdout().writeStreamingAll(io, url_with_newline) catch {};
7467 if (should_open_browser) {
75 openBrowserTab(gpa, io, url_with_newline[0 .. url_with_newline.len - 1 :'\n']) catch |err| {
68 openBrowserTab(io, url_with_newline[0 .. url_with_newline.len - 1 :'\n']) catch |err| {
7669 std.log.err("unable to open browser: {t}", .{err});
7770 };
7871 }
......@@ -324,11 +317,12 @@ fn buildWasmBinary(
324317 "--listen=-", //
325318 });
326319
327 var child = std.process.Child.init(argv.items, gpa);
328 child.stdin_behavior = .Pipe;
329 child.stdout_behavior = .Pipe;
330 child.stderr_behavior = .Pipe;
331 try child.spawn(io);
320 var child = try std.process.spawn(io, .{
321 .argv = argv.items,
322 .stdin = .pipe,
323 .stdout = .pipe,
324 .stderr = .pipe,
325 });
332326
333327 var poller = Io.poll(gpa, enum { stdout, stderr }, .{
334328 .stdout = child.stdout.?,
......@@ -388,19 +382,26 @@ fn buildWasmBinary(
388382 child.stdin = null;
389383
390384 switch (try child.wait(io)) {
391 .Exited => |code| {
385 .exited => |code| {
392386 if (code != 0) {
393387 std.log.err(
394388 "the following command exited with error code {d}:\n{s}",
395 .{ code, try std.Build.Step.allocPrintCmd(arena, null, argv.items) },
389 .{ code, try std.Build.Step.allocPrintCmd(arena, null, null, argv.items) },
396390 );
397391 return error.WasmCompilationFailed;
398392 }
399393 },
400 .Signal, .Stopped, .Unknown => {
394 .signal => |sig| {
395 std.log.err(
396 "the following command terminated with signal {t}:\n{s}",
397 .{ sig, try std.Build.Step.allocPrintCmd(arena, null, null, argv.items) },
398 );
399 return error.WasmCompilationFailed;
400 },
401 .stopped, .unknown => {
401402 std.log.err(
402403 "the following command terminated unexpectedly:\n{s}",
403 .{try std.Build.Step.allocPrintCmd(arena, null, argv.items)},
404 .{try std.Build.Step.allocPrintCmd(arena, null, null, argv.items)},
404405 );
405406 return error.WasmCompilationFailed;
406407 },
......@@ -410,14 +411,14 @@ fn buildWasmBinary(
410411 try result_error_bundle.renderToStderr(io, .{}, .auto);
411412 std.log.err("the following command failed with {d} compilation errors:\n{s}", .{
412413 result_error_bundle.errorMessageCount(),
413 try std.Build.Step.allocPrintCmd(arena, null, argv.items),
414 try std.Build.Step.allocPrintCmd(arena, null, null, argv.items),
414415 });
415416 return error.WasmCompilationFailed;
416417 }
417418
418419 return result orelse {
419420 std.log.err("child process failed to report result\n{s}", .{
420 try std.Build.Step.allocPrintCmd(arena, null, argv.items),
421 try std.Build.Step.allocPrintCmd(arena, null, null, argv.items),
421422 });
422423 return error.WasmCompilationFailed;
423424 };
......@@ -434,22 +435,24 @@ fn sendMessage(io: Io, file: Io.File, tag: std.zig.Client.Message.Tag) !void {
434435 };
435436}
436437
437fn openBrowserTab(gpa: Allocator, io: Io, url: []const u8) !void {
438fn openBrowserTab(io: Io, url: []const u8) !void {
438439 // Until https://github.com/ziglang/zig/issues/19205 is implemented, we
439 // spawn a thread for this child process.
440 _ = try std.Thread.spawn(.{}, openBrowserTabThread, .{ gpa, io, url });
440 // spawn and then leak a concurrent task for this child process.
441 const future = try io.concurrent(openBrowserTabTask, .{ io, url });
442 _ = future; // leak it
441443}
442444
443fn openBrowserTabThread(gpa: Allocator, io: Io, url: []const u8) !void {
445fn openBrowserTabTask(io: Io, url: []const u8) !void {
444446 const main_exe = switch (builtin.os.tag) {
445447 .windows => "explorer",
446448 .macos => "open",
447449 else => "xdg-open",
448450 };
449 var child = std.process.Child.init(&.{ main_exe, url }, gpa);
450 child.stdin_behavior = .ignore;
451 child.stdout_behavior = .ignore;
452 child.stderr_behavior = .ignore;
453 try child.spawn(io);
451 var child = try std.process.spawn(io, .{
452 .argv = &.{ main_exe, url },
453 .stdin = .ignore,
454 .stdout = .ignore,
455 .stderr = .ignore,
456 });
454457 _ = try child.wait(io);
455458}
lib/compiler/translate-c/main.zig+4-13
......@@ -9,19 +9,10 @@ const Translator = @import("Translator.zig");
99
1010const fast_exit = @import("builtin").mode != .Debug;
1111
12var general_purpose_allocator: std.heap.GeneralPurposeAllocator(.{}) = .init;
13
14pub fn main() u8 {
15 const gpa = general_purpose_allocator.allocator();
16 defer _ = general_purpose_allocator.deinit();
17
18 var arena_instance = std.heap.ArenaAllocator.init(gpa);
19 defer arena_instance.deinit();
20 const arena = arena_instance.allocator();
21
22 var threaded: std.Io.Threaded = .init(gpa, .{});
23 defer threaded.deinit();
24 const io = threaded.io();
12pub fn main(init: std.process.Init) u8 {
13 const gpa = init.gpa;
14 const arena = init.arena.allocator();
15 const io = init.io;
2516
2617 const args = process.argsAlloc(arena) catch {
2718 std.debug.print("ran out of memory allocating arguments\n", .{});
lib/std/zig.zig+6
......@@ -742,6 +742,7 @@ pub const EnvVar = enum {
742742 ZIG_IS_DETECTING_LIBC_PATHS,
743743 ZIG_IS_TRYING_TO_NOT_CALL_ITSELF,
744744
745 // C toolchain integration
745746 NIX_CFLAGS_COMPILE,
746747 NIX_CFLAGS_LINK,
747748 NIX_LDFLAGS,
......@@ -750,13 +751,18 @@ pub const EnvVar = enum {
750751 LIBRARY_PATH,
751752 CC,
752753
754 // Terminal integration
753755 NO_COLOR,
754756 CLICOLOR_FORCE,
755757
758 // Debug info integration
756759 XDG_CACHE_HOME,
757760 LOCALAPPDATA,
758761 HOME,
759762
763 // Windows SDK integration
764 PROGRAMDATA,
765
760766 pub fn isSet(ev: EnvVar, map: *const std.process.Environ.Map) bool {
761767 return map.contains(@tagName(ev));
762768 }
lib/std/zig/LibCInstallation.zig+5-4
......@@ -13,6 +13,7 @@ const fs = std.fs;
1313const Allocator = std.mem.Allocator;
1414const Path = std.Build.Cache.Path;
1515const log = std.log.scoped(.libc_installation);
16const Environ = std.process.Environ;
1617
1718include_dir: ?[]const u8 = null,
1819sys_include_dir: ?[]const u8 = null,
......@@ -167,7 +168,7 @@ pub fn render(self: LibCInstallation, out: *std.Io.Writer) !void {
167168
168169pub const FindNativeOptions = struct {
169170 target: *const std.Target,
170 env_map: *const std.process.Environ.Map,
171 env_map: *const Environ.Map,
171172
172173 /// If enabled, will print human-friendly errors to stderr.
173174 verbose: bool = false,
......@@ -192,7 +193,7 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib
192193 });
193194 return self;
194195 } else if (is_windows) {
195 const sdk = std.zig.WindowsSdk.find(gpa, io, args.target.cpu.arch) catch |err| switch (err) {
196 const sdk = std.zig.WindowsSdk.find(gpa, io, args.target.cpu.arch, args.env_map) catch |err| switch (err) {
196197 error.NotFound => return error.WindowsSdkNotFound,
197198 error.PathTooLong => return error.WindowsSdkNotFound,
198199 error.OutOfMemory => return error.OutOfMemory,
......@@ -552,7 +553,7 @@ fn findNativeMsvcLibDir(
552553}
553554
554555pub const CCPrintFileNameOptions = struct {
555 env_map: *const std.process.Environ.Map,
556 env_map: *const Environ.Map,
556557 search_basename: []const u8,
557558 want_dirname: enum { full_path, only_dir },
558559 verbose: bool = false,
......@@ -672,7 +673,7 @@ const inf_loop_env_key = "ZIG_IS_DETECTING_LIBC_PATHS";
672673fn appendCcExe(
673674 args: *std.array_list.Managed([]const u8),
674675 skip_cc_env_var: bool,
675 env_map: *const std.process.Environ.Map,
676 env_map: *const Environ.Map,
676677) !void {
677678 const default_cc_exe = if (is_windows) "cc.exe" else "cc";
678679 try args.ensureUnusedCapacity(1);
lib/std/zig/WindowsSdk.zig+41-23
......@@ -6,6 +6,7 @@ const Io = std.Io;
66const Dir = std.Io.Dir;
77const Writer = std.Io.Writer;
88const Allocator = std.mem.Allocator;
9const Environ = std.process.Environ;
910
1011windows10sdk: ?Installation,
1112windows81sdk: ?Installation,
......@@ -24,7 +25,12 @@ const product_version_max_length = version_major_minor_max_length + ".65535".len
2425/// Find path and version of Windows 10 SDK and Windows 8.1 SDK, and find path to MSVC's `lib/` directory.
2526/// Caller owns the result's fields.
2627/// Returns memory allocated by `gpa`
27pub fn find(gpa: Allocator, io: Io, arch: std.Target.Cpu.Arch) error{ OutOfMemory, NotFound, PathTooLong }!WindowsSdk {
28pub fn find(
29 gpa: Allocator,
30 io: Io,
31 arch: std.Target.Cpu.Arch,
32 env_map: *const Environ.Map,
33) error{ OutOfMemory, NotFound, PathTooLong }!WindowsSdk {
2834 if (builtin.os.tag != .windows) return error.NotFound;
2935
3036 //note(dimenus): If this key doesn't exist, neither the Win 8 SDK nor the Win 10 SDK is installed
......@@ -49,7 +55,7 @@ pub fn find(gpa: Allocator, io: Io, arch: std.Target.Cpu.Arch) error{ OutOfMemor
4955 };
5056 errdefer if (windows81sdk) |*w| w.free(gpa);
5157
52 const msvc_lib_dir: ?[]const u8 = MsvcLibDir.find(gpa, io, arch) catch |err| switch (err) {
58 const msvc_lib_dir: ?[]const u8 = MsvcLibDir.find(gpa, io, arch, env_map) catch |err| switch (err) {
5359 error.MsvcLibDirNotFound => null,
5460 error.OutOfMemory => return error.OutOfMemory,
5561 };
......@@ -671,7 +677,11 @@ const MsvcLibDir = struct {
671677 return Dir.openDirAbsolute(io, instances_path, .{ .iterate = true }) catch return error.PathNotFound;
672678 }
673679
674 fn findInstancesDir(gpa: Allocator, io: Io) error{ OutOfMemory, PathNotFound }!Dir {
680 fn findInstancesDir(
681 gpa: Allocator,
682 io: Io,
683 env_map: *const Environ.Map,
684 ) error{ OutOfMemory, PathNotFound }!Dir {
675685 // First, try getting the packages cache path from the registry.
676686 // This only seems to exist when the path is different from the default.
677687 method1: {
......@@ -691,16 +701,13 @@ const MsvcLibDir = struct {
691701 // If that can't be found, fall back to manually appending
692702 // `Microsoft\VisualStudio\Packages\_Instances` to %PROGRAMDATA%
693703 method3: {
694 const program_data = std.process.getEnvVarOwned(gpa, "PROGRAMDATA") catch |err| switch (err) {
695 error.OutOfMemory => |e| return e,
696 error.InvalidWtf8 => unreachable,
697 error.EnvironmentVariableNotFound => break :method3,
698 };
699 defer gpa.free(program_data);
704 const program_data = std.zig.EnvVar.PROGRAMDATA.get(env_map) orelse break :method3;
700705
701706 if (!Dir.path.isAbsolute(program_data)) break :method3;
702707
703 const instances_path = try Dir.path.join(gpa, &.{ program_data, "Microsoft", "VisualStudio", "Packages", "_Instances" });
708 const instances_path = try Dir.path.join(gpa, &.{
709 program_data, "Microsoft", "VisualStudio", "Packages", "_Instances",
710 });
704711 defer gpa.free(instances_path);
705712
706713 return Dir.openDirAbsolute(io, instances_path, .{ .iterate = true }) catch break :method3;
......@@ -754,12 +761,17 @@ const MsvcLibDir = struct {
754761 ///
755762 /// The logic in this function is intended to match what ISetupConfiguration does
756763 /// under-the-hood, as verified using Procmon.
757 fn findViaCOM(gpa: Allocator, io: Io, arch: std.Target.Cpu.Arch) error{ OutOfMemory, PathNotFound }![]const u8 {
764 fn findViaCOM(
765 gpa: Allocator,
766 io: Io,
767 arch: std.Target.Cpu.Arch,
768 env_map: *const Environ.Map,
769 ) error{ OutOfMemory, PathNotFound }![]const u8 {
758770 // Typically `%PROGRAMDATA%\Microsoft\VisualStudio\Packages\_Instances`
759771 // This will contain directories with names of instance IDs like 80a758ca,
760772 // which will contain `state.json` files that have the version and
761773 // installation directory.
762 var instances_dir = try findInstancesDir(gpa, io);
774 var instances_dir = try findInstancesDir(gpa, io, env_map);
763775 defer instances_dir.close(io);
764776
765777 var state_subpath_buf: [Dir.max_name_bytes + 32]u8 = undefined;
......@@ -856,15 +868,16 @@ const MsvcLibDir = struct {
856868 }
857869
858870 // https://learn.microsoft.com/en-us/visualstudio/install/tools-for-managing-visual-studio-instances?view=vs-2022#editing-the-registry-for-a-visual-studio-instance
859 fn findViaRegistry(gpa: Allocator, io: Io, arch: std.Target.Cpu.Arch) error{ OutOfMemory, PathNotFound }![]const u8 {
871 fn findViaRegistry(
872 gpa: Allocator,
873 io: Io,
874 arch: std.Target.Cpu.Arch,
875 env_map: *const Environ.Map,
876 ) error{ OutOfMemory, PathNotFound }![]const u8 {
860877
861878 // %localappdata%\Microsoft\VisualStudio\
862879 // %appdata%\Local\Microsoft\VisualStudio\
863 const local_app_data_path = (std.zig.EnvVar.LOCALAPPDATA.get(gpa) catch |err| switch (err) {
864 error.OutOfMemory => |e| return e,
865 error.InvalidWtf8 => return error.PathNotFound,
866 }) orelse return error.PathNotFound;
867 defer gpa.free(local_app_data_path);
880 const local_app_data_path = std.zig.EnvVar.LOCALAPPDATA.get(env_map) orelse return error.PathNotFound;
868881 const visualstudio_folder_path = try Dir.path.join(gpa, &.{
869882 local_app_data_path, "Microsoft\\VisualStudio\\",
870883 });
......@@ -955,7 +968,7 @@ const MsvcLibDir = struct {
955968 gpa: Allocator,
956969 io: Io,
957970 arch: std.Target.Cpu.Arch,
958 env_map: *const std.process.Environ.Map,
971 env_map: *const Environ.Map,
959972 ) error{ OutOfMemory, PathNotFound }![]const u8 {
960973 var base_path: std.array_list.Managed(u8) = base_path: {
961974 try_env: {
......@@ -1029,12 +1042,17 @@ const MsvcLibDir = struct {
10291042
10301043 /// Find path to MSVC's `lib/` directory.
10311044 /// Caller owns the result.
1032 pub fn find(gpa: Allocator, io: Io, arch: std.Target.Cpu.Arch) error{ OutOfMemory, MsvcLibDirNotFound }![]const u8 {
1033 const full_path = MsvcLibDir.findViaCOM(gpa, io, arch) catch |err1| switch (err1) {
1045 pub fn find(
1046 gpa: Allocator,
1047 io: Io,
1048 arch: std.Target.Cpu.Arch,
1049 env_map: *const Environ.Map,
1050 ) error{ OutOfMemory, MsvcLibDirNotFound }![]const u8 {
1051 const full_path = MsvcLibDir.findViaCOM(gpa, io, arch, env_map) catch |err1| switch (err1) {
10341052 error.OutOfMemory => return error.OutOfMemory,
1035 error.PathNotFound => MsvcLibDir.findViaRegistry(gpa, io, arch) catch |err2| switch (err2) {
1053 error.PathNotFound => MsvcLibDir.findViaRegistry(gpa, io, arch, env_map) catch |err2| switch (err2) {
10361054 error.OutOfMemory => return error.OutOfMemory,
1037 error.PathNotFound => MsvcLibDir.findViaVs7Key(gpa, io, arch) catch |err3| switch (err3) {
1055 error.PathNotFound => MsvcLibDir.findViaVs7Key(gpa, io, arch, env_map) catch |err3| switch (err3) {
10381056 error.OutOfMemory => return error.OutOfMemory,
10391057 error.PathNotFound => return error.MsvcLibDirNotFound,
10401058 },
src/Compilation.zig+1
......@@ -2128,6 +2128,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
21282128 .manifest_dir = options.dirs.local_cache.handle.createDirPathOpen(io, "h", .{}) catch |err| {
21292129 return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = "h", .err = err } });
21302130 },
2131 .cwd = options.dirs.cwd,
21312132 };
21322133 // These correspond to std.zig.Server.Message.PathPrefix.
21332134 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
src/Zcu/PerThread.zig+1-4
......@@ -2571,10 +2571,7 @@ fn newEmbedFile(
25712571 try whole.cache_manifest_mutex.lock(io);
25722572 defer whole.cache_manifest_mutex.unlock(io);
25732573
2574 man.addFilePostContents(path_str, contents, new_file.stat) catch |err| switch (err) {
2575 error.Unexpected => unreachable,
2576 else => |e| return e,
2577 };
2574 try man.addFilePostContents(path_str, contents, new_file.stat);
25782575 }
25792576
25802577 return new_file;
src/introspect.zig+8-7
......@@ -6,6 +6,7 @@ const Dir = std.Io.Dir;
66const mem = std.mem;
77const Allocator = std.mem.Allocator;
88const Cache = std.Build.Cache;
9const assert = std.debug.assert;
910
1011const build_options = @import("build_options");
1112
......@@ -62,14 +63,14 @@ pub fn getResolvedCwd(gpa: Allocator) error{
6263 if (std.debug.runtime_safety) {
6364 const cwd = try std.process.getCwdAlloc(gpa);
6465 defer gpa.free(cwd);
65 std.debug.assert(mem.eql(u8, cwd, "."));
66 assert(mem.eql(u8, cwd, "."));
6667 }
6768 return "";
6869 }
6970 const cwd = try std.process.getCwdAlloc(gpa);
7071 defer gpa.free(cwd);
7172 const resolved = try Dir.path.resolve(gpa, &.{cwd});
72 std.debug.assert(Dir.path.isAbsolute(resolved));
73 assert(Dir.path.isAbsolute(resolved));
7374 return resolved;
7475}
7576
......@@ -140,7 +141,7 @@ pub fn resolvePath(
140141 paths: []const []const u8,
141142) Allocator.Error![]u8 {
142143 if (builtin.target.os.tag == .wasi) {
143 std.debug.assert(mem.eql(u8, cwd_resolved, ""));
144 assert(mem.eql(u8, cwd_resolved, ""));
144145 const res = try Dir.path.resolve(gpa, paths);
145146 if (mem.eql(u8, res, ".")) {
146147 gpa.free(res);
......@@ -160,8 +161,8 @@ pub fn resolvePath(
160161 gpa.free(res);
161162 return "";
162163 }
163 std.debug.assert(!Dir.path.isAbsolute(res));
164 std.debug.assert(!isUpDir(res));
164 assert(!Dir.path.isAbsolute(res));
165 assert(!isUpDir(res));
165166 return res;
166167 }
167168
......@@ -180,8 +181,8 @@ pub fn resolvePath(
180181 };
181182 errdefer gpa.free(path_resolved);
182183
183 std.debug.assert(Dir.path.isAbsolute(path_resolved));
184 std.debug.assert(Dir.path.isAbsolute(cwd_resolved));
184 assert(Dir.path.isAbsolute(path_resolved));
185 assert(Dir.path.isAbsolute(cwd_resolved));
185186
186187 if (!std.mem.startsWith(u8, path_resolved, cwd_resolved)) return path_resolved; // not in cwd
187188 if (path_resolved.len == cwd_resolved.len) {
src/libs/mingw.zig+1
......@@ -259,6 +259,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
259259 .gpa = gpa,
260260 .io = io,
261261 .manifest_dir = try comp.dirs.global_cache.handle.createDirPathOpen(io, "h", .{}),
262 .cwd = comp.dirs.cwd,
262263 };
263264 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
264265 cache.addPrefix(comp.dirs.zig_lib);
test/standalone/child_process/main.zig+7-4
......@@ -1,15 +1,15 @@
11const std = @import("std");
22const Io = std.Io;
33
4pub fn main() !void {
4pub fn main(init: std.process.Init.Minimal) !void {
55 // make sure safety checks are enabled even in release modes
6 var gpa_state = std.heap.GeneralPurposeAllocator(.{ .safety = true }){};
6 var gpa_state: std.heap.GeneralPurposeAllocator(.{ .safety = true }) = .{};
77 defer if (gpa_state.deinit() != .ok) {
88 @panic("found memory leaks");
99 };
1010 const gpa = gpa_state.allocator();
1111
12 var it = try std.process.argsWithAllocator(gpa);
12 var it = try init.iterateAllocator(gpa);
1313 defer it.deinit();
1414 _ = it.next() orelse unreachable; // skip binary name
1515 const child_path, const needs_free = child_path: {
......@@ -21,7 +21,10 @@ pub fn main() !void {
2121 };
2222 defer if (needs_free) gpa.free(child_path);
2323
24 var threaded: Io.Threaded = .init(gpa, .{});
24 var threaded: Io.Threaded = .init(gpa, .{
25 .argv0 = .init(init.args),
26 .environ = init.environ,
27 });
2528 defer threaded.deinit();
2629 const io = threaded.io();
2730
test/standalone/env_vars/main.zig+3-8
......@@ -2,16 +2,11 @@ const std = @import("std");
22const builtin = @import("builtin");
33
44// Note: the environment variables under test are set by the build.zig
5pub fn main() !void {
5pub fn main(init: std.process.Init) !void {
66 @setEvalBranchQuota(10000);
77
8 var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
9 defer _ = gpa.deinit();
10 const allocator = gpa.allocator();
11
12 var arena_state = std.heap.ArenaAllocator.init(allocator);
13 defer arena_state.deinit();
14 const arena = arena_state.allocator();
8 const allocator = init.gpa;
9 const arena = init.arena.allocator();
1510
1611 // hasNonEmptyEnvVar
1712 {
test/standalone/run_output_paths/create_file.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.args.iterateAllocator(init.arena.allocator());
66 _ = args.skip();
77 const dir_name = args.next().?;
88 const dir = try std.Io.Dir.cwd().openDir(io, if (std.mem.startsWith(u8, dir_name, "--dir="))
test/standalone/self_exe_symlink/create-symlink.zig+6-10
......@@ -1,21 +1,17 @@
11const std = @import("std");
22
3pub fn main() anyerror!void {
4 var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
5 defer if (gpa.deinit() == .leak) @panic("found memory leaks");
6 const allocator = gpa.allocator();
7
8 var it = try std.process.argsWithAllocator(allocator);
3pub fn main(init: std.process.Init) !void {
4 const io = init.io;
5 const gpa = init.gpa;
6 var it = try init.args.iterateAllocator(gpa);
97 defer it.deinit();
108 _ = it.next() orelse unreachable; // skip binary name
119 const exe_path = it.next() orelse unreachable;
1210 const symlink_path = it.next() orelse unreachable;
1311
1412 // If `exe_path` is relative to our cwd, we need to convert it to be relative to the dirname of `symlink_path`.
15 const exe_rel_path = try std.fs.path.relative(allocator, std.fs.path.dirname(symlink_path) orelse ".", exe_path);
16 defer allocator.free(exe_rel_path);
17
18 const io = std.Io.Threaded.global_single_threaded.ioBasic();
13 const exe_rel_path = try std.fs.path.relative(gpa, std.fs.path.dirname(symlink_path) orelse ".", exe_path);
14 defer gpa.free(exe_rel_path);
1915
2016 try std.Io.Dir.cwd().symLink(io, exe_rel_path, symlink_path, .{});
2117}
test/standalone/simple/cat/main.zig+4-10
......@@ -4,16 +4,10 @@ const mem = std.mem;
44const warn = std.log.warn;
55const fatal = std.process.fatal;
66
7pub fn main() !void {
8 var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
9 defer arena_instance.deinit();
10 const arena = arena_instance.allocator();
11
12 var threaded: std.Io.Threaded = .init(arena, .{});
13 defer threaded.deinit();
14 const io = threaded.io();
15
16 const args = try std.process.argsAlloc(arena);
7pub fn main(init: std.process.Init) !void {
8 const arena = init.arena.allocator();
9 const io = init.io;
10 const args = try init.args.toSlice(arena);
1711
1812 const exe = args[0];
1913 var catted_anything = false;