Skip to content

Commit 97c59f6

Browse files
committed
fix darwin build
1 parent 364530b commit 97c59f6

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

src/DarwinPosixSpawn.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub const Actions = struct {
8181
}
8282

8383
pub fn open(self: *Actions, fd: std.c.fd_t, path: []const u8, flags: u32, mode: std.c.mode_t) Error!void {
84-
const posix_path = try std.os.toPosixPath(path);
84+
const posix_path = try std.posix.toPosixPath(path);
8585
return self.openZ(fd, &posix_path, flags, mode);
8686
}
8787

@@ -130,7 +130,7 @@ pub const Actions = struct {
130130
}
131131

132132
pub fn chdir(self: *Actions, path: []const u8) Error!void {
133-
const posix_path = try std.os.toPosixPath(path);
133+
const posix_path = try std.posix.toPosixPath(path);
134134
return self.chdirZ(&posix_path);
135135
}
136136

@@ -164,7 +164,7 @@ pub fn spawn(
164164
argv: [*:null]?[*:0]const u8,
165165
envp: [*:null]?[*:0]const u8,
166166
) Error!std.c.pid_t {
167-
const posix_path = try std.os.toPosixPath(path);
167+
const posix_path = try std.posix.toPosixPath(path);
168168
return spawnZ(&posix_path, actions, attr, argv, envp);
169169
}
170170

@@ -204,12 +204,12 @@ pub fn spawnZ(
204204
}
205205
}
206206

