-
Notifications
You must be signed in to change notification settings - Fork 44
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
Linker errors when building with --xcode-integ on Big Sur #41
Comments
@irh I was drafting an issue at exactly the same time 😄 Good to know I'm not alone on this. I still don't have a good solution for this but I'll share what I tried: First, looking at the linker (
This was my first "bingo!". They removed the standard libs from As a workaround, I tried copying the missing library symlinks in
This works on the simulator only (probably because I'm using the I hope this helps and if you find out something else please report here! Also I really hope @TimNN can take a look, he'll probably will understand the issue much better than I. UPDATE: I just tried this hack again using a real iphone and it worked. They only thing that changed wrt the last time I tried is that I upgraded my command line tools yesterday. |
@v-almonacid: Thanks for the vote of confidence, but I haven’t touched or used this code in years. I‘d be happy to review any patches related to this, but probably won’t spend any time investigating this in the near future. (I‘ll see about updating the readme to make the maintenance status of the project clear). |
@v-almonacid Thanks for the pointers. I haven't fully cracked this yet but I made some progress. Rather than trying to force the use of
While poking at this I found that building directly with
before the call to @TimNN Thanks for clarifying, I'm not at the point of making a PR but it's good to know that it would be accepted. |
We had the exact same issue, but we found out that there are two "linkers":
both report the same version AND the same "InstalledDir" since /usr/bin/clang in the end probably executes the one in the xcode.app bundle (it is not a symlink though):
Linking with /usr/bin/clang works, so we hardcoded the linker in the cargo config file as following: [target.aarch64-apple-ios]
linker="/usr/bin/clang"
[target.x86_64-apple-darwin]
linker="/usr/bin/clang We were not explicitly using cargo lipo, but I found this issue and thought I dump our experience as well :) |
I stumbled across a neat workaround for this here: if [[ -n "${DEVELOPER_SDK_DIR:-}" ]]; then
# Assume we're in Xcode, which means we're probably cross-compiling.
# In this case, we need to add an extra library search path for build scripts and proc-macros,
# which run on the host instead of the target.
# (macOS Big Sur does not have linkable libraries in /usr/lib/.)
export LIBRARY_PATH="${DEVELOPER_SDK_DIR}/MacOSX.sdk/usr/lib:${LIBRARY_PATH:-}"
fi This worked great for me on my machine and is a simpler solution than some of the other options presented in this thread. |
…me $0` && pwd)/leaf FILENAME="libleaf.a" # See TimNN/cargo-lipo#41 (comment) if [[ -n "${DEVELOPER_SDK_DIR:-}" ]]; then # Assume we're in Xcode, which means we're probably cross-compiling. # In this case, we need to add an extra library search path for build scripts and proc-macros, # which run on the host instead of the target. # (macOS Big Sur does not have linkable libraries in /usr/lib/.) export LIBRARY_PATH="${DEVELOPER_SDK_DIR}/MacOSX.sdk/usr/lib:${LIBRARY_PATH:-}" # The $PATH used by Xcode likely won't contain Cargo, fix that. # This assumes a default `rustup` setup. export PATH="${HOME}/.cargo/bin:{$PATH}" # Delete old build, if any. rm -f "${BUILT_PRODUCTS_DIR}/${FILENAME}" # --xcode-integ determines --release and --targets from Xcode's env vars. # Depending your setup, specify the rustup toolchain explicitly. cargo lipo --xcode-integ --manifest-path "${DIR}/Cargo.toml" -p leaf-ffi # cargo-lipo drops result in different folder, depending on the config. if [[ $CONFIGURATION = "Debug" ]]; then SOURCE="$DIR/target/universal/debug/${FILENAME}" else SOURCE="$DIR/target/universal/release/${FILENAME}" fi # Copy compiled library to BUILT_PRODUCTS_DIR. Use that in your Xcode project # settings under General -> Frameworks and Libraries. # You will also need to have tun2tor.h somewhere in your search paths! # (Easiest way: have it referenced in your project files list.) if [ -e "${SOURCE}" ]; then cp -a "${SOURCE}" "${BUILT_PRODUCTS_DIR}" fi else # Direct command line usage. cargo lipo --manifest-path $DIR/Cargo.toml -p leaf-ffi fi cbindgen --config "${DIR}/leaf-ffi/cbindgen.toml" "${DIR}/leaf-ffi/src/lib.rs" > leaf.h #!/usr/bin/env sh # Get absolute path to this script. DIR=$(cd `dirname $0` && pwd)/leaf FILENAME="libleaf.a" # See TimNN/cargo-lipo#41 (comment) if [[ -n "${DEVELOPER_SDK_DIR:-}" ]]; then # Assume we're in Xcode, which means we're probably cross-compiling. # In this case, we need to add an extra library search path for build scripts and proc-macros, # which run on the host instead of the target. # (macOS Big Sur does not have linkable libraries in /usr/lib/.) export LIBRARY_PATH="${DEVELOPER_SDK_DIR}/MacOSX.sdk/usr/lib:${LIBRARY_PATH:-}" # The $PATH used by Xcode likely won't contain Cargo, fix that. # This assumes a default `rustup` setup. export PATH="${HOME}/.cargo/bin:{$PATH}" # Delete old build, if any. rm -f "${BUILT_PRODUCTS_DIR}/${FILENAME}" # --xcode-integ determines --release and --targets from Xcode's env vars. # Depending your setup, specify the rustup toolchain explicitly. cargo lipo --xcode-integ --manifest-path "${DIR}/Cargo.toml" -p leaf-ffi # cargo-lipo drops result in different folder, depending on the config. if [[ $CONFIGURATION = "Debug" ]]; then SOURCE="$DIR/target/universal/debug/${FILENAME}" else SOURCE="$DIR/target/universal/release/${FILENAME}" fi # Copy compiled library to BUILT_PRODUCTS_DIR. Use that in your Xcode project # settings under General -> Frameworks and Libraries. # You will also need to have tun2tor.h somewhere in your search paths! # (Easiest way: have it referenced in your project files list.) if [ -e "${SOURCE}" ]; then cp -a "${SOURCE}" "${BUILT_PRODUCTS_DIR}" fi else # Direct command line usage. cargo lipo --manifest-path $DIR/Cargo.toml -p leaf-ffi fi cbindgen --config "${DIR}/leaf-ffi/cbindgen.toml" "${DIR}/leaf-ffi/src/lib.rs" > leaf.h
I'm running into build errors on Big Sur when using cargo-lipo in an Xcode build script.
I've made a small test project here.
It builds successfully in Xcode 12.2 on Catalina 10.15.7, but fails with Big Sur 11.0.1.
The errors are along the lines of
Building the project on the command line with
cargo lipo
without--xcode-integ
works correctly.Big Sur has introduced a dynamic library cache, so libSystem.dylib isn't in
/usr/lib
as it is on Catalina, I assume that's got something to do with it but I haven't had any luck finding a solution so far.Any ideas? Thanks for cargo-lipo 👍
The text was updated successfully, but these errors were encountered: