@@ -1551,6 +1551,7 @@ impl Config {
1551
1551
let mut debuginfo_level_tests = None ;
1552
1552
let mut optimize = None ;
1553
1553
let mut omit_git_hash = None ;
1554
+ let mut lld_enabled = None ;
1554
1555
1555
1556
if let Some ( rust) = toml. rust {
1556
1557
let Rust {
@@ -1584,7 +1585,7 @@ impl Config {
1584
1585
dist_src,
1585
1586
save_toolstates,
1586
1587
codegen_backends,
1587
- lld,
1588
+ lld : lld_enabled_toml ,
1588
1589
llvm_tools,
1589
1590
llvm_bitcode_linker,
1590
1591
deny_warnings,
@@ -1639,6 +1640,7 @@ impl Config {
1639
1640
debuginfo_level_std = debuginfo_level_std_toml;
1640
1641
debuginfo_level_tools = debuginfo_level_tools_toml;
1641
1642
debuginfo_level_tests = debuginfo_level_tests_toml;
1643
+ lld_enabled = lld_enabled_toml;
1642
1644
1643
1645
config. rust_split_debuginfo_for_build_triple = split_debuginfo
1644
1646
. as_deref ( )
@@ -1672,18 +1674,8 @@ impl Config {
1672
1674
config. incremental = true ;
1673
1675
}
1674
1676
set ( & mut config. lld_mode , lld_mode) ;
1675
- set ( & mut config. lld_enabled , lld) ;
1676
1677
set ( & mut config. llvm_bitcode_linker_enabled , llvm_bitcode_linker) ;
1677
1678
1678
- if matches ! ( config. lld_mode, LldMode :: SelfContained )
1679
- && !config. lld_enabled
1680
- && flags. stage . unwrap_or ( 0 ) > 0
1681
- {
1682
- panic ! (
1683
- "Trying to use self-contained lld as a linker, but LLD is not being added to the sysroot. Enable it with rust.lld = true."
1684
- ) ;
1685
- }
1686
-
1687
1679
config. llvm_tools_enabled = llvm_tools. unwrap_or ( true ) ;
1688
1680
config. rustc_parallel =
1689
1681
parallel_compiler. unwrap_or ( config. channel == "dev" || config. channel == "nightly" ) ;
@@ -1973,6 +1965,43 @@ impl Config {
1973
1965
config. llvm_plugins = llvm_plugins. unwrap_or ( false ) ;
1974
1966
config. rust_optimize = optimize. unwrap_or ( RustOptimize :: Bool ( true ) ) ;
1975
1967
1968
+ // We make `x86_64-unknown-linux-gnu` use the self-contained linker by default, so we will
1969
+ // build our internal lld and use it as the default linker, by setting the `rust.lld` config
1970
+ // to true by default:
1971
+ // - on the `x86_64-unknown-linux-gnu` target
1972
+ // - on the `dev` and `nightly` channels
1973
+ // - when building our in-tree llvm (i.e. the target has not set an `llvm-config`), so that
1974
+ // we're also able to build the corresponding lld
1975
+ // - or when using an external llvm that's downloaded from CI, which also contains our prebuilt
1976
+ // lld
1977
+ // - otherwise, we'd be using an external llvm, and lld would not necessarily available and
1978
+ // thus, disabled
1979
+ // - similarly, lld will not be built nor used by default when explicitly asked not to, e.g.
1980
+ // when the config sets `rust.lld = false`
1981
+ if config. build . triple == "x86_64-unknown-linux-gnu"
1982
+ && config. hosts == & [ config. build ]
1983
+ && ( config. channel == "dev" || config. channel == "nightly" )
1984
+ {
1985
+ let no_llvm_config = config
1986
+ . target_config
1987
+ . get ( & config. build )
1988
+ . is_some_and ( |target_config| target_config. llvm_config . is_none ( ) ) ;
1989
+ let enable_lld = config. llvm_from_ci || no_llvm_config;
1990
+ // Prefer the config setting in case an explicit opt-out is needed.
1991
+ config. lld_enabled = lld_enabled. unwrap_or ( enable_lld) ;
1992
+ } else {
1993
+ set ( & mut config. lld_enabled , lld_enabled) ;
1994
+ }
1995
+
1996
+ if matches ! ( config. lld_mode, LldMode :: SelfContained )
1997
+ && !config. lld_enabled
1998
+ && flags. stage . unwrap_or ( 0 ) > 0
1999
+ {
2000
+ panic ! (
2001
+ "Trying to use self-contained lld as a linker, but LLD is not being added to the sysroot. Enable it with rust.lld = true."
2002
+ ) ;
2003
+ }
2004
+
1976
2005
let default = debug == Some ( true ) ;
1977
2006
config. rust_debug_assertions = debug_assertions. unwrap_or ( default) ;
1978
2007
config. rust_debug_assertions_std =
0 commit comments