mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-30 09:24:35 +00:00
Don't use target's linker when linking build scripts
This commit is contained in:
parent
9e0fc5ccd0
commit
89d9ce4ec3
@ -120,6 +120,11 @@ fn main() {
|
||||
cmd.arg("-L").arg(&root);
|
||||
}
|
||||
|
||||
// Override linker if necessary.
|
||||
if let Ok(target_linker) = env::var("RUSTC_TARGET_LINKER") {
|
||||
cmd.arg(format!("-Clinker={}", target_linker));
|
||||
}
|
||||
|
||||
// Pass down incremental directory, if any.
|
||||
if let Ok(dir) = env::var("RUSTC_INCREMENTAL") {
|
||||
cmd.arg(format!("-Zincremental={}", dir));
|
||||
@ -246,13 +251,11 @@ fn main() {
|
||||
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
|
||||
cmd.arg("-Z").arg("force-unstable-if-unmarked");
|
||||
}
|
||||
}
|
||||
|
||||
// Pass down extra flags, commonly used to configure `-Clinker`.
|
||||
// Linker options should be set for build scripts as well,
|
||||
// can't link a build script executable without a linker!
|
||||
if let Ok(s) = env::var("RUSTC_FLAGS") {
|
||||
cmd.args(&s.split(" ").filter(|s| !s.is_empty()).collect::<Vec<_>>());
|
||||
} else {
|
||||
// Override linker if necessary.
|
||||
if let Ok(host_linker) = env::var("RUSTC_HOST_LINKER") {
|
||||
cmd.arg(format!("-Clinker={}", host_linker));
|
||||
}
|
||||
}
|
||||
|
||||
let color = match env::var("RUSTC_COLOR") {
|
||||
|
@ -47,7 +47,7 @@ fn main() {
|
||||
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
|
||||
cmd.arg("-Z").arg("force-unstable-if-unmarked");
|
||||
}
|
||||
if let Some(linker) = env::var_os("RUSTDOC_LINKER") {
|
||||
if let Some(linker) = env::var_os("RUSTC_TARGET_LINKER") {
|
||||
cmd.arg("--linker").arg(linker).arg("-Z").arg("unstable-options");
|
||||
}
|
||||
|
||||
|
@ -420,7 +420,7 @@ impl<'a> Builder<'a> {
|
||||
.env("RUSTDOC_REAL", self.rustdoc(host))
|
||||
.env("RUSTDOC_CRATE_VERSION", self.build.rust_version());
|
||||
if let Some(linker) = self.build.linker(host) {
|
||||
cmd.env("RUSTDOC_LINKER", linker);
|
||||
cmd.env("RUSTC_TARGET_LINKER", linker);
|
||||
}
|
||||
cmd
|
||||
}
|
||||
@ -484,11 +484,13 @@ impl<'a> Builder<'a> {
|
||||
} else {
|
||||
PathBuf::from("/path/to/nowhere/rustdoc/not/required")
|
||||
})
|
||||
.env("TEST_MIRI", self.config.test_miri.to_string())
|
||||
.env("RUSTC_FLAGS", self.rustc_flags(target).join(" "));
|
||||
.env("TEST_MIRI", self.config.test_miri.to_string());
|
||||
|
||||
if let Some(linker) = self.build.linker(target) {
|
||||
cargo.env("RUSTDOC_LINKER", linker);
|
||||
if let Some(host_linker) = self.build.linker(compiler.host) {
|
||||
cargo.env("RUSTC_HOST_LINKER", host_linker);
|
||||
}
|
||||
if let Some(target_linker) = self.build.linker(target) {
|
||||
cargo.env("RUSTC_TARGET_LINKER", target_linker);
|
||||
}
|
||||
|
||||
if mode != Mode::Tool {
|
||||
|
@ -725,9 +725,6 @@ impl Step for Compiletest {
|
||||
// Avoid depending on rustdoc when we don't need it.
|
||||
if mode == "rustdoc" || mode == "run-make" {
|
||||
cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host));
|
||||
if let Some(linker) = build.linker(target) {
|
||||
cmd.arg("--linker").arg(linker);
|
||||
}
|
||||
}
|
||||
|
||||
cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
|
||||
@ -750,12 +747,14 @@ impl Step for Compiletest {
|
||||
flags.push("-g".to_string());
|
||||
}
|
||||
|
||||
let mut hostflags = build.rustc_flags(compiler.host);
|
||||
hostflags.extend(flags.clone());
|
||||
if let Some(linker) = build.linker(target) {
|
||||
cmd.arg("--linker").arg(linker);
|
||||
}
|
||||
|
||||
let hostflags = flags.clone();
|
||||
cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
|
||||
|
||||
let mut targetflags = build.rustc_flags(target);
|
||||
targetflags.extend(flags);
|
||||
let mut targetflags = flags.clone();
|
||||
targetflags.push(format!("-Lnative={}",
|
||||
build.test_helpers_out(target).display()));
|
||||
cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
|
||||
|
@ -649,10 +649,6 @@ impl Build {
|
||||
self.ar.get(&target).map(|p| &**p)
|
||||
}
|
||||
|
||||
fn linker(&self, target: Interned<String>) -> Option<&Path> {
|
||||
self.config.target_config.get(&target).and_then(|c| c.linker.as_ref().map(|p| &**p))
|
||||
}
|
||||
|
||||
/// Returns the path to the C++ compiler for the target specified.
|
||||
fn cxx(&self, target: Interned<String>) -> Result<&Path, String> {
|
||||
match self.cxx.get(&target) {
|
||||
@ -663,24 +659,16 @@ impl Build {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns flags to pass to the compiler to generate code for `target`.
|
||||
fn rustc_flags(&self, target: Interned<String>) -> Vec<String> {
|
||||
// New flags should be added here with great caution!
|
||||
//
|
||||
// It's quite unfortunate to **require** flags to generate code for a
|
||||
// target, so it should only be passed here if absolutely necessary!
|
||||
// Most default configuration should be done through target specs rather
|
||||
// than an entry here.
|
||||
|
||||
let mut base = Vec::new();
|
||||
if let Some(linker) = self.linker(target) {
|
||||
// If linker was explictly provided, force it on all the compiled Rust code.
|
||||
base.push(format!("-Clinker={}", linker.display()));
|
||||
} else if target != self.config.build && !target.contains("msvc") &&
|
||||
!target.contains("emscripten") {
|
||||
base.push(format!("-Clinker={}", self.cc(target).display()));
|
||||
/// Returns the path to the linker for the given target if it needs to be overriden.
|
||||
fn linker(&self, target: Interned<String>) -> Option<&Path> {
|
||||
if let Some(config) = self.config.target_config.get(&target) {
|
||||
config.linker.as_ref().map(|p| &**p)
|
||||
} else if target != self.config.build &&
|
||||
!target.contains("msvc") && !target.contains("emscripten") {
|
||||
Some(self.cc(target))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
base
|
||||
}
|
||||
|
||||
/// Returns if this target should statically link the C runtime, if specified
|
||||
|
@ -1444,6 +1444,9 @@ actual:\n\
|
||||
} else {
|
||||
rustc.args(self.split_maybe_args(&self.config.target_rustcflags));
|
||||
}
|
||||
if let Some(ref linker) = self.config.linker {
|
||||
rustc.arg(format!("-Clinker={}", linker));
|
||||
}
|
||||
|
||||
rustc.args(&self.props.compile_flags);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user