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

filter SDKROOT for macos->macos build #537

Merged
merged 1 commit into from
Aug 6, 2020

Conversation

Dushistov
Copy link
Contributor

fixes #530

The code mainly based on rustc source code,
but instead of removing it replace SDKROOT env variable,
because of it is important to find libc headers, like pthread.h

@alexcrichton
Copy link
Member

Thanks for the PR! I would prefer to avoid modifying the environment of the calling process if possible, only updating the environment of spawned processes. Additionally this seems not super great to hardcode a path into this crate which may not be the same for all users? Would it be possible to somehow infer that? Are you sure that if the env var isn't set it won't work?

@Dushistov Dushistov force-pushed the fix-iphone-os-build branch from ffa88dd to 4f578aa Compare August 5, 2020 11:22
@Dushistov
Copy link
Contributor Author

Dushistov commented Aug 5, 2020

I would prefer to avoid modifying the environment of the calling process if possible, only updating the environment of spawned processes.

Done

Additionally this seems not super great to hardcode a path into this crate which may not be the same for all users? Would it be possible to somehow infer that?

Done

Are you sure that if the env var isn't set it won't work?

Yes, I used such script to find out what is really problem in #530:

export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:$PATH
#export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
unset SDKROOT


cd /usr/local/var/cache//registry/src/github.com-1ecc6299db9ec823/libloading-0.5.2
"cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-arch" "x86_64" "-Wall" "-Wextra" "-o" "/tmp/global_static.o" "-c" "src/os/unix/global_static.c"

Initially I inserted all environment variables into it and then binary search the problem env. variables.
As result only two environment variables matter: PATH and SDKROOT.
If I run this script it fails and prints pthread.h not found,
if I comment unset SDKROOT and uncomment SDKROOT all works fine.

So cc in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin works only with setted SDKROOT, /usr/bin/cc works just fine without SDKROOT,
but I run all build under xcodebuild and it changes default cc and set SDKROOT unfortunately.

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated
if host.contains("apple-darwin") && target.contains("apple-darwin") {
// Replace the `SDKROOT` environment variable if it's clearly set for the wrong platform, which
// may occur when we're linking a custom build script while targeting iOS for example.
// Removing is not enough, because of cc from XCode can not find include files in such case
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this comment be clarified? The point of "removing is not enough" is only applicable when we're running clang directly out of the sysroot I suspect. Executing /usr/bin/clang doesn't require SDKROOT to be set, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

src/lib.rs Outdated Show resolved Hide resolved
@Dushistov Dushistov force-pushed the fix-iphone-os-build branch from 4f578aa to f56b08e Compare August 6, 2020 10:35
@alexcrichton alexcrichton merged commit a970b0a into rust-lang:master Aug 6, 2020
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 this pull request may close these issues.

crosscompiling macos -> ios + xcodebuild + build-script problem
2 participants