rustbuild: Deduplicate LLD checks slightly

This commit is contained in:
Vadim Petrochenkov
2020-09-07 00:39:58 +03:00
parent 5118a51b4d
commit b27fca71d4
3 changed files with 13 additions and 10 deletions

View File

@@ -758,7 +758,7 @@ impl<'a> Builder<'a> {
if let Some(linker) = self.linker(compiler.host) { if let Some(linker) = self.linker(compiler.host) {
cmd.env("RUSTDOC_LINKER", linker); cmd.env("RUSTDOC_LINKER", linker);
} }
if self.config.use_lld && !compiler.host.contains("msvc") { if self.is_fuse_ld_lld(compiler.host) {
cmd.env("RUSTDOC_FUSE_LD_LLD", "1"); cmd.env("RUSTDOC_FUSE_LD_LLD", "1");
} }
cmd cmd
@@ -1047,7 +1047,7 @@ impl<'a> Builder<'a> {
if let Some(host_linker) = self.linker(compiler.host) { if let Some(host_linker) = self.linker(compiler.host) {
cargo.env("RUSTC_HOST_LINKER", host_linker); cargo.env("RUSTC_HOST_LINKER", host_linker);
} }
if self.config.use_lld && !compiler.host.contains("msvc") { if self.is_fuse_ld_lld(compiler.host) {
cargo.env("RUSTC_HOST_FUSE_LD_LLD", "1"); cargo.env("RUSTC_HOST_FUSE_LD_LLD", "1");
} }
@@ -1055,8 +1055,7 @@ impl<'a> Builder<'a> {
let target = crate::envify(&target.triple); let target = crate::envify(&target.triple);
cargo.env(&format!("CARGO_TARGET_{}_LINKER", target), target_linker); cargo.env(&format!("CARGO_TARGET_{}_LINKER", target), target_linker);
} }
if self.is_fuse_ld_lld(target) {
if self.config.use_lld && !target.contains("msvc") {
rustflags.arg("-Clink-args=-fuse-ld=lld"); rustflags.arg("-Clink-args=-fuse-ld=lld");
} }

View File

@@ -863,15 +863,19 @@ impl Build {
&& !target.contains("msvc") && !target.contains("msvc")
{ {
Some(self.cc(target)) Some(self.cc(target))
} else if target.contains("msvc") && self.config.use_lld && self.build == target { } else if self.config.use_lld && !self.is_fuse_ld_lld(target) && self.build == target {
// `rust.use_lld` means using LLD directly only for MSVC, for other targets it only
// adds `-fuse-ld=lld` to already selected linker.
Some(&self.initial_lld) Some(&self.initial_lld)
} else { } else {
None None
} }
} }
// LLD is used through `-fuse-ld=lld` rather than directly.
// Only MSVC targets use LLD directly at the moment.
fn is_fuse_ld_lld(&self, target: TargetSelection) -> bool {
self.config.use_lld && !target.contains("msvc")
}
/// Returns if this target should statically link the C runtime, if specified /// Returns if this target should statically link the C runtime, if specified
fn crt_static(&self, target: TargetSelection) -> Option<bool> { fn crt_static(&self, target: TargetSelection) -> Option<bool> {
if target.contains("pc-windows-msvc") { if target.contains("pc-windows-msvc") {

View File

@@ -603,7 +603,7 @@ impl Step for RustdocTheme {
if let Some(linker) = builder.linker(self.compiler.host) { if let Some(linker) = builder.linker(self.compiler.host) {
cmd.env("RUSTDOC_LINKER", linker); cmd.env("RUSTDOC_LINKER", linker);
} }
if builder.config.use_lld && !self.compiler.host.contains("msvc") { if builder.is_fuse_ld_lld(self.compiler.host) {
cmd.env("RUSTDOC_FUSE_LD_LLD", "1"); cmd.env("RUSTDOC_FUSE_LD_LLD", "1");
} }
try_run(builder, &mut cmd); try_run(builder, &mut cmd);
@@ -1070,14 +1070,14 @@ impl Step for Compiletest {
let mut hostflags = flags.clone(); let mut hostflags = flags.clone();
hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display())); hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
if builder.config.use_lld && !compiler.host.triple.contains("msvc") { if builder.is_fuse_ld_lld(compiler.host) {
hostflags.push("-Clink-args=-fuse-ld=lld".to_string()); hostflags.push("-Clink-args=-fuse-ld=lld".to_string());
} }
cmd.arg("--host-rustcflags").arg(hostflags.join(" ")); cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
let mut targetflags = flags; let mut targetflags = flags;
targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display())); targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
if builder.config.use_lld && !target.contains("msvc") { if builder.is_fuse_ld_lld(target) {
targetflags.push("-Clink-args=-fuse-ld=lld".to_string()); targetflags.push("-Clink-args=-fuse-ld=lld".to_string());
} }
cmd.arg("--target-rustcflags").arg(targetflags.join(" ")); cmd.arg("--target-rustcflags").arg(targetflags.join(" "));