Skip to content

Commit

Permalink
fix darwin build
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Mar 19, 2024
1 parent 364530b commit 97c59f6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
10 changes: 5 additions & 5 deletions src/DarwinPosixSpawn.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)),
},
Expand Down
8 changes: 4 additions & 4 deletions src/link/MachO.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
39 changes: 20 additions & 19 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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| {
Expand All @@ -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);
Expand Down Expand Up @@ -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 });
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 });
}
}
}
Expand Down Expand Up @@ -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,
});
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -5985,21 +5986,21 @@ 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,
};
if (!have_rlimit) return;
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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 97c59f6

Please sign in to comment.