Skip to content

Commit 7695e5a

Browse files
committed
enable rust-lld on x86_64-unknown-linux-gnu when requested
the `rust.lld` config enables rustc's `CFG_USE_SELF_CONTAINED_LINKER` env var, and we: - set the linker-flavor to use lld - enable the self-contained linker this makes the target use the rust-lld linker by default
1 parent 5f04f6d commit 7695e5a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

compiler/rustc_target/src/spec/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,12 @@ impl LinkSelfContainedDefault {
612612
_ => "crt-objects-fallback",
613613
}
614614
}
615+
616+
/// Creates a `LinkSelfContainedDefault` enabling the self-contained linker for target specs
617+
/// (the equivalent of `-Clink-self-contained=+linker` on the CLI).
618+
pub fn with_linker() -> LinkSelfContainedDefault {
619+
LinkSelfContainedDefault::WithComponents(LinkSelfContainedComponents::LINKER)
620+
}
615621
}
616622

617623
bitflags::bitflags! {

compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_gnu.rs

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ pub fn target() -> Target {
1818
| SanitizerSet::THREAD;
1919
base.supports_xray = true;
2020

21+
// When we're asked to use the `rust-lld` linker by default, set the appropriate lld-using
22+
// linker flavor, and self-contained linker component.
23+
if option_env!("CFG_USE_SELF_CONTAINED_LINKER").is_some() {
24+
base.linker_flavor = LinkerFlavor::Gnu(Cc::Yes, Lld::Yes);
25+
base.link_self_contained = crate::spec::LinkSelfContainedDefault::with_linker();
26+
}
27+
2128
Target {
2229
llvm_target: "x86_64-unknown-linux-gnu".into(),
2330
metadata: crate::spec::TargetMetadata {

0 commit comments

Comments
 (0)