| author | |
| committer | |
| log | 960c512efd71ab4b658952fe8761453128cc8292 |
| tree | 5a519f99451bb6ad896dcfa438d8ebed77f2c03e |
| parent | a6f519c20f105a60c2ac51530354f9ac7c3e1fd9 |
14 files changed, 126 insertions(+), 119 deletions(-)
lib/compiler/std-docs.zig+36-33| ... | ... | @@ -21,19 +21,12 @@ fn usage(io: Io) noreturn { |
| 21 | 21 | std.process.exit(1); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | pub 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(); | |
| 24 | pub fn main(init: std.process.Init) !void { | |
| 25 | const arena = init.arena.allocator(); | |
| 26 | const gpa = init.gpa; | |
| 27 | const io = init.io; | |
| 31 | 28 | |
| 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); | |
| 37 | 30 | defer argv.deinit(); |
| 38 | 31 | assert(argv.skip()); |
| 39 | 32 | const zig_lib_directory = argv.next().?; |
| ... | ... | @@ -72,7 +65,7 @@ pub fn main() !void { |
| 72 | 65 | const url_with_newline = try std.fmt.allocPrint(arena, "http://127.0.0.1:{d}/\n", .{port}); |
| 73 | 66 | Io.File.stdout().writeStreamingAll(io, url_with_newline) catch {}; |
| 74 | 67 | 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| { | |
| 76 | 69 | std.log.err("unable to open browser: {t}", .{err}); |
| 77 | 70 | }; |
| 78 | 71 | } |
| ... | ... | @@ -324,11 +317,12 @@ fn buildWasmBinary( |
| 324 | 317 | "--listen=-", // |
| 325 | 318 | }); |
| 326 | 319 | |
| 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 | }); | |
| 332 | 326 | |
| 333 | 327 | var poller = Io.poll(gpa, enum { stdout, stderr }, .{ |
| 334 | 328 | .stdout = child.stdout.?, |
| ... | ... | @@ -388,19 +382,26 @@ fn buildWasmBinary( |
| 388 | 382 | child.stdin = null; |
| 389 | 383 | |
| 390 | 384 | switch (try child.wait(io)) { |
| 391 | .Exited => |code| { | |
| 385 | .exited => |code| { | |
| 392 | 386 | if (code != 0) { |
| 393 | 387 | std.log.err( |
| 394 | 388 | "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) }, | |
| 396 | 390 | ); |
| 397 | 391 | return error.WasmCompilationFailed; |
| 398 | 392 | } |
| 399 | 393 | }, |
| 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 => { | |
| 401 | 402 | std.log.err( |
| 402 | 403 | "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)}, | |
| 404 | 405 | ); |
| 405 | 406 | return error.WasmCompilationFailed; |
| 406 | 407 | }, |
| ... | ... | @@ -410,14 +411,14 @@ fn buildWasmBinary( |
| 410 | 411 | try result_error_bundle.renderToStderr(io, .{}, .auto); |
| 411 | 412 | std.log.err("the following command failed with {d} compilation errors:\n{s}", .{ |
| 412 | 413 | 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), | |
| 414 | 415 | }); |
| 415 | 416 | return error.WasmCompilationFailed; |
| 416 | 417 | } |
| 417 | 418 | |
| 418 | 419 | return result orelse { |
| 419 | 420 | 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), | |
| 421 | 422 | }); |
| 422 | 423 | return error.WasmCompilationFailed; |
| 423 | 424 | }; |
| ... | ... | @@ -434,22 +435,24 @@ fn sendMessage(io: Io, file: Io.File, tag: std.zig.Client.Message.Tag) !void { |
| 434 | 435 | }; |
| 435 | 436 | } |
| 436 | 437 | |
| 437 | fn openBrowserTab(gpa: Allocator, io: Io, url: []const u8) !void { | |
| 438 | fn openBrowserTab(io: Io, url: []const u8) !void { | |
| 438 | 439 | // 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 | |
| 441 | 443 | } |
| 442 | 444 | |
| 443 | fn openBrowserTabThread(gpa: Allocator, io: Io, url: []const u8) !void { | |
| 445 | fn openBrowserTabTask(io: Io, url: []const u8) !void { | |
| 444 | 446 | const main_exe = switch (builtin.os.tag) { |
| 445 | 447 | .windows => "explorer", |
| 446 | 448 | .macos => "open", |
| 447 | 449 | else => "xdg-open", |
| 448 | 450 | }; |
| 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 | }); | |
| 454 | 457 | _ = try child.wait(io); |
| 455 | 458 | } |
lib/compiler/translate-c/main.zig+4-13| ... | ... | @@ -9,19 +9,10 @@ const Translator = @import("Translator.zig"); |
| 9 | 9 | |
| 10 | 10 | const fast_exit = @import("builtin").mode != .Debug; |
| 11 | 11 | |
| 12 | var general_purpose_allocator: std.heap.GeneralPurposeAllocator(.{}) = .init; | |
| 13 | ||
| 14 | pub 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(); | |
| 12 | pub fn main(init: std.process.Init) u8 { | |
| 13 | const gpa = init.gpa; | |
| 14 | const arena = init.arena.allocator(); | |
| 15 | const io = init.io; | |
| 25 | 16 | |
| 26 | 17 | const args = process.argsAlloc(arena) catch { |
| 27 | 18 | std.debug.print("ran out of memory allocating arguments\n", .{}); |
lib/std/zig.zig+6| ... | ... | @@ -742,6 +742,7 @@ pub const EnvVar = enum { |
| 742 | 742 | ZIG_IS_DETECTING_LIBC_PATHS, |
| 743 | 743 | ZIG_IS_TRYING_TO_NOT_CALL_ITSELF, |
| 744 | 744 | |
| 745 | // C toolchain integration | |
| 745 | 746 | NIX_CFLAGS_COMPILE, |
| 746 | 747 | NIX_CFLAGS_LINK, |
| 747 | 748 | NIX_LDFLAGS, |
| ... | ... | @@ -750,13 +751,18 @@ pub const EnvVar = enum { |
| 750 | 751 | LIBRARY_PATH, |
| 751 | 752 | CC, |
| 752 | 753 | |
| 754 | // Terminal integration | |
| 753 | 755 | NO_COLOR, |
| 754 | 756 | CLICOLOR_FORCE, |
| 755 | 757 | |
| 758 | // Debug info integration | |
| 756 | 759 | XDG_CACHE_HOME, |
| 757 | 760 | LOCALAPPDATA, |
| 758 | 761 | HOME, |
| 759 | 762 | |
| 763 | // Windows SDK integration | |
| 764 | PROGRAMDATA, | |
| 765 | ||
| 760 | 766 | pub fn isSet(ev: EnvVar, map: *const std.process.Environ.Map) bool { |
| 761 | 767 | return map.contains(@tagName(ev)); |
| 762 | 768 | } |
lib/std/zig/LibCInstallation.zig+5-4| ... | ... | @@ -13,6 +13,7 @@ const fs = std.fs; |
| 13 | 13 | const Allocator = std.mem.Allocator; |
| 14 | 14 | const Path = std.Build.Cache.Path; |
| 15 | 15 | const log = std.log.scoped(.libc_installation); |
| 16 | const Environ = std.process.Environ; | |
| 16 | 17 | |
| 17 | 18 | include_dir: ?[]const u8 = null, |
| 18 | 19 | sys_include_dir: ?[]const u8 = null, |
| ... | ... | @@ -167,7 +168,7 @@ pub fn render(self: LibCInstallation, out: *std.Io.Writer) !void { |
| 167 | 168 | |
| 168 | 169 | pub const FindNativeOptions = struct { |
| 169 | 170 | target: *const std.Target, |
| 170 | env_map: *const std.process.Environ.Map, | |
| 171 | env_map: *const Environ.Map, | |
| 171 | 172 | |
| 172 | 173 | /// If enabled, will print human-friendly errors to stderr. |
| 173 | 174 | verbose: bool = false, |
| ... | ... | @@ -192,7 +193,7 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib |
| 192 | 193 | }); |
| 193 | 194 | return self; |
| 194 | 195 | } 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) { | |
| 196 | 197 | error.NotFound => return error.WindowsSdkNotFound, |
| 197 | 198 | error.PathTooLong => return error.WindowsSdkNotFound, |
| 198 | 199 | error.OutOfMemory => return error.OutOfMemory, |
| ... | ... | @@ -552,7 +553,7 @@ fn findNativeMsvcLibDir( |
| 552 | 553 | } |
| 553 | 554 | |
| 554 | 555 | pub const CCPrintFileNameOptions = struct { |
| 555 | env_map: *const std.process.Environ.Map, | |
| 556 | env_map: *const Environ.Map, | |
| 556 | 557 | search_basename: []const u8, |
| 557 | 558 | want_dirname: enum { full_path, only_dir }, |
| 558 | 559 | verbose: bool = false, |
| ... | ... | @@ -672,7 +673,7 @@ const inf_loop_env_key = "ZIG_IS_DETECTING_LIBC_PATHS"; |
| 672 | 673 | fn appendCcExe( |
| 673 | 674 | args: *std.array_list.Managed([]const u8), |
| 674 | 675 | skip_cc_env_var: bool, |
| 675 | env_map: *const std.process.Environ.Map, | |
| 676 | env_map: *const Environ.Map, | |
| 676 | 677 | ) !void { |
| 677 | 678 | const default_cc_exe = if (is_windows) "cc.exe" else "cc"; |
| 678 | 679 | try args.ensureUnusedCapacity(1); |
lib/std/zig/WindowsSdk.zig+41-23| ... | ... | @@ -6,6 +6,7 @@ const Io = std.Io; |
| 6 | 6 | const Dir = std.Io.Dir; |
| 7 | 7 | const Writer = std.Io.Writer; |
| 8 | 8 | const Allocator = std.mem.Allocator; |
| 9 | const Environ = std.process.Environ; | |
| 9 | 10 | |
| 10 | 11 | windows10sdk: ?Installation, |
| 11 | 12 | windows81sdk: ?Installation, |
| ... | ... | @@ -24,7 +25,12 @@ const product_version_max_length = version_major_minor_max_length + ".65535".len |
| 24 | 25 | /// Find path and version of Windows 10 SDK and Windows 8.1 SDK, and find path to MSVC's `lib/` directory. |
| 25 | 26 | /// Caller owns the result's fields. |
| 26 | 27 | /// Returns memory allocated by `gpa` |
| 27 | pub fn find(gpa: Allocator, io: Io, arch: std.Target.Cpu.Arch) error{ OutOfMemory, NotFound, PathTooLong }!WindowsSdk { | |
| 28 | pub 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 { | |
| 28 | 34 | if (builtin.os.tag != .windows) return error.NotFound; |
| 29 | 35 | |
| 30 | 36 | //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 |
| 49 | 55 | }; |
| 50 | 56 | errdefer if (windows81sdk) |*w| w.free(gpa); |
| 51 | 57 | |
| 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) { | |
| 53 | 59 | error.MsvcLibDirNotFound => null, |
| 54 | 60 | error.OutOfMemory => return error.OutOfMemory, |
| 55 | 61 | }; |
| ... | ... | @@ -671,7 +677,11 @@ const MsvcLibDir = struct { |
| 671 | 677 | return Dir.openDirAbsolute(io, instances_path, .{ .iterate = true }) catch return error.PathNotFound; |
| 672 | 678 | } |
| 673 | 679 | |
| 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 { | |
| 675 | 685 | // First, try getting the packages cache path from the registry. |
| 676 | 686 | // This only seems to exist when the path is different from the default. |
| 677 | 687 | method1: { |
| ... | ... | @@ -691,16 +701,13 @@ const MsvcLibDir = struct { |
| 691 | 701 | // If that can't be found, fall back to manually appending |
| 692 | 702 | // `Microsoft\VisualStudio\Packages\_Instances` to %PROGRAMDATA% |
| 693 | 703 | 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; | |
| 700 | 705 | |
| 701 | 706 | if (!Dir.path.isAbsolute(program_data)) break :method3; |
| 702 | 707 | |
| 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 | }); | |
| 704 | 711 | defer gpa.free(instances_path); |
| 705 | 712 | |
| 706 | 713 | return Dir.openDirAbsolute(io, instances_path, .{ .iterate = true }) catch break :method3; |
| ... | ... | @@ -754,12 +761,17 @@ const MsvcLibDir = struct { |
| 754 | 761 | /// |
| 755 | 762 | /// The logic in this function is intended to match what ISetupConfiguration does |
| 756 | 763 | /// 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 { | |
| 758 | 770 | // Typically `%PROGRAMDATA%\Microsoft\VisualStudio\Packages\_Instances` |
| 759 | 771 | // This will contain directories with names of instance IDs like 80a758ca, |
| 760 | 772 | // which will contain `state.json` files that have the version and |
| 761 | 773 | // installation directory. |
| 762 | var instances_dir = try findInstancesDir(gpa, io); | |
| 774 | var instances_dir = try findInstancesDir(gpa, io, env_map); | |
| 763 | 775 | defer instances_dir.close(io); |
| 764 | 776 | |
| 765 | 777 | var state_subpath_buf: [Dir.max_name_bytes + 32]u8 = undefined; |
| ... | ... | @@ -856,15 +868,16 @@ const MsvcLibDir = struct { |
| 856 | 868 | } |
| 857 | 869 | |
| 858 | 870 | // 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 { | |
| 860 | 877 | |
| 861 | 878 | // %localappdata%\Microsoft\VisualStudio\ |
| 862 | 879 | // %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; | |
| 868 | 881 | const visualstudio_folder_path = try Dir.path.join(gpa, &.{ |
| 869 | 882 | local_app_data_path, "Microsoft\\VisualStudio\\", |
| 870 | 883 | }); |
| ... | ... | @@ -955,7 +968,7 @@ const MsvcLibDir = struct { |
| 955 | 968 | gpa: Allocator, |
| 956 | 969 | io: Io, |
| 957 | 970 | arch: std.Target.Cpu.Arch, |
| 958 | env_map: *const std.process.Environ.Map, | |
| 971 | env_map: *const Environ.Map, | |
| 959 | 972 | ) error{ OutOfMemory, PathNotFound }![]const u8 { |
| 960 | 973 | var base_path: std.array_list.Managed(u8) = base_path: { |
| 961 | 974 | try_env: { |
| ... | ... | @@ -1029,12 +1042,17 @@ const MsvcLibDir = struct { |
| 1029 | 1042 | |
| 1030 | 1043 | /// Find path to MSVC's `lib/` directory. |
| 1031 | 1044 | /// 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) { | |
| 1034 | 1052 | 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) { | |
| 1036 | 1054 | 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) { | |
| 1038 | 1056 | error.OutOfMemory => return error.OutOfMemory, |
| 1039 | 1057 | error.PathNotFound => return error.MsvcLibDirNotFound, |
| 1040 | 1058 | }, |
src/Compilation.zig+1| ... | ... | @@ -2128,6 +2128,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, |
| 2128 | 2128 | .manifest_dir = options.dirs.local_cache.handle.createDirPathOpen(io, "h", .{}) catch |err| { |
| 2129 | 2129 | return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = "h", .err = err } }); |
| 2130 | 2130 | }, |
| 2131 | .cwd = options.dirs.cwd, | |
| 2131 | 2132 | }; |
| 2132 | 2133 | // These correspond to std.zig.Server.Message.PathPrefix. |
| 2133 | 2134 | cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() }); |
src/Zcu/PerThread.zig+1-4| ... | ... | @@ -2571,10 +2571,7 @@ fn newEmbedFile( |
| 2571 | 2571 | try whole.cache_manifest_mutex.lock(io); |
| 2572 | 2572 | defer whole.cache_manifest_mutex.unlock(io); |
| 2573 | 2573 | |
| 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); | |
| 2578 | 2575 | } |
| 2579 | 2576 | |
| 2580 | 2577 | return new_file; |
src/introspect.zig+8-7| ... | ... | @@ -6,6 +6,7 @@ const Dir = std.Io.Dir; |
| 6 | 6 | const mem = std.mem; |
| 7 | 7 | const Allocator = std.mem.Allocator; |
| 8 | 8 | const Cache = std.Build.Cache; |
| 9 | const assert = std.debug.assert; | |
| 9 | 10 | |
| 10 | 11 | const build_options = @import("build_options"); |
| 11 | 12 | |
| ... | ... | @@ -62,14 +63,14 @@ pub fn getResolvedCwd(gpa: Allocator) error{ |
| 62 | 63 | if (std.debug.runtime_safety) { |
| 63 | 64 | const cwd = try std.process.getCwdAlloc(gpa); |
| 64 | 65 | defer gpa.free(cwd); |
| 65 | std.debug.assert(mem.eql(u8, cwd, ".")); | |
| 66 | assert(mem.eql(u8, cwd, ".")); | |
| 66 | 67 | } |
| 67 | 68 | return ""; |
| 68 | 69 | } |
| 69 | 70 | const cwd = try std.process.getCwdAlloc(gpa); |
| 70 | 71 | defer gpa.free(cwd); |
| 71 | 72 | const resolved = try Dir.path.resolve(gpa, &.{cwd}); |
| 72 | std.debug.assert(Dir.path.isAbsolute(resolved)); | |
| 73 | assert(Dir.path.isAbsolute(resolved)); | |
| 73 | 74 | return resolved; |
| 74 | 75 | } |
| 75 | 76 | |
| ... | ... | @@ -140,7 +141,7 @@ pub fn resolvePath( |
| 140 | 141 | paths: []const []const u8, |
| 141 | 142 | ) Allocator.Error![]u8 { |
| 142 | 143 | if (builtin.target.os.tag == .wasi) { |
| 143 | std.debug.assert(mem.eql(u8, cwd_resolved, "")); | |
| 144 | assert(mem.eql(u8, cwd_resolved, "")); | |
| 144 | 145 | const res = try Dir.path.resolve(gpa, paths); |
| 145 | 146 | if (mem.eql(u8, res, ".")) { |
| 146 | 147 | gpa.free(res); |
| ... | ... | @@ -160,8 +161,8 @@ pub fn resolvePath( |
| 160 | 161 | gpa.free(res); |
| 161 | 162 | return ""; |
| 162 | 163 | } |
| 163 | std.debug.assert(!Dir.path.isAbsolute(res)); | |
| 164 | std.debug.assert(!isUpDir(res)); | |
| 164 | assert(!Dir.path.isAbsolute(res)); | |
| 165 | assert(!isUpDir(res)); | |
| 165 | 166 | return res; |
| 166 | 167 | } |
| 167 | 168 | |
| ... | ... | @@ -180,8 +181,8 @@ pub fn resolvePath( |
| 180 | 181 | }; |
| 181 | 182 | errdefer gpa.free(path_resolved); |
| 182 | 183 | |
| 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)); | |
| 185 | 186 | |
| 186 | 187 | if (!std.mem.startsWith(u8, path_resolved, cwd_resolved)) return path_resolved; // not in cwd |
| 187 | 188 | 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 { |
| 259 | 259 | .gpa = gpa, |
| 260 | 260 | .io = io, |
| 261 | 261 | .manifest_dir = try comp.dirs.global_cache.handle.createDirPathOpen(io, "h", .{}), |
| 262 | .cwd = comp.dirs.cwd, | |
| 262 | 263 | }; |
| 263 | 264 | cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() }); |
| 264 | 265 | cache.addPrefix(comp.dirs.zig_lib); |
test/standalone/child_process/main.zig+7-4| ... | ... | @@ -1,15 +1,15 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const Io = std.Io; |
| 3 | 3 | |
| 4 | pub fn main() !void { | |
| 4 | pub fn main(init: std.process.Init.Minimal) !void { | |
| 5 | 5 | // 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 }) = .{}; | |
| 7 | 7 | defer if (gpa_state.deinit() != .ok) { |
| 8 | 8 | @panic("found memory leaks"); |
| 9 | 9 | }; |
| 10 | 10 | const gpa = gpa_state.allocator(); |
| 11 | 11 | |
| 12 | var it = try std.process.argsWithAllocator(gpa); | |
| 12 | var it = try init.iterateAllocator(gpa); | |
| 13 | 13 | defer it.deinit(); |
| 14 | 14 | _ = it.next() orelse unreachable; // skip binary name |
| 15 | 15 | const child_path, const needs_free = child_path: { |
| ... | ... | @@ -21,7 +21,10 @@ pub fn main() !void { |
| 21 | 21 | }; |
| 22 | 22 | defer if (needs_free) gpa.free(child_path); |
| 23 | 23 | |
| 24 | var threaded: Io.Threaded = .init(gpa, .{}); | |
| 24 | var threaded: Io.Threaded = .init(gpa, .{ | |
| 25 | .argv0 = .init(init.args), | |
| 26 | .environ = init.environ, | |
| 27 | }); | |
| 25 | 28 | defer threaded.deinit(); |
| 26 | 29 | const io = threaded.io(); |
| 27 | 30 |
test/standalone/env_vars/main.zig+3-8| ... | ... | @@ -2,16 +2,11 @@ const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | |
| 4 | 4 | // Note: the environment variables under test are set by the build.zig |
| 5 | pub fn main() !void { | |
| 5 | pub fn main(init: std.process.Init) !void { | |
| 6 | 6 | @setEvalBranchQuota(10000); |
| 7 | 7 | |
| 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(); | |
| 15 | 10 | |
| 16 | 11 | // hasNonEmptyEnvVar |
| 17 | 12 | { |
test/standalone/run_output_paths/create_file.zig+3-3| ... | ... | @@ -1,8 +1,8 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | |
| 3 | pub fn main() !void { | |
| 4 | const io = std.Io.Threaded.global_single_threaded.ioBasic(); | |
| 5 | var args = try std.process.argsWithAllocator(std.heap.page_allocator); | |
| 3 | pub fn main(init: std.process.Init) !void { | |
| 4 | const io = init.io; | |
| 5 | var args = try init.args.iterateAllocator(init.arena.allocator()); | |
| 6 | 6 | _ = args.skip(); |
| 7 | 7 | const dir_name = args.next().?; |
| 8 | 8 | 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 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | |
| 3 | pub 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); | |
| 3 | pub 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); | |
| 9 | 7 | defer it.deinit(); |
| 10 | 8 | _ = it.next() orelse unreachable; // skip binary name |
| 11 | 9 | const exe_path = it.next() orelse unreachable; |
| 12 | 10 | const symlink_path = it.next() orelse unreachable; |
| 13 | 11 | |
| 14 | 12 | // 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); | |
| 19 | 15 | |
| 20 | 16 | try std.Io.Dir.cwd().symLink(io, exe_rel_path, symlink_path, .{}); |
| 21 | 17 | } |
test/standalone/simple/cat/main.zig+4-10| ... | ... | @@ -4,16 +4,10 @@ const mem = std.mem; |
| 4 | 4 | const warn = std.log.warn; |
| 5 | 5 | const fatal = std.process.fatal; |
| 6 | 6 | |
| 7 | pub 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); | |
| 7 | pub 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); | |
| 17 | 11 | |
| 18 | 12 | const exe = args[0]; |
| 19 | 13 | var catted_anything = false; |