zig
zig copied to clipboard
`zig libc` panics on macOS
Zig Version
0.10.0-dev.4870+be5130ec5
Steps to Reproduce
Run zig libc
Expected Behavior
Don't panic, maybe print a non-zero exit code
Actual Behavior

thread 28145757 panic: Darwin is handled separately via std.zig.system.darwin module
Unable to dump stack trace: debug info stripped
fish: Job 1, 'zig libc' terminated by signal SIGABRT (Abort)
Were you running a beta release on macOS by chance?
Were you running a beta release on macOS by chance?
I was when this was happening to me (but it turned out zig just didn’t support Ventura)
Yep, this is because Zig doesn't include a copy of libSystem.tbd for that macOS version.
In order to use Zig on Ventura, #12080 is required as well as the following diff:
diff --git a/src/Compilation.zig b/src/Compilation.zig
index b00f13581..4e21245f4 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -4474,7 +4474,7 @@ fn detectLibCIncludeDirs(
// If linking system libraries and targeting the native abi, default to
// using the system libc installation.
- if (link_system_libs and is_native_abi and !target.isMinGW()) {
+ if ((link_system_libs or target.isDarwin()) and is_native_abi and !target.isMinGW()) {
if (target.isDarwin()) {
return if (has_macos_sdk)
// For Darwin/macOS, we are all set with getDarwinSDK found earlier.
I started seeing this issue after upgrading my computer to MacOSX 13.0 (Ventura)
Can you try the macos-13 branch?
@jedisct1 I tried to build macos-13 branch using instructions from https://github.com/ziglang/zig/wiki/Building-Zig-From-Source and stage3 fails for me with
[ 93%] Building CXX object CMakeFiles/zigstage1.dir/src/stage1/range_set.cpp.o
[ 94%] Building CXX object CMakeFiles/zigstage1.dir/src/stage1/softfloat_ext.cpp.o
[ 94%] Building CXX object CMakeFiles/zigstage1.dir/src/stage1/stage1.cpp.o
[ 95%] Building CXX object CMakeFiles/zigstage1.dir/src/stage1/target.cpp.o
[ 95%] Building CXX object CMakeFiles/zigstage1.dir/src/stage1/tokenizer.cpp.o
[ 96%] Building CXX object CMakeFiles/zigstage1.dir/src/stage1/util.cpp.o
[ 97%] Linking CXX static library zigcpp/libzigstage1.a
[ 97%] Built target zigstage1
[ 98%] Building CXX object CMakeFiles/zig1.dir/src/stage1/zig0.cpp.o
[ 98%] Linking CXX executable zig1
[ 98%] Built target zig1
[ 99%] Building stage2 object /Users/apomazau/sources/zig/build/zig2.o
[ 99%] Building CXX object CMakeFiles/zig2.dir/src/stage1/empty.cpp.o
[100%] Linking CXX executable zig2
[100%] Built target zig2
[100%] Building stage3
error(compilation): clang failed with stderr: In file included from /Users/apomazau/sources/zig/deps/SoftFloat-3e/source/s_tryPropagateNaNF128M.c:38:
In file included from /Users/apomazau/sources/zig/lib/include/stdint.h:52:
In file included from /Users/apomazau/sources/zig/lib/libc/include/any-macos-any/stdint.h:52:
/Users/apomazau/sources/zig/lib/libc/include/any-macos-any/sys/_types.h:32:10: fatal error: 'sys/cdefs.h' file not found
error(compilation): clang failed with stderr: In file included from /Users/apomazau/sources/zig/deps/SoftFloat-3e/source/softfloat_state.c:37:
In file included from /Users/apomazau/sources/zig/lib/include/stdint.h:52:
In file included from /Users/apomazau/sources/zig/lib/libc/include/any-macos-any/stdint.h:52:
/Users/apomazau/sources/zig/lib/libc/include/any-macos-any/sys/_types.h:32:10: fatal error: 'sys/cdefs.h' file not found
error(compilation): clang failed with stderr: In file included from /Users/apomazau/sources/zig/deps/SoftFloat-3e/source/f64_to_f16.c:38:
In file included from /Users/apomazau/sources/zig/lib/include/stdint.h:52:
In file included from /Users/apomazau/sources/zig/lib/libc/include/any-macos-any/stdint.h:52:
/Users/apomazau/sources/zig/lib/libc/include/any-macos-any/sys/_types.h:32:10: fatal error: 'sys/cdefs.h' file not found
error(compilation): clang failed with stderr: In file included from /Users/apomazau/sources/zig/deps/SoftFloat-3e/source/s_addExtF80M.c:38:
In file included from /Users/apomazau/sources/zig/lib/include/stdint.h:52:
In file included from /Users/apomazau/sources/zig/lib/libc/include/any-macos-any/stdint.h:52:
/Users/apomazau/sources/zig/lib/libc/include/any-macos-any/sys/_types.h:32:10: fatal error: 'sys/cdefs.h' file not found
error(compilation): clang failed with stderr: In file included from /Users/apomazau/sources/zig/deps/SoftFloat-3e/source/i32_to_f128M.c:37:
In file included from /Users/apomazau/sources/zig/lib/include/stdint.h:52:
In file included from /Users/apomazau/sources/zig/lib/libc/include/any-macos-any/stdint.h:52:
/Users/apomazau/sources/zig/lib/libc/include/any-macos-any/sys/_types.h:32:10: fatal error: 'sys/cdefs.h' file not found
error(compilation): clang failed with stderr: In file included from /Users/apomazau/sources/zig/deps/SoftFloat-3e/source/ui32_to_f128M.c:37:
In file included from /Users/apomazau/sources/zig/lib/include/stdint.h:52:
In file included from /Users/apomazau/sources/zig/lib/libc/include/any-macos-any/stdint.h:52:
/Users/apomazau/sources/zig/lib/libc/include/any-macos-any/sys/_types.h:32:10: fatal error: 'sys/cdefs.h' file not found
error(compilation): clang failed with stderr: In file included from /Users/apomazau/sources/zig/deps/SoftFloat-3e/source/s_addF128M.c:38:
In file included from /Users/apomazau/sources/zig/lib/include/stdint.h:52:
In file included from /Users/apomazau/sources/zig/lib/libc/include/any-macos-any/stdint.h:52:
/Users/apomazau/sources/zig/lib/libc/include/any-macos-any/sys/_types.h:32:10: fatal error: 'sys/cdefs.h' file not found
https://github.com/ziglang/zig/blob/macos-13/lib/libc/include/aarch64-macos.13-none/sys/cdefs.h exists https://github.com/ziglang/zig/blob/macos-13/lib/libc/include/x86_64-macos.13-none/sys/cdefs.h does not
Can you git pull and try again?
Also, Jakub has a PR for it: https://github.com/ziglang/zig/pull/13299
Now macos-13 branch compiles and runs without any errors.
Ventura support landed in d42a719e8f7ba31a9e18d6be9d58691b0b38c69a
Is there any chance to have this fix in a 0.9.2 to be able to run it on Ventura?
Sorry, 0.9.2 is not planned.
Then Homebrew formula needs to be patched explicitly. cc @carlocab
@kubkon could you please specify a minimum list of patches on top of 0.9.1 required for Ventura support?
Instead of patching Zig I suggest to start passing -target native-macos.11 in your project. This will produce binaries that run on Big Sur, Monterey, and Ventura.
Alternately you can upgrade to Zig 0.10.0 which is to be released 4 days from now.
Yes, waiting for the release of 0.10.0 sounds like a much better idea. Thanks!
brew install zig is x86 running under Rosetta:
file /usr/local/Cellar/zig/0.10.0/bin/zig
/usr/local/Cellar/zig/0.10.0/bin/zig: Mach-O 64-bit executable x86_64
That's because you've installed Homebrew into /usr/local. Everything Homebrew installs in that prefix is built for x64 and runs in Rosetta on M1 macOS.
Ah yes I remember dealing with this earlier. I was recently messing around with my .zshrc file and I must have preferenced the /usr/local over /opt/homebrew somehow.
FYI I'm seeing this panic on Zig 0.10.0, downloaded with homebrew:
~ % zig version
0.10.0
~ % zig libc
thread 697244 panic: Darwin is handled separately via std.zig.system.darwin module
Unable to dump stack trace: debug info stripped
zsh: abort zig libc
(on macOS Ventura 13.0.1, Macbook Air M1 2020)
@akgvn What does which zig show?
@vjpr
~ % which zig
/opt/homebrew/bin/zig
~ % file /opt/homebrew/bin/zig
/opt/homebrew/bin/zig: Mach-O 64-bit executable arm64
``
@akgvn, what's the output of
brew config
brew doctor
brew info zig
cat "$(brew --prefix zig)/INSTALL_RECEIPT.json" | grep -E '(tap_git_head|os_version)'
?
@carlocab Ran all those in order:
~ % brew config
HOMEBREW_VERSION: 3.6.16-2-gf679990
ORIGIN: https://github.com/Homebrew/brew
HEAD: f679990d7918d9f99d9c6c99b7bec504bc4088fe
Last commit: 2 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 8f1d26349bf051432c341946d2d8e33dfcf9770e
Core tap last commit: 27 hours ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 14.0.0 build 1400
Git: 2.37.1 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.84.0 => /usr/bin/curl
macOS: 13.0.1-arm64
CLT: 14.2.0.0.1.1668646533
Xcode: N/A
Rosetta 2: false
~ % brew doctor
Your system is ready to brew.
~ % brew info zig
==> zig: stable 0.10.0 (bottled), HEAD
Programming language designed for robustness, optimality, and clarity
https://ziglang.org/
/opt/homebrew/Cellar/zig/0.10.0 (13,837 files, 362.1MB) *
Poured from bottle on 2022-12-21 at 21:24:03
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/zig.rb
License: MIT
==> Dependencies
Build: cmake ✘, llvm ✔
Required: z3 ✔, zstd ✔
==> Requirements
Required: macOS >= 11 ✔
==> Options
--HEAD
Install HEAD version
==> Analytics
install: 2,620 (30 days), 10,601 (90 days), 26,848 (365 days)
install-on-request: 2,393 (30 days), 9,717 (90 days), 24,535 (365 days)
build-error: 119 (30 days)
~ % cat "$(brew --prefix zig)/INSTALL_RECEIPT.json" | grep -E '(tap_git_head|os_version)'
"tap_git_head": "fbda5f2fc575872ae3cba9e7e252b621fe1dce11",
"os_version": "macOS 13",
Yea, this seems to be a problem with Zig. I can reproduce this using the latest build from master at https://ziglang.org/builds/zig-macos-aarch64-0.11.0-dev.937+c9e3524d0.tar.xz.
❯ curl -fsSL https://ziglang.org/builds/zig-macos-aarch64-0.11.0-dev.937+c9e3524d0.tar.xz | tar -x
❯ ./zig-macos-aarch64-0.11.0-dev.937+c9e3524d0/zig libc
thread 9838929 panic: Darwin is handled separately via std.zig.system.darwin module
Unable to dump stack trace: debug info stripped
[1] 73171 abort ./zig-macos-aarch64-0.11.0-dev.937+c9e3524d0/zig libc
I suggest opening a new issue (if there isn't already a related one open).
I'm seeing similar error on macOS 11.7.8 (20G1351)
$ zig libc
thread 5715000 panic: Darwin is handled separately via std.zig.system.darwin module
Unable to dump stack trace: debug info stripped
Abort trap: 6
$ uname -a
Darwin hostname.local 20.6.0 Darwin Kernel Version 20.6.0: Thu Jun 8 22:36:09 PDT 2023; root:xnu-7195.141.49.701.4~1/RELEASE_X86_64 x86_64
$ zig version
0.10.1
$ brew info zig
==> zig: stable 0.10.1 (bottled)
Programming language designed for robustness, optimality, and clarity
https://ziglang.org/
/usr/local/Cellar/zig/0.10.1 (13,841 files, 385.3MB) *
Poured from bottle using the formulae.brew.sh API on 2023-01-30 at 08:42:31
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/z/zig.rb
License: MIT
==> Dependencies
Build: cmake ✔, llvm@15 ✘
Required: zstd ✔
==> Requirements
Required: macOS >= 11 (or Linux) ✔
==> Analytics
install: 1,940 (30 days), 3,787 (90 days), 6,644 (365 days)
install-on-request: 1,497 (30 days), 3,005 (90 days), 5,406 (365 days)
build-error: 18 (30 days)
$ cat /usr/local/opt/zig/INSTALL_RECEIPT.json | grep --extended-regexp '(tap_git_head|os_version)'
"tap_git_head": "a02abf8819cbb0fbdf50701e17cfb7d56730dbac",
"os_version": "macOS 11.7",
Is there something obvious I'm missing?
I'm seeing similar error on
macOS 11.7.8 (20G1351)$ zig libc thread 5715000 panic: Darwin is handled separately via std.zig.system.darwin module Unable to dump stack trace: debug info stripped Abort trap: 6 $ uname -a Darwin hostname.local 20.6.0 Darwin Kernel Version 20.6.0: Thu Jun 8 22:36:09 PDT 2023; root:xnu-7195.141.49.701.4~1/RELEASE_X86_64 x86_64 $ zig version 0.10.1 $ brew info zig ==> zig: stable 0.10.1 (bottled) Programming language designed for robustness, optimality, and clarity https://ziglang.org/ /usr/local/Cellar/zig/0.10.1 (13,841 files, 385.3MB) * Poured from bottle using the formulae.brew.sh API on 2023-01-30 at 08:42:31 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/z/zig.rb License: MIT ==> Dependencies Build: cmake ✔, llvm@15 ✘ Required: zstd ✔ ==> Requirements Required: macOS >= 11 (or Linux) ✔ ==> Analytics install: 1,940 (30 days), 3,787 (90 days), 6,644 (365 days) install-on-request: 1,497 (30 days), 3,005 (90 days), 5,406 (365 days) build-error: 18 (30 days) $ cat /usr/local/opt/zig/INSTALL_RECEIPT.json | grep --extended-regexp '(tap_git_head|os_version)' "tap_git_head": "a02abf8819cbb0fbdf50701e17cfb7d56730dbac", "os_version": "macOS 11.7",Is there something obvious I'm missing?
It's been fixed in Zig 0.11.
Okay nice. I thought it was fixed in 0.10.0 since this issue has 0.10.0 in its milestone, and my system is somewhat different from other users seeing this error. So I think it could be something new and unrelated to aarch64 macOS.