207-
pub fn waitpid(pid: std.c.pid_t, flags: u32) Error!std.os.WaitPidResult {
207+
pub fn waitpid(pid: std.c.pid_t, flags: u32) Error!std.posix.WaitPidResult {
208208
var status: c_int = undefined;
209209
while (true) {
210210
const rc = waitpid(pid, &status, @as(c_int, @intCast(flags)));
211211
switch (errno(rc)) {
212-
.SUCCESS => return std.os.WaitPidResult{
212+
.SUCCESS => return std.posix.WaitPidResult{
213213
.pid = @as(std.c.pid_t, @intCast(rc)),
214214
.status = @as(u32, @bitCast(status)),
215215
},

src/link/MachO.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4136,10 +4136,10 @@ pub fn getDebugSymbols(self: *MachO) ?*DebugSymbols {
41364136
return null;
41374137
}
41384138

4139-
pub fn ptraceAttach(self: *MachO, pid: std.os.pid_t) !void {
4139+
pub fn ptraceAttach(self: *MachO, pid: std.posix.pid_t) !void {
41404140
if (!is_hot_update_compatible) return;
41414141

4142-
const mach_task = try std.os.darwin.machTaskForPid(pid);
4142+
const mach_task = try std.c.machTaskForPid(pid);
41434143
log.debug("Mach task for pid {d}: {any}", .{ pid, mach_task });
41444144
self.hot_state.mach_task = mach_task;
41454145

@@ -4149,7 +4149,7 @@ pub fn ptraceAttach(self: *MachO, pid: std.os.pid_t) !void {
41494149
// try std.os.ptrace(std.os.darwin.PT.ATTACHEXC, pid, 0, 0);
41504150
}
41514151

4152-
pub fn ptraceDetach(self: *MachO, pid: std.os.pid_t) !void {
4152+
pub fn ptraceDetach(self: *MachO, pid: std.posix.pid_t) !void {
41534153
if (!is_hot_update_compatible) return;
41544154

41554155
_ = pid;
@@ -4330,7 +4330,7 @@ const Section = struct {
43304330
};
43314331

43324332
const HotUpdateState = struct {
4333-
mach_task: ?std.os.darwin.MachTask = null,
4333+
mach_task: ?std.c.MachTask = null,
43344334
};
43354335

43364336
pub const DynamicRelocs = struct {

src/main.zig

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const Color = std.zig.Color;
1212
const warn = std.log.warn;
1313
const ThreadPool = std.Thread.Pool;
1414
const cleanExit = std.process.cleanExit;
15+
const native_os = builtin.os.tag;
1516

1617
const tracy = @import("tracy.zig");
1718
const Compilation = @import("Compilation.zig");
@@ -158,9 +159,9 @@ var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{
158159
pub fn main() anyerror!void {
159160
crash_report.initialize();
160161

161-
const use_gpa = (build_options.force_gpa or !builtin.link_libc) and builtin.os.tag != .wasi;
162+
const use_gpa = (build_options.force_gpa or !builtin.link_libc) and native_os != .wasi;
162163
const gpa = gpa: {
163-
if (builtin.os.tag == .wasi) {
164+
if (native_os == .wasi) {
164165
break :gpa std.heap.wasm_allocator;
165166
}
166167
if (use_gpa) {
@@ -187,7 +188,7 @@ pub fn main() anyerror!void {
187188
return mainArgs(gpa_tracy.allocator(), arena, args);
188189
}
189190

190-
if (builtin.os.tag == .wasi) {
191+
if (native_os == .wasi) {
191192
wasi_preopens = try fs.wasi.preopensAlloc(arena);
192193
}
193194

@@ -813,9 +814,9 @@ fn buildOutputType(
813814
var no_builtin = false;
814815
var listen: Listen = .none;
815816
var debug_compile_errors = false;
816-
var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and
817+
var verbose_link = (native_os != .wasi or builtin.link_libc) and
817818
EnvVar.ZIG_VERBOSE_LINK.isSet();
818-
var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and
819+
var verbose_cc = (native_os != .wasi or builtin.link_libc) and
819820
EnvVar.ZIG_VERBOSE_CC.isSet();
820821
var verbose_air = false;
821822
var verbose_intern_pool = false;
@@ -991,7 +992,7 @@ fn buildOutputType(
991992
// if it exists, default the color setting to .off
992993
// explicit --color arguments will still override this setting.
993994
// Disable color on WASI per https://github.com/WebAssembly/WASI/issues/162
994-
var color: Color = if (builtin.os.tag == .wasi or EnvVar.NO_COLOR.isSet()) .off else .auto;
995+
var color: Color = if (native_os == .wasi or EnvVar.NO_COLOR.isSet()) .off else .auto;
995996

996997
switch (arg_mode) {
997998
.build, .translate_c, .zig_test, .run => {
@@ -2684,7 +2685,7 @@ fn buildOutputType(
26842685
fatal("unable to open zig lib directory '{s}': {s}", .{ lib_dir, @errorName(err) });
26852686
},
26862687
};
2687-
} else if (builtin.os.tag == .wasi) {
2688+
} else if (native_os == .wasi) {
26882689
break :d getWasiPreopen("/lib");
26892690
} else if (self_exe_path) |p| {
26902691
break :d introspect.findZigLibDirFromSelfExe(arena, p) catch |err| {
@@ -2703,7 +2704,7 @@ fn buildOutputType(
27032704
.path = p,
27042705
};
27052706
}
2706-
if (builtin.os.tag == .wasi) {
2707+
if (native_os == .wasi) {
27072708
break :l getWasiPreopen("/cache");
27082709
}
27092710
const p = try introspect.resolveGlobalCacheDir(arena);
@@ -4368,7 +4369,7 @@ fn runOrTest(
43684369
}
43694370
} else {
43704371
const cmd = try std.mem.join(arena, " ", argv.items);
4371-
fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
4372+
fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(native_os), cmd });
43724373
}
43734374
}
43744375

@@ -4747,9 +4748,9 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
47474748
var child_argv = std.ArrayList([]const u8).init(arena);
47484749
var reference_trace: ?u32 = null;
47494750
var debug_compile_errors = false;
4750-
var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and
4751+
var verbose_link = (native_os != .wasi or builtin.link_libc) and
47514752
EnvVar.ZIG_VERBOSE_LINK.isSet();
4752-
var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and
4753+
var verbose_cc = (native_os != .wasi or builtin.link_libc) and
47534754
EnvVar.ZIG_VERBOSE_CC.isSet();
47544755
var verbose_air = false;
47554756
var verbose_intern_pool = false;
@@ -4894,7 +4895,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
48944895
}
48954896
}
48964897

4897-
const work_around_btrfs_bug = builtin.os.tag == .linux and
4898+
const work_around_btrfs_bug = native_os == .linux and
48984899
EnvVar.ZIG_BTRFS_WORKAROUND.isSet();
48994900
const color: Color = .auto;
49004901

@@ -5311,7 +5312,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
53115312
}
53125313
} else {
53135314
const cmd = try std.mem.join(arena, " ", child_argv.items);
5314-
fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
5315+
fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(native_os), cmd });
53155316
}
53165317
}
53175318
}
@@ -5543,7 +5544,7 @@ fn jitCmd(
55435544
if (!process.can_spawn) {
55445545
const cmd = try std.mem.join(arena, " ", child_argv.items);
55455546
fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{
5546-
@tagName(builtin.os.tag), cmd,
5547+
@tagName(native_os), cmd,
55475548
});
55485549
}
55495550

@@ -5655,7 +5656,7 @@ pub fn lldMain(
56555656
var count: usize = 0;
56565657
};
56575658
if (CallCounter.count == 1) { // Issue the warning on the first repeat call
5658-
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)});
5659+
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)});
56595660
}
56605661
CallCounter.count += 1;
56615662

@@ -5985,21 +5986,21 @@ fn parseCodeModel(arg: []const u8) std.builtin.CodeModel {
59855986
/// garbage collector to run concurrently to zig processes, and to allow multiple
59865987
/// zig processes to run concurrently with each other, without clobbering each other.
59875988
fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {
5988-
const have_rlimit = switch (builtin.os.tag) {
5989+
const have_rlimit = switch (native_os) {
59895990
.windows, .wasi => false,
59905991
else => true,
59915992
};
59925993
if (!have_rlimit) return;
59935994
const posix = std.posix;
59945995

59955996
var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried.
5996-
if (comptime builtin.target.isDarwin()) {
5997+
if (native_os.isDarwin()) {
59975998
// On Darwin, `NOFILE` is bounded by a hardcoded value `OPEN_MAX`.
59985999
// According to the man pages for setrlimit():
59996000
// setrlimit() now returns with errno set to EINVAL in places that historically succeeded.
60006001
// It no longer accepts "rlim_cur = RLIM.INFINITY" for RLIM.NOFILE.
60016002
// Use "rlim_cur = min(OPEN_MAX, rlim_max)".
6002-
lim.max = @min(std.os.darwin.OPEN_MAX, lim.max);
6003+
lim.max = @min(std.c.OPEN_MAX, lim.max);
60036004
}
60046005
if (lim.cur == lim.max) return;
60056006

@@ -6770,7 +6771,7 @@ fn cmdFetch(
67706771
args: []const []const u8,
67716772
) !void {
67726773
const color: Color = .auto;
6773-
const work_around_btrfs_bug = builtin.os.tag == .linux and
6774+
const work_around_btrfs_bug = native_os == .linux and
67746775
EnvVar.ZIG_BTRFS_WORKAROUND.isSet();
67756776
var opt_path_or_url: ?[]const u8 = null;
67766777
var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena);

0 commit comments

Comments
 (0)