forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always attempt to get SDK root, and pass it to Clang via env var
The exact reasoning why we do not always pass the SDK root with `-isysroot` to `cc` when linking on macOS eludes me (the git history dead ends in rust-lang#100286), but I suspect it's because we want to support `cc`s which do not support this option. So instead, we pass the SDK root via the environment variable SDKROOT. This way, compiler drivers that support setting the SDK root (such as Clang and GCC) can use it, while compiler drivers that don't (presumably because they figure out the SDK root in some other way) can just ignore it. This fixes rust-lang#80817 (by always passing the SDK root, even when linking with cc on macOS).
- Loading branch information
Showing
4 changed files
with
69 additions
and
48 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,26 @@ | ||
//! 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 cc_bin = cmd("xcrun").arg("--find").arg("cc").run().stdout_utf8(); | ||
let toolchain_bin = cc_bin.trim().strip_suffix("/cc").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 with ld64. | ||
rustc().target(target()).env_remove("SDKROOT").env("PATH", &path).arg("-Clinker-flavor=ld").input("foo.rs").run(); | ||
} |