Always set the deployment target when building std
This commit is contained in:
parent
e790b92d72
commit
9318fbb33a
2 changed files with 57 additions and 3 deletions
|
@ -443,8 +443,41 @@ fn compiler_rt_for_profiler(builder: &Builder<'_>) -> PathBuf {
|
||||||
/// Configure cargo to compile the standard library, adding appropriate env vars
|
/// Configure cargo to compile the standard library, adding appropriate env vars
|
||||||
/// and such.
|
/// and such.
|
||||||
pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, cargo: &mut Cargo) {
|
pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, cargo: &mut Cargo) {
|
||||||
if let Some(target) = env::var_os("MACOSX_STD_DEPLOYMENT_TARGET") {
|
// rustc already ensures that it builds with the minimum deployment
|
||||||
cargo.env("MACOSX_DEPLOYMENT_TARGET", target);
|
// target, so ideally we shouldn't need to do anything here.
|
||||||
|
//
|
||||||
|
// However, `cc` currently defaults to a higher version for backwards
|
||||||
|
// compatibility, which means that compiler-rt, which is built via
|
||||||
|
// compiler-builtins' build script, gets built with a higher deployment
|
||||||
|
// target. This in turn causes warnings while linking, and is generally
|
||||||
|
// a compatibility hazard.
|
||||||
|
//
|
||||||
|
// So, at least until https://github.com/rust-lang/cc-rs/issues/1171, or
|
||||||
|
// perhaps https://github.com/rust-lang/cargo/issues/13115 is resolved, we
|
||||||
|
// explicitly set the deployment target environment variables to avoid
|
||||||
|
// this issue.
|
||||||
|
//
|
||||||
|
// This place also serves as an extension point if we ever wanted to raise
|
||||||
|
// rustc's default deployment target while keeping the prebuilt `std` at
|
||||||
|
// a lower version, so it's kinda nice to have in any case.
|
||||||
|
if target.contains("apple") && !builder.config.dry_run() {
|
||||||
|
// Query rustc for the deployment target, and the associated env var.
|
||||||
|
// The env var is one of the standard `*_DEPLOYMENT_TARGET` vars, i.e.
|
||||||
|
// `MACOSX_DEPLOYMENT_TARGET`, `IPHONEOS_DEPLOYMENT_TARGET`, etc.
|
||||||
|
let mut cmd = command(builder.rustc(cargo.compiler()));
|
||||||
|
cmd.arg("--target").arg(target.rustc_target_arg());
|
||||||
|
cmd.arg("--print=deployment-target");
|
||||||
|
let output = cmd.run_capture_stdout(builder).stdout();
|
||||||
|
|
||||||
|
let (env_var, value) = output.split_once('=').unwrap();
|
||||||
|
// Unconditionally set the env var (if it was set in the environment
|
||||||
|
// already, rustc should've picked that up).
|
||||||
|
cargo.env(env_var.trim(), value.trim());
|
||||||
|
|
||||||
|
// Allow CI to override the deployment target for `std`.
|
||||||
|
if let Some(target) = env::var_os("MACOSX_STD_DEPLOYMENT_TARGET") {
|
||||||
|
cargo.env("MACOSX_DEPLOYMENT_TARGET", target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Paths needed by `library/profiler_builtins/build.rs`.
|
// Paths needed by `library/profiler_builtins/build.rs`.
|
||||||
|
|
|
@ -7,7 +7,11 @@
|
||||||
|
|
||||||
//@ only-apple
|
//@ only-apple
|
||||||
|
|
||||||
use run_make_support::{apple_os, cmd, run_in_tmpdir, rustc, target};
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
use run_make_support::{
|
||||||
|
apple_os, cmd, has_extension, path, regex, run_in_tmpdir, rustc, shallow_find_files, target,
|
||||||
|
};
|
||||||
|
|
||||||
/// Run vtool to check the `minos` field in LC_BUILD_VERSION.
|
/// Run vtool to check the `minos` field in LC_BUILD_VERSION.
|
||||||
///
|
///
|
||||||
|
@ -166,4 +170,21 @@ fn main() {
|
||||||
rustc().env_remove(env_var).run();
|
rustc().env_remove(env_var).run();
|
||||||
minos("foo.o", default_version);
|
minos("foo.o", default_version);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Test that all binaries in rlibs produced by `rustc` have the same version.
|
||||||
|
// Regression test for https://github.com/rust-lang/rust/issues/128419.
|
||||||
|
let sysroot = rustc().print("sysroot").run().stdout_utf8();
|
||||||
|
let target_sysroot = path(sysroot.trim()).join("lib/rustlib").join(target()).join("lib");
|
||||||
|
let rlibs = shallow_find_files(&target_sysroot, |path| has_extension(path, "rlib"));
|
||||||
|
|
||||||
|
let output = cmd("otool").arg("-l").args(rlibs).run().stdout_utf8();
|
||||||
|
let re = regex::Regex::new(r"(minos|version) ([0-9.]*)").unwrap();
|
||||||
|
let mut versions = HashSet::new();
|
||||||
|
for (_, [_, version]) in re.captures_iter(&output).map(|c| c.extract()) {
|
||||||
|
versions.insert(version);
|
||||||
|
}
|
||||||
|
// FIXME(madsmtm): See above for aarch64-apple-watchos.
|
||||||
|
if versions.len() != 1 && target() != "aarch64-apple-watchos" {
|
||||||
|
panic!("std rlibs contained multiple different deployment target versions: {versions:?}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue