authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-15 15:34:14-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:09-08:00
log22afd168d95b1d6be4a99196e07573bed8f4b472
tree253622ccb9c6cee2a2326ef7bb73c0f5ed34c314
parent9407ad8516378c9e7cb739a7e8ef39965ba02d45

fix build runner compilation errors on macOS


7 files changed, 38 insertions(+), 34 deletions(-)

lib/std/Build/Watch/FsEvents.zig+2-2
...@@ -78,10 +78,10 @@ const ResolvedSymbols = struct {...@@ -78,10 +78,10 @@ const ResolvedSymbols = struct {
78 kCFAllocatorUseContext: *const CFAllocatorRef,78 kCFAllocatorUseContext: *const CFAllocatorRef,
79};79};
8080
81pub fn init(io: Io) error{ OpenFrameworkFailed, MissingCoreServicesSymbol }!FsEvents {81pub fn init() error{ OpenFrameworkFailed, MissingCoreServicesSymbol }!FsEvents {
82 var core_services = std.DynLib.open("/System/Library/Frameworks/CoreServices.framework/CoreServices") catch82 var core_services = std.DynLib.open("/System/Library/Frameworks/CoreServices.framework/CoreServices") catch
83 return error.OpenFrameworkFailed;83 return error.OpenFrameworkFailed;
84 errdefer core_services.close(io);84 errdefer core_services.close();
8585
86 var resolved_symbols: ResolvedSymbols = undefined;86 var resolved_symbols: ResolvedSymbols = undefined;
87 inline for (@typeInfo(ResolvedSymbols).@"struct".fields) |f| {87 inline for (@typeInfo(ResolvedSymbols).@"struct".fields) |f| {
lib/std/Io/Dir.zig+2
...@@ -377,6 +377,8 @@ pub fn walk(dir: Dir, allocator: Allocator) Allocator.Error!Walker {...@@ -377,6 +377,8 @@ pub fn walk(dir: Dir, allocator: Allocator) Allocator.Error!Walker {
377pub const Handle = std.posix.fd_t;377pub const Handle = std.posix.fd_t;
378378
379pub const PathNameError = error{379pub const PathNameError = error{
380 /// Returned when an insufficient buffer is provided that cannot fit the
381 /// path name.
380 NameTooLong,382 NameTooLong,
381 /// File system cannot encode the requested file name bytes.383 /// File system cannot encode the requested file name bytes.
382 /// Could be due to invalid WTF-8 on Windows, invalid UTF-8 on WASI,384 /// Could be due to invalid WTF-8 on Windows, invalid UTF-8 on WASI,
lib/std/Io/Threaded.zig+23-21
...@@ -2033,7 +2033,7 @@ fn fileLength(userdata: ?*anyopaque, file: File) File.LengthError!u64 {...@@ -2033,7 +2033,7 @@ fn fileLength(userdata: ?*anyopaque, file: File) File.LengthError!u64 {
2033 // TODO call NtQueryInformationFile and ask for only the size instead of "all"2033 // TODO call NtQueryInformationFile and ask for only the size instead of "all"
2034 }2034 }
20352035
2036 const stat = try fileStat(ioBasic(t), file);2036 const stat = try fileStat(t, file);
2037 return stat.size;2037 return stat.size;
2038}2038}
20392039
...@@ -3429,7 +3429,7 @@ fn dirReadDarwin(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) Di...@@ -3429,7 +3429,7 @@ fn dirReadDarwin(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) Di
3429 const dents_buffer = dr.buffer[header_end..];3429 const dents_buffer = dr.buffer[header_end..];
3430 try current_thread.beginSyscall();3430 try current_thread.beginSyscall();
3431 const n: usize = while (true) {3431 const n: usize = while (true) {
3432 const rc = posix.system.getdirentries(dr.dir.fd, dents_buffer.ptr, dents_buffer.len, &header.seek);3432 const rc = posix.system.getdirentries(dr.dir.handle, dents_buffer.ptr, dents_buffer.len, &header.seek);
3433 switch (posix.errno(rc)) {3433 switch (posix.errno(rc)) {
3434 .SUCCESS => {3434 .SUCCESS => {
3435 current_thread.endSyscall();3435 current_thread.endSyscall();
...@@ -3735,9 +3735,11 @@ fn dirRealPathPosix(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, out_b...@@ -3735,9 +3735,11 @@ fn dirRealPathPosix(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, out_b
3735 if (@hasField(posix.O, "CLOEXEC")) flags.CLOEXEC = true;3735 if (@hasField(posix.O, "CLOEXEC")) flags.CLOEXEC = true;
3736 if (@hasField(posix.O, "PATH")) flags.PATH = true;3736 if (@hasField(posix.O, "PATH")) flags.PATH = true;
37373737
3738 const mode: posix.mode_t = 0;
3739
3738 try current_thread.beginSyscall();3740 try current_thread.beginSyscall();
3739 const fd: posix.fd_t = while (true) {3741 const fd: posix.fd_t = while (true) {
3740 const rc = openat_sym(dir.handle, sub_path_posix, flags, 0);3742 const rc = openat_sym(dir.handle, sub_path_posix, flags, mode);
3741 switch (posix.errno(rc)) {3743 switch (posix.errno(rc)) {
3742 .SUCCESS => {3744 .SUCCESS => {
3743 current_thread.endSyscall();3745 current_thread.endSyscall();
...@@ -3784,10 +3786,11 @@ fn dirRealPathPosix(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, out_b...@@ -3784,10 +3786,11 @@ fn dirRealPathPosix(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, out_b
3784 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => {3786 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => {
3785 // On macOS, we can use F.GETPATH fcntl command to query the OS for3787 // On macOS, we can use F.GETPATH fcntl command to query the OS for
3786 // the path to the file descriptor.3788 // the path to the file descriptor.
3787 @memset(out_buffer, 0);3789 var sufficient_buffer: [posix.PATH_MAX]u8 = undefined;
3790 @memset(&sufficient_buffer, 0);
3788 try current_thread.beginSyscall();3791 try current_thread.beginSyscall();
3789 while (true) {3792 while (true) {
3790 switch (posix.errno(posix.system.fcntl(fd, posix.F.GETPATH, out_buffer))) {3793 switch (posix.errno(posix.system.fcntl(fd, posix.F.GETPATH, &sufficient_buffer))) {
3791 .SUCCESS => {3794 .SUCCESS => {
3792 current_thread.endSyscall();3795 current_thread.endSyscall();
3793 break;3796 break;
...@@ -3803,14 +3806,15 @@ fn dirRealPathPosix(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, out_b...@@ -3803,14 +3806,15 @@ fn dirRealPathPosix(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, out_b
3803 .BADF => return error.FileNotFound,3806 .BADF => return error.FileNotFound,
3804 .NOSPC => return error.NameTooLong,3807 .NOSPC => return error.NameTooLong,
3805 .NOENT => return error.FileNotFound,3808 .NOENT => return error.FileNotFound,
3806 // TODO man pages for fcntl on macOS don't really tell you what
3807 // errno values to expect when command is F.GETPATH...
3808 else => |err| return posix.unexpectedErrno(err),3809 else => |err| return posix.unexpectedErrno(err),
3809 }3810 }
3810 },3811 },
3811 }3812 }
3812 }3813 }
3813 return std.mem.indexOfScalar(u8, &out_buffer, 0) orelse out_buffer.len;3814 const n = std.mem.indexOfScalar(u8, &sufficient_buffer, 0) orelse sufficient_buffer.len;
3815 if (n > out_buffer.len) return error.NameTooLong;
3816 @memcpy(out_buffer[0..n], sufficient_buffer[0..n]);
3817 return n;
3814 },3818 },
3815 .linux, .serenity, .illumos => {3819 .linux, .serenity, .illumos => {
3816 var procfs_buf: ["/proc/self/path/-2147483648\x00".len]u8 = undefined;3820 var procfs_buf: ["/proc/self/path/-2147483648\x00".len]u8 = undefined;
...@@ -6578,7 +6582,6 @@ fn processExecutableOpen(userdata: ?*anyopaque, flags: File.OpenFlags) std.proce...@@ -6578,7 +6582,6 @@ fn processExecutableOpen(userdata: ?*anyopaque, flags: File.OpenFlags) std.proce
65786582
6579fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.ExecutablePathError!usize {6583fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.ExecutablePathError!usize {
6580 const t: *Threaded = @ptrCast(@alignCast(userdata));6584 const t: *Threaded = @ptrCast(@alignCast(userdata));
6581 const max_path_bytes = std.fs.max_path_bytes;
65826585
6583 switch (native_os) {6586 switch (native_os) {
6584 .driverkit,6587 .driverkit,
...@@ -6591,20 +6594,19 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex...@@ -6591,20 +6594,19 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex
6591 => {6594 => {
6592 // Note that _NSGetExecutablePath() will return "a path" to6595 // Note that _NSGetExecutablePath() will return "a path" to
6593 // the executable not a "real path" to the executable.6596 // the executable not a "real path" to the executable.
6594 var symlink_path_buf: [max_path_bytes:0]u8 = undefined;6597 var symlink_path_buf: [posix.PATH_MAX:0]u8 = undefined;
6595 var u32_len: u32 = max_path_bytes + 1; // include the sentinel6598 var u32_len: u32 = posix.PATH_MAX + 1; // include the sentinel
6596 const rc = std.c._NSGetExecutablePath(&symlink_path_buf, &u32_len);6599 const rc = std.c._NSGetExecutablePath(&symlink_path_buf, &u32_len);
6597 if (rc != 0) return error.NameTooLong;6600 if (rc != 0) return error.NameTooLong;
65986601
6599 var real_path_buf: [max_path_bytes]u8 = undefined;6602 var real_path_buf: [posix.PATH_MAX]u8 = undefined;
6600 const real_path = Io.Dir.realPathAbsolute(ioBasic(t), &symlink_path_buf, &real_path_buf) catch |err| switch (err) {6603 const n = Io.Dir.realPathAbsolute(ioBasic(t), &symlink_path_buf, &real_path_buf) catch |err| switch (err) {
6601 error.NetworkNotFound => unreachable, // Windows-only6604 error.NetworkNotFound => unreachable, // Windows-only
6602 else => |e| return e,6605 else => |e| return e,
6603 };6606 };
6604 if (real_path.len > out_buffer.len) return error.NameTooLong;6607 if (n > out_buffer.len) return error.NameTooLong;
6605 const result = out_buffer[0..real_path.len];6608 @memcpy(out_buffer[0..n], real_path_buf[0..n]);
6606 @memcpy(result, real_path);6609 return n;
6607 return result.len;
6608 },6610 },
6609 .linux, .serenity => return Io.Dir.readLinkAbsolute(ioBasic(t), "/proc/self/exe", out_buffer) catch |err| switch (err) {6611 .linux, .serenity => return Io.Dir.readLinkAbsolute(ioBasic(t), "/proc/self/exe", out_buffer) catch |err| switch (err) {
6610 error.UnsupportedReparsePointType => unreachable, // Windows-only6612 error.UnsupportedReparsePointType => unreachable, // Windows-only
...@@ -6640,7 +6642,7 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex...@@ -6640,7 +6642,7 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex
6640 const argv0 = std.mem.span(std.os.argv[0]);6642 const argv0 = std.mem.span(std.os.argv[0]);
6641 if (std.mem.indexOf(u8, argv0, "/") != null) {6643 if (std.mem.indexOf(u8, argv0, "/") != null) {
6642 // argv[0] is a path (relative or absolute): use realpath(3) directly6644 // argv[0] is a path (relative or absolute): use realpath(3) directly
6643 var real_path_buf: [max_path_bytes]u8 = undefined;6645 var real_path_buf: [posix.PATH_MAX]u8 = undefined;
6644 const real_path = Io.Dir.realPathAbsolute(ioBasic(t), std.os.argv[0], &real_path_buf) catch |err| switch (err) {6646 const real_path = Io.Dir.realPathAbsolute(ioBasic(t), std.os.argv[0], &real_path_buf) catch |err| switch (err) {
6645 error.NetworkNotFound => unreachable, // Windows-only6647 error.NetworkNotFound => unreachable, // Windows-only
6646 else => |e| return e,6648 else => |e| return e,
...@@ -6655,12 +6657,12 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex...@@ -6655,12 +6657,12 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex
6655 const PATH = posix.getenvZ("PATH") orelse return error.FileNotFound;6657 const PATH = posix.getenvZ("PATH") orelse return error.FileNotFound;
6656 var path_it = std.mem.tokenizeScalar(u8, PATH, std.fs.path.delimiter);6658 var path_it = std.mem.tokenizeScalar(u8, PATH, std.fs.path.delimiter);
6657 while (path_it.next()) |a_path| {6659 while (path_it.next()) |a_path| {
6658 var resolved_path_buf: [max_path_bytes - 1:0]u8 = undefined;6660 var resolved_path_buf: [posix.PATH_MAX - 1:0]u8 = undefined;
6659 const resolved_path = std.fmt.bufPrintSentinel(&resolved_path_buf, "{s}/{s}", .{6661 const resolved_path = std.fmt.bufPrintSentinel(&resolved_path_buf, "{s}/{s}", .{
6660 a_path, std.os.argv[0],6662 a_path, std.os.argv[0],
6661 }, 0) catch continue;6663 }, 0) catch continue;
66626664
6663 var real_path_buf: [max_path_bytes]u8 = undefined;6665 var real_path_buf: [posix.PATH_MAX]u8 = undefined;
6664 if (Io.Dir.realPathAbsolute(ioBasic(t), resolved_path, &real_path_buf)) |real_path| {6666 if (Io.Dir.realPathAbsolute(ioBasic(t), resolved_path, &real_path_buf)) |real_path| {
6665 // found a file, and hope it is the right file6667 // found a file, and hope it is the right file
6666 if (real_path.len > out_buffer.len)6668 if (real_path.len > out_buffer.len)
...@@ -7566,7 +7568,7 @@ fn fileWriteFilePositional(...@@ -7566,7 +7568,7 @@ fn fileWriteFilePositional(
7566 current_thread.endSyscall();7568 current_thread.endSyscall();
7567 assert(error.Unexpected == switch (e) {7569 assert(error.Unexpected == switch (e) {
7568 .NOMEM => return error.SystemResources,7570 .NOMEM => return error.SystemResources,
7569 .INVAL => |err| posix.errnoBug(err),7571 .INVAL => |err| errnoBug(err),
7570 else => |err| posix.unexpectedErrno(err),7572 else => |err| posix.unexpectedErrno(err),
7571 });7573 });
7572 return 0;7574 return 0;
lib/std/debug/SelfInfo/MachO.zig+6-6
...@@ -21,11 +21,10 @@ pub fn deinit(si: *SelfInfo, gpa: Allocator) void {...@@ -21,11 +21,10 @@ pub fn deinit(si: *SelfInfo, gpa: Allocator) void {
21}21}
2222
23pub fn getSymbol(si: *SelfInfo, gpa: Allocator, io: Io, address: usize) Error!std.debug.Symbol {23pub fn getSymbol(si: *SelfInfo, gpa: Allocator, io: Io, address: usize) Error!std.debug.Symbol {
24 _ = io;
25 const module = try si.findModule(gpa, address);24 const module = try si.findModule(gpa, address);
26 defer si.mutex.unlock();25 defer si.mutex.unlock();
2726
28 const file = try module.getFile(gpa);27 const file = try module.getFile(gpa, io);
2928
30 // This is not necessarily the same as the vmaddr_slide that dyld would report. This is29 // This is not necessarily the same as the vmaddr_slide that dyld would report. This is
31 // because the segments in the file on disk might differ from the ones in memory. Normally30 // because the segments in the file on disk might differ from the ones in memory. Normally
...@@ -39,7 +38,7 @@ pub fn getSymbol(si: *SelfInfo, gpa: Allocator, io: Io, address: usize) Error!st...@@ -39,7 +38,7 @@ pub fn getSymbol(si: *SelfInfo, gpa: Allocator, io: Io, address: usize) Error!st
3938
40 const vaddr = address - vaddr_offset;39 const vaddr = address - vaddr_offset;
4140
42 const ofile_dwarf, const ofile_vaddr = file.getDwarfForAddress(gpa, vaddr) catch {41 const ofile_dwarf, const ofile_vaddr = file.getDwarfForAddress(gpa, io, vaddr) catch {
43 // Return at least the symbol name if available.42 // Return at least the symbol name if available.
44 return .{43 return .{
45 .name = try file.lookupSymbolName(vaddr),44 .name = try file.lookupSymbolName(vaddr),
...@@ -107,7 +106,8 @@ pub const UnwindContext = std.debug.Dwarf.SelfUnwinder;...@@ -107,7 +106,8 @@ pub const UnwindContext = std.debug.Dwarf.SelfUnwinder;
107/// Unwind a frame using MachO compact unwind info (from `__unwind_info`).106/// Unwind a frame using MachO compact unwind info (from `__unwind_info`).
108/// If the compact encoding can't encode a way to unwind a frame, it will107/// If the compact encoding can't encode a way to unwind a frame, it will
109/// defer unwinding to DWARF, in which case `__eh_frame` will be used if available.108/// defer unwinding to DWARF, in which case `__eh_frame` will be used if available.
110pub fn unwindFrame(si: *SelfInfo, gpa: Allocator, context: *UnwindContext) Error!usize {109pub fn unwindFrame(si: *SelfInfo, gpa: Allocator, io: Io, context: *UnwindContext) Error!usize {
110 _ = io;
111 return unwindFrameInner(si, gpa, context) catch |err| switch (err) {111 return unwindFrameInner(si, gpa, context) catch |err| switch (err) {
112 error.InvalidDebugInfo,112 error.InvalidDebugInfo,
113 error.MissingDebugInfo,113 error.MissingDebugInfo,
...@@ -546,12 +546,12 @@ const Module = struct {...@@ -546,12 +546,12 @@ const Module = struct {
546 };546 };
547 }547 }
548548
549 fn getFile(module: *Module, gpa: Allocator) Error!*MachOFile {549 fn getFile(module: *Module, gpa: Allocator, io: Io) Error!*MachOFile {
550 if (module.file == null) {550 if (module.file == null) {
551 const path = std.mem.span(551 const path = std.mem.span(
552 std.c.dyld_image_path_containing_address(@ptrFromInt(module.text_base)).?,552 std.c.dyld_image_path_containing_address(@ptrFromInt(module.text_base)).?,
553 );553 );
554 module.file = MachOFile.load(gpa, path, builtin.cpu.arch) catch |err| switch (err) {554 module.file = MachOFile.load(gpa, io, path, builtin.cpu.arch) catch |err| switch (err) {
555 error.InvalidMachO, error.InvalidDwarf => error.InvalidDebugInfo,555 error.InvalidMachO, error.InvalidDwarf => error.InvalidDebugInfo,
556 error.MissingDebugInfo, error.OutOfMemory, error.UnsupportedDebugInfo, error.ReadFailed => |e| e,556 error.MissingDebugInfo, error.OutOfMemory, error.UnsupportedDebugInfo, error.ReadFailed => |e| e,
557 };557 };
lib/std/dynamic_library.zig+2-2
...@@ -40,8 +40,8 @@ pub const DynLib = struct {...@@ -40,8 +40,8 @@ pub const DynLib = struct {
40 }40 }
4141
42 /// Trusts the file.42 /// Trusts the file.
43 pub fn close(self: *DynLib, io: Io) void {43 pub fn close(self: *DynLib) void {
44 return self.inner.close(io);44 return self.inner.close();
45 }45 }
4646
47 pub fn lookup(self: *DynLib, comptime T: type, name: [:0]const u8) ?T {47 pub fn lookup(self: *DynLib, comptime T: type, name: [:0]const u8) ?T {
lib/std/zig/system.zig+1-1
...@@ -248,7 +248,7 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {...@@ -248,7 +248,7 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {
248 os.version_range.windows.min = detected_version;248 os.version_range.windows.min = detected_version;
249 os.version_range.windows.max = detected_version;249 os.version_range.windows.max = detected_version;
250 },250 },
251 .macos => try darwin.macos.detect(&os),251 .macos => try darwin.macos.detect(io, &os),
252 .freebsd, .netbsd, .dragonfly => {252 .freebsd, .netbsd, .dragonfly => {
253 const key = switch (builtin.target.os.tag) {253 const key = switch (builtin.target.os.tag) {
254 .freebsd => "kern.osreldate",254 .freebsd => "kern.osreldate",
lib/std/zig/system/darwin/macos.zig+2-2
...@@ -9,7 +9,7 @@ const Target = std.Target;...@@ -9,7 +9,7 @@ const Target = std.Target;
99
10/// Detect macOS version.10/// Detect macOS version.
11/// `target_os` is not modified in case of error.11/// `target_os` is not modified in case of error.
12pub fn detect(target_os: *Target.Os) !void {12pub fn detect(io: Io, target_os: *Target.Os) !void {
13 // Drop use of osproductversion sysctl because:13 // Drop use of osproductversion sysctl because:
14 // 1. only available 10.13.4 High Sierra and later14 // 1. only available 10.13.4 High Sierra and later
15 // 2. when used from a binary built against < SDK 11.0 it returns 10.16 and masks Big Sur 11.x version15 // 2. when used from a binary built against < SDK 11.0 it returns 10.16 and masks Big Sur 11.x version
...@@ -55,7 +55,7 @@ pub fn detect(target_os: *Target.Os) !void {...@@ -55,7 +55,7 @@ pub fn detect(target_os: *Target.Os) !void {
55 // approx. 4 times historical file size55 // approx. 4 times historical file size
56 var buf: [2048]u8 = undefined;56 var buf: [2048]u8 = undefined;
5757
58 if (Io.Dir.cwd().readFile(path, &buf)) |bytes| {58 if (Io.Dir.cwd().readFile(io, path, &buf)) |bytes| {
59 if (parseSystemVersion(bytes)) |ver| {59 if (parseSystemVersion(bytes)) |ver| {
60 // never return non-canonical `10.(16+)`60 // never return non-canonical `10.(16+)`
61 if (!(ver.major == 10 and ver.minor >= 16)) {61 if (!(ver.major == 10 and ver.minor >= 16)) {