Skip to content

Commit ad360e1

Browse files
committed
Apple Silicon: no fstat$INODE64 symbol found
It seems that Apple has finally got rid of the 32bit versions of `fstat` and `fstatat`, and instead, only 64bit versions are available on BigSur and Apple Silicon. The tweak in this commit is required to make Zig stage1 compile on BigSur + aarch64.
1 parent 59af275 commit ad360e1

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/std/c.zig

+16-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,14 @@ pub extern "c" fn readlinkat(dirfd: fd_t, noalias path: [*:0]const u8, noalias b
124124
pub usingnamespace switch (builtin.os.tag) {
125125
.macos, .ios, .watchos, .tvos => struct {
126126
pub const realpath = @"realpath$DARWIN_EXTSN";
127-
pub const fstatat = @"fstatat$INODE64";
127+
pub usingnamespace switch (builtin.arch) {
128+
.aarch64 => struct {
129+
pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;
130+
},
131+
else => struct {
132+
pub const fstatat = @"fstatat$INODE64";
133+
},
134+
};
128135
},
129136
else => struct {
130137
pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
@@ -194,7 +201,14 @@ pub usingnamespace switch (builtin.os.tag) {
194201
// XXX: getdirentries -> _getdirentries64
195202
pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
196203
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
197-
pub const fstat = @"fstat$INODE64";
204+
pub usingnamespace switch (builtin.arch) {
205+
.aarch64 => struct {
206+
pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
207+
},
208+
else => struct {
209+
pub const fstat = @"fstat$INODE64";
210+
}
211+
};
198212
pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
199213
pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
200214
pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;

0 commit comments

Comments
 (0)