Skip to content
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

crosscompiling macos -> ios + xcodebuild + build-script problem #530

Closed
Dushistov opened this issue Jul 8, 2020 · 5 comments · Fixed by #537
Closed

crosscompiling macos -> ios + xcodebuild + build-script problem #530

Dushistov opened this issue Jul 8, 2020 · 5 comments · Fixed by #537

Comments

@Dushistov
Copy link
Contributor

Dushistov commented Jul 8, 2020

I call cargo build from my XCode project and build project for iOS.
One of my crates depend on bindgen, which depend on clang-sys,
which depend on libloading.

And build failed, with such error:

cargo:warning=In file included from src/os/unix/global_static.c:1:
cargo:warning=In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/pthread.h:60:
cargo:warning=In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/time.h:69:
cargo:warning=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types/_clock_t.h:31:9: error: unknown type name '__darwin_clock_t'
cargo:warning=typedef __darwin_clock_t clock_t;

libloading is part of build-script, so it should not be compiled for iOS,
it should be compiled for macOS, but for some reason it compiled for iOS instead of macOS.

Interesting thing that if I run cargo build --target=aarch64-apple-ios manually all works fine.

After analysing what environment variable set xcodebuild I thing culprit is

SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk

because of with it

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-o" "/tmp/global_static.o" "-c" /Users/evgeniy/.cargo/registry/src/github.com-1ecc6299db9ec823/libloading-0.5.2/src/os/unix/global_static.c

report the same problem, and if I change it into

export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

all works fine if I call cc manually.

@alexcrichton
Copy link
Member

Yes this is where build processes using env vars aren't really always the best equipped for cross compilation. I'm not really sure what this crate could do, since it can't blindly remove SDKROOT from the environment...

@Dushistov
Copy link
Contributor Author

Dushistov commented Jul 8, 2020

I suppose it should detect target == host == macos and then if SDKROOT contains ios
set SDKROOT=macos , but I am not sure how to find proper content of SDKROOT for macos.

@alexcrichton
Copy link
Member

Now that you mention it I recall that rustc does something similar, and that seems reasonable to add here too

@MichaelHills
Copy link

Is this the same as rust-lang/cargo#7283 ?

@Dushistov
Copy link
Contributor Author

@MichaelHills

It is roughly the same. Problem with include search, not linking problem. In solution I set environment variable to right value, instead of removing variable etc. But it is roughly the same problem: problem of building build script if the whole build is run via xcodebuild

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants