-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Apple: Always pass SDK root when linking with cc
, and pass it via SDKROOT
env var
#131477
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
Open
madsmtm
wants to merge
4
commits into
rust-lang:master
Choose a base branch
from
madsmtm:sdkroot-via-env-var
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+115
−54
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/doc/unstable-book/src/compiler-environment-variables/SDKROOT.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# `SDKROOT` | ||
|
||
This environment variable is used on Apple targets. | ||
It is passed through to the linker (currently either as `-isysroot` or `-syslibroot`). | ||
It is passed through to the linker (currently either directly or via the `-syslibroot` flag). | ||
|
||
Note that this variable is not always respected. When the SDKROOT is clearly wrong (e.g. when the platform of the SDK does not match the `--target` used by rustc), this is ignored and rustc does its own detection. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//! Test that linking works under an environment similar to what Xcode sets up. | ||
//! | ||
//! Regression test for https://github.com/rust-lang/rust/issues/80817. | ||
|
||
//@ only-apple | ||
|
||
use run_make_support::{cmd, rustc, target}; | ||
|
||
fn main() { | ||
// Fetch toolchain `/usr/bin` directory. Usually: | ||
// /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin | ||
let clang_bin = cmd("xcrun").arg("--find").arg("clang").run().stdout_utf8(); | ||
let toolchain_bin = clang_bin.trim().strip_suffix("/clang").unwrap(); | ||
|
||
// Put toolchain directory at the front of PATH. | ||
let path = format!("{}:{}", toolchain_bin, std::env::var("PATH").unwrap()); | ||
|
||
// Check that compiling and linking still works. | ||
// | ||
// Removing `SDKROOT` is necessary for the test to excercise what we want, since bootstrap runs | ||
// under `/usr/bin/python3`, which will set SDKROOT for us. | ||
rustc().target(target()).env_remove("SDKROOT").env("PATH", &path).input("foo.rs").run(); | ||
|
||
// Also check linking directly with the system linker. | ||
rustc() | ||
.target(target()) | ||
.env_remove("SDKROOT") | ||
.env("PATH", &path) | ||
.input("foo.rs") | ||
.arg("-Clinker-flavor=ld") | ||
.run(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.