From 97c59f685c74526c792fabc34db17f8a862b792c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 18 Mar 2024 23:59:35 -0700 Subject: [PATCH] fix darwin build --- src/DarwinPosixSpawn.zig | 10 +++++----- src/link/MachO.zig | 8 ++++---- src/main.zig | 39 ++++++++++++++++++++------------------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/DarwinPosixSpawn.zig b/src/DarwinPosixSpawn.zig index 336848353e6b..eaca94424175 100644 --- a/src/DarwinPosixSpawn.zig +++ b/src/DarwinPosixSpawn.zig @@ -81,7 +81,7 @@ pub const Actions = struct { } pub fn open(self: *Actions, fd: std.c.fd_t, path: []const u8, flags: u32, mode: std.c.mode_t) Error!void { - const posix_path = try std.os.toPosixPath(path); + const posix_path = try std.posix.toPosixPath(path); return self.openZ(fd, &posix_path, flags, mode); } @@ -130,7 +130,7 @@ pub const Actions = struct { } pub fn chdir(self: *Actions, path: []const u8) Error!void { - const posix_path = try std.os.toPosixPath(path); + const posix_path = try std.posix.toPosixPath(path); return self.chdirZ(&posix_path); } @@ -164,7 +164,7 @@ pub fn spawn( argv: [*:null]?[*:0]const u8, envp: [*:null]?[*:0]const u8, ) Error!std.c.pid_t { - const posix_path = try std.os.toPosixPath(path); + const posix_path = try std.posix.toPosixPath(path); return spawnZ(&posix_path, actions, attr, argv, envp); } @@ -204,12 +204,12 @@ pub fn spawnZ( } } -pub fn waitpid(pid: std.c.pid_t, flags: u32) Error!std.os.WaitPidResult { +pub fn waitpid(pid: std.c.pid_t, flags: u32) Error!std.posix.WaitPidResult { var status: c_int = undefined; while (true) { const rc = waitpid(pid, &status, @as(c_int, @intCast(flags))); switch (errno(rc)) { - .SUCCESS => return std.os.WaitPidResult{ + .SUCCESS => return std.posix.WaitPidResult{ .pid = @as(std.c.pid_t, @intCast(rc)), .status = @as(u32, @bitCast(status)), }, diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 6731f88e43ca..29ac89d26c0b 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -4136,10 +4136,10 @@ pub fn getDebugSymbols(self: *MachO) ?*DebugSymbols { return null; } -pub fn ptraceAttach(self: *MachO, pid: std.os.pid_t) !void { +pub fn ptraceAttach(self: *MachO, pid: std.posix.pid_t) !void { if (!is_hot_update_compatible) return; - const mach_task = try std.os.darwin.machTaskForPid(pid); + const mach_task = try std.c.machTaskForPid(pid); log.debug("Mach task for pid {d}: {any}", .{ pid, mach_task }); self.hot_state.mach_task = mach_task; @@ -4149,7 +4149,7 @@ pub fn ptraceAttach(self: *MachO, pid: std.os.pid_t) !void { // try std.os.ptrace(std.os.darwin.PT.ATTACHEXC, pid, 0, 0); } -pub fn ptraceDetach(self: *MachO, pid: std.os.pid_t) !void { +pub fn ptraceDetach(self: *MachO, pid: std.posix.pid_t) !void { if (!is_hot_update_compatible) return; _ = pid; @@ -4330,7 +4330,7 @@ const Section = struct { }; const HotUpdateState = struct { - mach_task: ?std.os.darwin.MachTask = null, + mach_task: ?std.c.MachTask = null, }; pub const DynamicRelocs = struct { diff --git a/src/main.zig b/src/main.zig index 4609109d15ad..be2083a0f8e4 100644 --- a/src/main.zig +++ b/src/main.zig @@ -12,6 +12,7 @@ const Color = std.zig.Color; const warn = std.log.warn; const ThreadPool = std.Thread.Pool; const cleanExit = std.process.cleanExit; +const native_os = builtin.os.tag; const tracy = @import("tracy.zig"); const Compilation = @import("Compilation.zig"); @@ -158,9 +159,9 @@ var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{ pub fn main() anyerror!void { crash_report.initialize(); - const use_gpa = (build_options.force_gpa or !builtin.link_libc) and builtin.os.tag != .wasi; + const use_gpa = (build_options.force_gpa or !builtin.link_libc) and native_os != .wasi; const gpa = gpa: { - if (builtin.os.tag == .wasi) { + if (native_os == .wasi) { break :gpa std.heap.wasm_allocator; } if (use_gpa) { @@ -187,7 +188,7 @@ pub fn main() anyerror!void { return mainArgs(gpa_tracy.allocator(), arena, args); } - if (builtin.os.tag == .wasi) { + if (native_os == .wasi) { wasi_preopens = try fs.wasi.preopensAlloc(arena); } @@ -813,9 +814,9 @@ fn buildOutputType( var no_builtin = false; var listen: Listen = .none; var debug_compile_errors = false; - var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and + var verbose_link = (native_os != .wasi or builtin.link_libc) and EnvVar.ZIG_VERBOSE_LINK.isSet(); - var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and + var verbose_cc = (native_os != .wasi or builtin.link_libc) and EnvVar.ZIG_VERBOSE_CC.isSet(); var verbose_air = false; var verbose_intern_pool = false; @@ -991,7 +992,7 @@ fn buildOutputType( // if it exists, default the color setting to .off // explicit --color arguments will still override this setting. // Disable color on WASI per https://github.com/WebAssembly/WASI/issues/162 - var color: Color = if (builtin.os.tag == .wasi or EnvVar.NO_COLOR.isSet()) .off else .auto; + var color: Color = if (native_os == .wasi or EnvVar.NO_COLOR.isSet()) .off else .auto; switch (arg_mode) { .build, .translate_c, .zig_test, .run => { @@ -2684,7 +2685,7 @@ fn buildOutputType( fatal("unable to open zig lib directory '{s}': {s}", .{ lib_dir, @errorName(err) }); }, }; - } else if (builtin.os.tag == .wasi) { + } else if (native_os == .wasi) { break :d getWasiPreopen("/lib"); } else if (self_exe_path) |p| { break :d introspect.findZigLibDirFromSelfExe(arena, p) catch |err| { @@ -2703,7 +2704,7 @@ fn buildOutputType( .path = p, }; } - if (builtin.os.tag == .wasi) { + if (native_os == .wasi) { break :l getWasiPreopen("/cache"); } const p = try introspect.resolveGlobalCacheDir(arena); @@ -4368,7 +4369,7 @@ fn runOrTest( } } else { const cmd = try std.mem.join(arena, " ", argv.items); - fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd }); + fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(native_os), cmd }); } } @@ -4747,9 +4748,9 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { var child_argv = std.ArrayList([]const u8).init(arena); var reference_trace: ?u32 = null; var debug_compile_errors = false; - var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and + var verbose_link = (native_os != .wasi or builtin.link_libc) and EnvVar.ZIG_VERBOSE_LINK.isSet(); - var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and + var verbose_cc = (native_os != .wasi or builtin.link_libc) and EnvVar.ZIG_VERBOSE_CC.isSet(); var verbose_air = false; var verbose_intern_pool = false; @@ -4894,7 +4895,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { } } - const work_around_btrfs_bug = builtin.os.tag == .linux and + const work_around_btrfs_bug = native_os == .linux and EnvVar.ZIG_BTRFS_WORKAROUND.isSet(); const color: Color = .auto; @@ -5311,7 +5312,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { } } else { const cmd = try std.mem.join(arena, " ", child_argv.items); - fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd }); + fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(native_os), cmd }); } } } @@ -5543,7 +5544,7 @@ fn jitCmd( if (!process.can_spawn) { const cmd = try std.mem.join(arena, " ", child_argv.items); fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ - @tagName(builtin.os.tag), cmd, + @tagName(native_os), cmd, }); } @@ -5655,7 +5656,7 @@ pub fn lldMain( var count: usize = 0; }; if (CallCounter.count == 1) { // Issue the warning on the first repeat call - warn("invoking LLD for the second time within the same process because the host OS ({s}) does not support spawning child processes. This sometimes activates LLD bugs", .{@tagName(builtin.os.tag)}); + warn("invoking LLD for the second time within the same process because the host OS ({s}) does not support spawning child processes. This sometimes activates LLD bugs", .{@tagName(native_os)}); } CallCounter.count += 1; @@ -5985,7 +5986,7 @@ fn parseCodeModel(arg: []const u8) std.builtin.CodeModel { /// garbage collector to run concurrently to zig processes, and to allow multiple /// zig processes to run concurrently with each other, without clobbering each other. fn gimmeMoreOfThoseSweetSweetFileDescriptors() void { - const have_rlimit = switch (builtin.os.tag) { + const have_rlimit = switch (native_os) { .windows, .wasi => false, else => true, }; @@ -5993,13 +5994,13 @@ fn gimmeMoreOfThoseSweetSweetFileDescriptors() void { const posix = std.posix; var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried. - if (comptime builtin.target.isDarwin()) { + if (native_os.isDarwin()) { // On Darwin, `NOFILE` is bounded by a hardcoded value `OPEN_MAX`. // According to the man pages for setrlimit(): // setrlimit() now returns with errno set to EINVAL in places that historically succeeded. // It no longer accepts "rlim_cur = RLIM.INFINITY" for RLIM.NOFILE. // Use "rlim_cur = min(OPEN_MAX, rlim_max)". - lim.max = @min(std.os.darwin.OPEN_MAX, lim.max); + lim.max = @min(std.c.OPEN_MAX, lim.max); } if (lim.cur == lim.max) return; @@ -6770,7 +6771,7 @@ fn cmdFetch( args: []const []const u8, ) !void { const color: Color = .auto; - const work_around_btrfs_bug = builtin.os.tag == .linux and + const work_around_btrfs_bug = native_os == .linux and EnvVar.ZIG_BTRFS_WORKAROUND.isSet(); var opt_path_or_url: ?[]const u8 = null; var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena);