Skip to content

Commit 40857b9

Browse files
committed
Auto merge of #75111 - mati865:use-lld-option, r=Mark-Simulacrum
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.
2 parents 80f84eb + 594f81a commit 40857b9

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

config.toml.example

+2-2
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@
433433
#
434434
# LLD will not be used if we're cross linking or running tests.
435435
#
436-
# Explicitly setting the linker for a target will override this option.
436+
# Explicitly setting the linker for a target will override this option when targeting MSVC.
437437
#use-lld = false
438438

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

509509
# Path to the `llvm-config` binary of the installation of a custom LLVM to link

src/bootstrap/builder.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ impl<'a> Builder<'a> {
10371037
}
10381038
}
10391039

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

@@ -1049,6 +1049,11 @@ impl<'a> Builder<'a> {
10491049
let target = crate::envify(&target.triple);
10501050
cargo.env(&format!("CARGO_TARGET_{}_LINKER", target), target_linker);
10511051
}
1052+
1053+
if self.config.use_lld && !target.contains("msvc") {
1054+
rustflags.arg("-Clink-args=-fuse-ld=lld");
1055+
}
1056+
10521057
if !(["build", "check", "clippy", "fix", "rustc"].contains(&cmd)) && want_rustdoc {
10531058
cargo.env("RUSTDOC_LIBDIR", self.rustc_libdir(compiler));
10541059
}

0 commit comments

Comments
 (0)