Skip to content

Commit

Permalink
Auto merge of #75111 - mati865:use-lld-option, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Make rust.use-lld config option work with non MSVC targets

Builds fine and passes tests on Linux.
Not overriding `use-lld` by `linker` makes sense on those platforms since very old GCC versions don't understand `-fuse-ld=lld`. This allows pointing to newer GCC or Clang that will know how to call LLD.
  • Loading branch information
bors committed Aug 4, 2020
2 parents 80f84eb + 594f81a commit 40857b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@
#
# LLD will not be used if we're cross linking or running tests.
#
# Explicitly setting the linker for a target will override this option.
# Explicitly setting the linker for a target will override this option when targeting MSVC.
#use-lld = false

# Indicates whether some LLVM tools, like llvm-objdump, will be made available in the
Expand Down Expand Up @@ -503,7 +503,7 @@
# Linker to be used to link Rust code. Note that the
# default value is platform specific, and if not specified it may also depend on
# what platform is crossing to what platform.
# Setting this will override the `use-lld` option for Rust code.
# Setting this will override the `use-lld` option for Rust code when targeting MSVC.
#linker = "cc"

# Path to the `llvm-config` binary of the installation of a custom LLVM to link
Expand Down
7 changes: 6 additions & 1 deletion src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ impl<'a> Builder<'a> {
}
}

// FIXME: Don't use LLD if we're compiling libtest, since it fails to link it.
// FIXME: Don't use LLD with MSVC if we're compiling libtest, since it fails to link it.
// See https://github.com/rust-lang/rust/issues/68647.
let can_use_lld = mode != Mode::Std;

Expand All @@ -1049,6 +1049,11 @@ impl<'a> Builder<'a> {
let target = crate::envify(&target.triple);
cargo.env(&format!("CARGO_TARGET_{}_LINKER", target), target_linker);
}

if self.config.use_lld && !target.contains("msvc") {
rustflags.arg("-Clink-args=-fuse-ld=lld");
}

if !(["build", "check", "clippy", "fix", "rustc"].contains(&cmd)) && want_rustdoc {
cargo.env("RUSTDOC_LIBDIR", self.rustc_libdir(compiler));
}
Expand Down

0 comments on commit 40857b9

Please sign in to comment.