-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zig cc -target aarch64-macos-gnu ...
with cgo fails with expansion-to-defined
and availability
errors that do not occur without -target ...
#10790
Comments
Thanks for filing this! Did you perhaps try building your project with Zig from the master branch to see if it fixes your issue? Please note that passing the sysroot to the linker is fixed in master meaning you shouldn't explicitly append the sysroot prefix to search dirs like you did in your build script above. |
Oh and also, what version of macOS are you on? |
Just tried with
With
macOS 12.2 (21D49) One other thing that might be interesting / relevant: this doesn't seem limited to just |
Hmm, it should be enough to specify the sysroot and then the search dirs without the sysroot prefix like so:
Can you confirm this is still generating the linker error for you?
|
This is the command line that is being invoked and the error it produces (removing the
|
Hmm, thanks. Let me run some checks locally. I am somewhat confused as this was recently fixed in master (not passing the sysroot from |
OK, I tried reproing it locally on my M1 and both native and cross scripts succeed for me. Here's what I did:
diff --git a/helpers/cc.sh b/helpers/cc.sh
index 3e41591..eb17e86 100755
--- a/helpers/cc.sh
+++ b/helpers/cc.sh
@@ -9,11 +9,11 @@ export ZIG_LOCAL_CACHE_DIR="$PROJECT_ROOT/.zigcache/"
set -x
if [[ -z "${ZTARGET+x}" ]]; then
- zig cc "$@"
+ /Users/kubkon/Downloads/zig/zig cc "$@"
else
SYSROOT="$(xcrun --show-sdk-path)"
# The -I, -F and -L flags are required to configure the sysroot correctly - see https://github.com/ziglang/zig/issues/10513#issuecomment-1005652047.
- zig cc -target "$ZTARGET" --sysroot "$SYSROOT" "-I$SYSROOT/usr/include" "-F$SYSROOT/System/Library/Frameworks" "-L$SYSROOT/usr/lib" "$@"
+ /Users/kubkon/Downloads/zig/zig cc -target "$ZTARGET" --sysroot="$SYSROOT" "-I/usr/include" "-F/System/Library/Frameworks" "-L/usr/lib" "$@"
fi
set +x
diff --git a/helpers/cxx.sh b/helpers/cxx.sh
index 8a31b30..42d2e53 100755
--- a/helpers/cxx.sh
+++ b/helpers/cxx.sh
@@ -9,11 +9,11 @@ export ZIG_LOCAL_CACHE_DIR="$PROJECT_ROOT/.zigcache/"
set -x
if [[ -z "${ZTARGET+x}" ]]; then
- zig c++ "$@"
+ /Users/kubkon/Downloads/zig/zig c++ "$@"
else
SYSROOT="$(xcrun --show-sdk-path)"
# The -I, -F and -L flags are required to configure the sysroot correctly - see https://github.com/ziglang/zig/issues/10513#issuecomment-1005652047.
- zig c++ -target "$ZTARGET" --sysroot "$SYSROOT" "-I$SYSROOT/usr/include" "-F$SYSROOT/System/Library/Frameworks" "-L$SYSROOT/usr/lib" "$@"
+ /Users/kubkon/Downloads/zig/zig c++ -target "$ZTARGET" --sysroot="$SYSROOT" "-I/usr/include" "-F/System/Library/Frameworks" "-L/usr/lib" "$@"
fi
set +x Also note that in the presence of sysroot, the search directories for system libraries and frameworks should not include the sysroot prefix as it will be automatically prepended to them by the linker. This behaviour is similar to how Apple's Therefore, I will close the issue but feel free to reopen if you still get errors. |
Not sure what I did wrong the first time round, but this is working for me now with the latest version of Zig. Thanks for your help @kubkon! |
No probs at all and happy to help! |
Zig Version
0.9.0
Steps to Reproduce
(This issue is split from #10513 (comment).)
I've created a sample project (https://github.com/charleskorn/zig-cgo-libs) that illustrates the problem.
Run
./build-native.sh shared
to run the build without cross-compilation.zig cc
will be invoked without-target
by thecc.sh
wrapper script.Run
./build-cross.sh shared darwin arm64
to build with cross-compilation enabled.zig cc
will be invoked with-target aarch64-macos-gnu --sysroot "$SYSROOT" "-I$SYSROOT/usr/include" "-F$SYSROOT/System/Library/Frameworks" "-L$SYSROOT/usr/lib"
.Expected Behavior
Both invocations behave the same when running on my M1 Mac - ie. both produce the same warnings and errors, and both succeed or both fail.
Actual Behavior
The native build (ie. without
-target ...
) succeeds without error:Logs
The cross-compiled build (ie. with
-target ...
) fails with a number of errors:Logs
Adding
-Wno-availability -Wno-expansion-to-defined
to thezig cc -target ...
command line results in a build that succeeds, however a number ofnullability-completeness
warnings are generated:Logs
Adding
-Wno-nullability-completeness
to thezig cc -target ...
invocation suppresses these warnings.The text was updated successfully, but these errors were encountered: