Commit bda9a159aa

Jakub Konka <kubkon@jakubkonka.com>
2020-10-27 21:47:34
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 e1ca694
Changed files (1)
lib
std
lib/std/c.zig
@@ -124,7 +124,14 @@ pub extern "c" fn readlinkat(dirfd: fd_t, noalias path: [*:0]const u8, noalias b
 pub usingnamespace switch (builtin.os.tag) {
     .macos, .ios, .watchos, .tvos => struct {
         pub const realpath = @"realpath$DARWIN_EXTSN";
-        pub const fstatat = @"fstatat$INODE64";
+        pub usingnamespace switch (builtin.arch) {
+            .aarch64 => struct {
+                pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;
+            },
+            else => struct {
+                pub const fstatat = @"fstatat$INODE64";
+            },
+        };
     },
     else => struct {
         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) {
         // XXX: getdirentries -> _getdirentries64
         pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
         pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
-        pub const fstat = @"fstat$INODE64";
+        pub usingnamespace switch (builtin.arch) {
+            .aarch64 => struct {
+                pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
+            },
+            else => struct {
+                pub const fstat = @"fstat$INODE64";
+            }
+        };
         pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
         pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
         pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;