@@ -1532,6 +1532,7 @@ impl Config {
1532
1532
let mut debuginfo_level_tests = None ;
1533
1533
let mut optimize = None ;
1534
1534
let mut omit_git_hash = None ;
1535
+ let mut lld_enabled = None ;
1535
1536
1536
1537
if let Some ( rust) = toml. rust {
1537
1538
let Rust {
@@ -1565,7 +1566,7 @@ impl Config {
1565
1566
dist_src,
1566
1567
save_toolstates,
1567
1568
codegen_backends,
1568
- lld,
1569
+ lld : lld_enabled_toml ,
1569
1570
llvm_tools,
1570
1571
llvm_bitcode_linker,
1571
1572
deny_warnings,
@@ -1620,6 +1621,7 @@ impl Config {
1620
1621
debuginfo_level_std = debuginfo_level_std_toml;
1621
1622
debuginfo_level_tools = debuginfo_level_tools_toml;
1622
1623
debuginfo_level_tests = debuginfo_level_tests_toml;
1624
+ lld_enabled = lld_enabled_toml;
1623
1625
1624
1626
config. rust_split_debuginfo_for_build_triple = split_debuginfo
1625
1627
. as_deref ( )
@@ -1653,18 +1655,8 @@ impl Config {
1653
1655
config. incremental = true ;
1654
1656
}
1655
1657
set ( & mut config. lld_mode , lld_mode) ;
1656
- set ( & mut config. lld_enabled , lld) ;
1657
1658
set ( & mut config. llvm_bitcode_linker_enabled , llvm_bitcode_linker) ;
1658
1659
1659
- if matches ! ( config. lld_mode, LldMode :: SelfContained )
1660
- && !config. lld_enabled
1661
- && flags. stage . unwrap_or ( 0 ) > 0
1662
- {
1663
- panic ! (
1664
- "Trying to use self-contained lld as a linker, but LLD is not being added to the sysroot. Enable it with rust.lld = true."
1665
- ) ;
1666
- }
1667
-
1668
1660
config. llvm_tools_enabled = llvm_tools. unwrap_or ( true ) ;
1669
1661
config. rustc_parallel =
1670
1662
parallel_compiler. unwrap_or ( config. channel == "dev" || config. channel == "nightly" ) ;
@@ -1954,6 +1946,43 @@ impl Config {
1954
1946
config. llvm_plugins = llvm_plugins. unwrap_or ( false ) ;
1955
1947
config. rust_optimize = optimize. unwrap_or ( RustOptimize :: Bool ( true ) ) ;
1956
1948
1949
+ // We make `x86_64-unknown-linux-gnu` use the self-contained linker by default, so we will
1950
+ // build our internal lld and use it as the default linker, by setting the `rust.lld` config
1951
+ // to true by default:
1952
+ // - on the `x86_64-unknown-linux-gnu` target
1953
+ // - on the `dev` and `nightly` channels
1954
+ // - when building our in-tree llvm (i.e. the target has not set an `llvm-config`), so that
1955
+ // we're also able to build the corresponding lld
1956
+ // - or when using an external llvm that's downloaded from CI, which also contains our prebuilt
1957
+ // lld
1958
+ // - otherwise, we'd be using an external llvm, and lld would not necessarily available and
1959
+ // thus, disabled
1960
+ // - similarly, lld will not be built nor used by default when explicitly asked not to, e.g.
1961
+ // when the config sets `rust.lld = false`
1962
+ if config. build . triple == "x86_64-unknown-linux-gnu"
1963
+ && config. hosts == [ config. build ]
1964
+ && ( config. channel == "dev" || config. channel == "nightly" )
1965
+ {
1966
+ let no_llvm_config = config
1967
+ . target_config
1968
+ . get ( & config. build )
1969
+ . is_some_and ( |target_config| target_config. llvm_config . is_none ( ) ) ;
1970
+ let enable_lld = config. llvm_from_ci || no_llvm_config;
1971
+ // Prefer the config setting in case an explicit opt-out is needed.
1972
+ config. lld_enabled = lld_enabled. unwrap_or ( enable_lld) ;
1973
+ } else {
1974
+ set ( & mut config. lld_enabled , lld_enabled) ;
1975
+ }
1976
+
1977
+ if matches ! ( config. lld_mode, LldMode :: SelfContained )
1978
+ && !config. lld_enabled
1979
+ && flags. stage . unwrap_or ( 0 ) > 0
1980
+ {
1981
+ panic ! (
1982
+ "Trying to use self-contained lld as a linker, but LLD is not being added to the sysroot. Enable it with rust.lld = true."
1983
+ ) ;
1984
+ }
1985
+
1957
1986
let default = debug == Some ( true ) ;
1958
1987
config. rust_debug_assertions = debug_assertions. unwrap_or ( default) ;
1959
1988
config. rust_debug_assertions_std =
0 commit comments