Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9d33ef3

Browse files
Rollup merge of rust-lang#147046 - Kobzol:bootstrap-ll, r=jieyouxu
Rename `rust.use-lld` to `rust.bootstrap-override-lld` First part of rust-lang#146640. The old option is kept for backwards compatibility, we can remove it in ~6 months, as usually. I'm not sure if the bootstrap prefix is ideal, after all we have a bunch of other configs that only affect bootstrap's behavior and not the built artifacts. Maybe `build.override-lld`? But I don't think it matters that much, as long as it's clear that it is an override, and how does it differ from `rust.lld`. r? ```@jieyouxu```
2 parents 66cfbfe + 0374fc5 commit 9d33ef3

File tree

11 files changed

+113
-54
lines changed

11 files changed

+113
-54
lines changed

‎bootstrap.example.toml‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,16 +768,15 @@
768768
# make this default to false.
769769
#rust.lld = false in all cases, except on `x86_64-unknown-linux-gnu` as described above, where it is true
770770

771-
# Indicates whether LLD will be used to link Rust crates during bootstrap on
772-
# supported platforms.
771+
# Indicates if we should override the linker used to link Rust crates during bootstrap to be LLD.
773772
# If set to `true` or `"external"`, a global `lld` binary that has to be in $PATH
774773
# will be used.
775774
# If set to `"self-contained"`, rust-lld from the snapshot compiler will be used.
776775
#
777776
# On MSVC, LLD will not be used if we're cross linking.
778777
#
779778
# Explicitly setting the linker for a target will override this option when targeting MSVC.
780-
#rust.use-lld = false
779+
#rust.bootstrap-override-lld = false
781780

782781
# Indicates whether some LLVM tools, like llvm-objdump, will be made available in the
783782
# sysroot.
@@ -950,7 +949,7 @@
950949
# Linker to be used to bootstrap Rust code. Note that the
951950
# default value is platform specific, and if not specified it may also depend on
952951
# what platform is crossing to what platform.
953-
# Setting this will override the `use-lld` option for Rust code when targeting MSVC.
952+
# Setting this will override the `bootstrap-override-lld` option for Rust code when targeting MSVC.
954953
#linker = "cc" (path)
955954

956955
# Should rustc and the standard library be built with split debuginfo? Default

‎src/bootstrap/src/core/build_steps/compile.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ pub fn rustc_cargo(
12211221
// us a faster startup time. However GNU ld < 2.40 will error if we try to link a shared object
12221222
// with direct references to protected symbols, so for now we only use protected symbols if
12231223
// linking with LLD is enabled.
1224-
if builder.build.config.lld_mode.is_used() {
1224+
if builder.build.config.bootstrap_override_lld.is_used() {
12251225
cargo.rustflag("-Zdefault-visibility=protected");
12261226
}
12271227

@@ -1258,7 +1258,7 @@ pub fn rustc_cargo(
12581258
// is already on by default in MSVC optimized builds, which is interpreted as --icf=all:
12591259
// https://github.com/llvm/llvm-project/blob/3329cec2f79185bafd678f310fafadba2a8c76d2/lld/COFF/Driver.cpp#L1746
12601260
// https://github.com/rust-lang/rust/blob/f22819bcce4abaff7d1246a56eec493418f9f4ee/compiler/rustc_codegen_ssa/src/back/linker.rs#L827
1261-
if builder.config.lld_mode.is_used() && !build_compiler.host.is_msvc() {
1261+
if builder.config.bootstrap_override_lld.is_used() && !build_compiler.host.is_msvc() {
12621262
cargo.rustflag("-Clink-args=-Wl,--icf=all");
12631263
}
12641264

‎src/bootstrap/src/core/config/config.rs‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use crate::core::config::toml::gcc::Gcc;
4141
use crate::core::config::toml::install::Install;
4242
use crate::core::config::toml::llvm::Llvm;
4343
use crate::core::config::toml::rust::{
44-
LldMode, Rust, RustOptimize, check_incompatible_options_for_ci_rustc,
44+
BootstrapOverrideLld, Rust, RustOptimize, check_incompatible_options_for_ci_rustc,
4545
default_lld_opt_in_targets, parse_codegen_backends,
4646
};
4747
use crate::core::config::toml::target::Target;
@@ -174,7 +174,7 @@ pub struct Config {
174174
pub llvm_from_ci: bool,
175175
pub llvm_build_config: HashMap<String, String>,
176176

177-
pub lld_mode:LldMode,
177+
pub bootstrap_override_lld:BootstrapOverrideLld,
178178
pub lld_enabled: bool,
179179
pub llvm_tools_enabled: bool,
180180
pub llvm_bitcode_linker_enabled: bool,
@@ -553,7 +553,8 @@ impl Config {
553553
frame_pointers: rust_frame_pointers,
554554
stack_protector: rust_stack_protector,
555555
strip: rust_strip,
556-
lld_mode: rust_lld_mode,
556+
bootstrap_override_lld: rust_bootstrap_override_lld,
557+
bootstrap_override_lld_legacy: rust_bootstrap_override_lld_legacy,
557558
std_features: rust_std_features,
558559
break_on_ice: rust_break_on_ice,
559560
} = toml.rust.unwrap_or_default();
@@ -601,6 +602,15 @@ impl Config {
601602

602603
let Gcc { download_ci_gcc: gcc_download_ci_gcc } = toml.gcc.unwrap_or_default();
603604

605+
if rust_bootstrap_override_lld.is_some() && rust_bootstrap_override_lld_legacy.is_some() {
606+
panic!(
607+
"Cannot use both `rust.use-lld` and `rust.bootstrap-override-lld`. Please use only `rust.bootstrap-override-lld`"
608+
);
609+
}
610+
611+
let bootstrap_override_lld =
612+
rust_bootstrap_override_lld.or(rust_bootstrap_override_lld_legacy).unwrap_or_default();
613+
604614
if rust_optimize.as_ref().is_some_and(|v| matches!(v, RustOptimize::Bool(false))) {
605615
eprintln!(
606616
"WARNING: setting `optimize` to `false` is known to cause errors and \
@@ -932,7 +942,7 @@ impl Config {
932942

933943
let initial_rustfmt = build_rustfmt.or_else(|| maybe_download_rustfmt(&dwn_ctx, &out));
934944

935-
if matches!(rust_lld_mode.unwrap_or_default(),LldMode::SelfContained)
945+
if matches!(bootstrap_override_lld,BootstrapOverrideLld::SelfContained)
936946
&& !lld_enabled
937947
&& flags_stage.unwrap_or(0) > 0
938948
{
@@ -1144,6 +1154,7 @@ impl Config {
11441154
backtrace_on_ice: rust_backtrace_on_ice.unwrap_or(false),
11451155
bindir: install_bindir.map(PathBuf::from).unwrap_or("bin".into()),
11461156
bootstrap_cache_path: build_bootstrap_cache_path,
1157+
bootstrap_override_lld,
11471158
bypass_bootstrap_lock: flags_bypass_bootstrap_lock,
11481159
cargo_info,
11491160
cargo_native_static: build_cargo_native_static.unwrap_or(false),
@@ -1210,7 +1221,6 @@ impl Config {
12101221
libdir: install_libdir.map(PathBuf::from),
12111222
library_docs_private_items: build_library_docs_private_items.unwrap_or(false),
12121223
lld_enabled,
1213-
lld_mode: rust_lld_mode.unwrap_or_default(),
12141224
lldb: build_lldb.map(PathBuf::from),
12151225
llvm_allow_old_toolchain: llvm_allow_old_toolchain.unwrap_or(false),
12161226
llvm_assertions,

‎src/bootstrap/src/core/config/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use serde_derive::Deserialize;
3737
pub use target_selection::TargetSelection;
3838
pub use toml::BUILDER_CONFIG_FILENAME;
3939
pub use toml::change_id::ChangeId;
40-
pub use toml::rust::LldMode;
40+
pub use toml::rust::BootstrapOverrideLld;
4141
pub use toml::target::Target;
4242

4343
use crate::Display;

‎src/bootstrap/src/core/config/tests.rs‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use crate::core::build_steps::clippy::{LintConfig, get_clippy_rules_in_order};
1717
use crate::core::build_steps::llvm;
1818
use crate::core::build_steps::llvm::LLVM_INVALIDATION_PATHS;
1919
use crate::core::config::toml::TomlConfig;
20-
use crate::core::config::{CompilerBuiltins, LldMode, StringOrBool, Target, TargetSelection};
20+
use crate::core::config::{
21+
BootstrapOverrideLld, CompilerBuiltins, StringOrBool, Target, TargetSelection,
22+
};
2123
use crate::utils::tests::git::git_test;
2224

2325
pub(crate) fn parse(config: &str) -> Config {
@@ -298,11 +300,33 @@ fn verify_file_integrity() {
298300

299301
#[test]
300302
fn rust_lld() {
301-
assert!(matches!(parse("").lld_mode, LldMode::Unused));
302-
assert!(matches!(parse("rust.use-lld = \"self-contained\"").lld_mode, LldMode::SelfContained));
303-
assert!(matches!(parse("rust.use-lld = \"external\"").lld_mode, LldMode::External));
304-
assert!(matches!(parse("rust.use-lld = true").lld_mode, LldMode::External));
305-
assert!(matches!(parse("rust.use-lld = false").lld_mode, LldMode::Unused));
303+
assert!(matches!(parse("").bootstrap_override_lld, BootstrapOverrideLld::None));
304+
assert!(matches!(
305+
parse("rust.bootstrap-override-lld = \"self-contained\"").bootstrap_override_lld,
306+
BootstrapOverrideLld::SelfContained
307+
));
308+
assert!(matches!(
309+
parse("rust.bootstrap-override-lld = \"external\"").bootstrap_override_lld,
310+
BootstrapOverrideLld::External
311+
));
312+
assert!(matches!(
313+
parse("rust.bootstrap-override-lld = true").bootstrap_override_lld,
314+
BootstrapOverrideLld::External
315+
));
316+
assert!(matches!(
317+
parse("rust.bootstrap-override-lld = false").bootstrap_override_lld,
318+
BootstrapOverrideLld::None
319+
));
320+
321+
// Also check the legacy options
322+
assert!(matches!(
323+
parse("rust.use-lld = true").bootstrap_override_lld,
324+
BootstrapOverrideLld::External
325+
));
326+
assert!(matches!(
327+
parse("rust.use-lld = false").bootstrap_override_lld,
328+
BootstrapOverrideLld::None
329+
));
306330
}
307331

308332
#[test]

‎src/bootstrap/src/core/config/toml/rust.rs‎

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ define_config! {
4545
codegen_backends: Option<Vec<String>> = "codegen-backends",
4646
llvm_bitcode_linker: Option<bool> = "llvm-bitcode-linker",
4747
lld: Option<bool> = "lld",
48-
lld_mode: Option<LldMode> = "use-lld",
48+
bootstrap_override_lld: Option<BootstrapOverrideLld> = "bootstrap-override-lld",
49+
// FIXME: Remove this option in Spring 2026
50+
bootstrap_override_lld_legacy: Option<BootstrapOverrideLld> = "use-lld",
4951
llvm_tools: Option<bool> = "llvm-tools",
5052
deny_warnings: Option<bool> = "deny-warnings",
5153
backtrace_on_ice: Option<bool> = "backtrace-on-ice",
@@ -70,22 +72,33 @@ define_config! {
7072
}
7173
}
7274

73-
/// LLD in bootstrap works like this:
74-
/// - Self-contained lld: use `rust-lld` from the compiler's sysroot
75+
/// Determines if we should override the linker used for linking Rust code built
76+
/// during the bootstrapping process to be LLD.
77+
///
78+
/// The primary use-case for this is to make local (re)builds of Rust code faster
79+
/// when using bootstrap.
80+
///
81+
/// This does not affect the *behavior* of the built/distributed compiler when invoked
82+
/// outside of bootstrap.
83+
/// It might affect its performance/binary size though, as that can depend on the
84+
/// linker that links rustc.
85+
///
86+
/// There are two ways of overriding the linker to be LLD:
87+
/// - Self-contained LLD: use `rust-lld` from the compiler's sysroot
7588
/// - External: use an external `lld` binary
7689
///
7790
/// It is configured depending on the target:
7891
/// 1) Everything except MSVC
79-
/// - Self-contained: `-Clinker-flavor=gnu-lld-cc -Clink-self-contained=+linker`
80-
/// - External: `-Clinker-flavor=gnu-lld-cc`
92+
/// - Self-contained: `-Clinker-features=+lld -Clink-self-contained=+linker`
93+
/// - External: `-Clinker-features=+lld`
8194
/// 2) MSVC
8295
/// - Self-contained: `-Clinker=<path to rust-lld>`
8396
/// - External: `-Clinker=lld`
8497
#[derive(Copy, Clone, Default, Debug, PartialEq)]
85-
pub enum LldMode {
86-
/// Do not use LLD
98+
pub enum BootstrapOverrideLld {
99+
/// Do not override the linker LLD
87100
#[default]
88-
Unused,
101+
None,
89102
/// Use `rust-lld` from the compiler's sysroot
90103
SelfContained,
91104
/// Use an externally provided `lld` binary.
@@ -94,24 +107,24 @@ pub enum LldMode {
94107
External,
95108
}
96109

97-
impl LldMode {
110+
impl BootstrapOverrideLld {
98111
pub fn is_used(&self) -> bool {
99112
match self {
100-
LldMode::SelfContained | LldMode::External => true,
101-
LldMode::Unused => false,
113+
BootstrapOverrideLld::SelfContained | BootstrapOverrideLld::External => true,
114+
BootstrapOverrideLld::None => false,
102115
}
103116
}
104117
}
105118

106-
impl<'de> Deserialize<'de> for LldMode {
119+
impl<'de> Deserialize<'de> for BootstrapOverrideLld {
107120
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
108121
where
109122
D: Deserializer<'de>,
110123
{
111124
struct LldModeVisitor;
112125

113126
impl serde::de::Visitor<'_> for LldModeVisitor {
114-
type Value = LldMode;
127+
type Value = BootstrapOverrideLld;
115128

116129
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
117130
formatter.write_str("one of true, 'self-contained' or 'external'")
@@ -121,16 +134,16 @@ impl<'de> Deserialize<'de> for LldMode {
121134
where
122135
E: serde::de::Error,
123136
{
124-
Ok(if v { LldMode::External } else { LldMode::Unused })
137+
Ok(if v { BootstrapOverrideLld::External } else { BootstrapOverrideLld::None })
125138
}
126139

127140
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
128141
where
129142
E: serde::de::Error,
130143
{
131144
match v {
132-
"external" => Ok(LldMode::External),
133-
"self-contained" => Ok(LldMode::SelfContained),
145+
"external" => Ok(BootstrapOverrideLld::External),
146+
"self-contained" => Ok(BootstrapOverrideLld::SelfContained),
134147
_ => Err(E::custom(format!("unknown mode {v}"))),
135148
}
136149
}
@@ -311,7 +324,6 @@ pub fn check_incompatible_options_for_ci_rustc(
311324
lto,
312325
stack_protector,
313326
strip,
314-
lld_mode,
315327
jemalloc,
316328
rpath,
317329
channel,
@@ -359,6 +371,8 @@ pub fn check_incompatible_options_for_ci_rustc(
359371
frame_pointers: _,
360372
break_on_ice: _,
361373
parallel_frontend_threads: _,
374+
bootstrap_override_lld: _,
375+
bootstrap_override_lld_legacy: _,
362376
} = ci_rust_config;
363377

364378
// There are two kinds of checks for CI rustc incompatible options:
@@ -374,7 +388,6 @@ pub fn check_incompatible_options_for_ci_rustc(
374388
err!(current_rust_config.debuginfo_level_rustc, debuginfo_level_rustc, "rust");
375389
err!(current_rust_config.rpath, rpath, "rust");
376390
err!(current_rust_config.strip, strip, "rust");
377-
err!(current_rust_config.lld_mode, lld_mode, "rust");
378391
err!(current_rust_config.llvm_tools, llvm_tools, "rust");
379392
err!(current_rust_config.llvm_bitcode_linker, llvm_bitcode_linker, "rust");
380393
err!(current_rust_config.jemalloc, jemalloc, "rust");

‎src/bootstrap/src/lib.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use utils::exec::ExecutionContext;
3535

3636
use crate::core::builder;
3737
use crate::core::builder::Kind;
38-
use crate::core::config::{DryRun,LldMode, LlvmLibunwind, TargetSelection, flags};
38+
use crate::core::config::{BootstrapOverrideLld,DryRun, LlvmLibunwind, TargetSelection, flags};
3939
use crate::utils::exec::{BootstrapCommand, command};
4040
use crate::utils::helpers::{self, dir_is_empty, exe, libdir, set_file_times, split_debuginfo};
4141

@@ -1358,14 +1358,14 @@ impl Build {
13581358
&& !target.is_msvc()
13591359
{
13601360
Some(self.cc(target))
1361-
} else if self.config.lld_mode.is_used()
1361+
} else if self.config.bootstrap_override_lld.is_used()
13621362
&& self.is_lld_direct_linker(target)
13631363
&& self.host_target == target
13641364
{
1365-
match self.config.lld_mode {
1366-
LldMode::SelfContained => Some(self.initial_lld.clone()),
1367-
LldMode::External => Some("lld".into()),
1368-
LldMode::Unused => None,
1365+
match self.config.bootstrap_override_lld {
1366+
BootstrapOverrideLld::SelfContained => Some(self.initial_lld.clone()),
1367+
BootstrapOverrideLld::External => Some("lld".into()),
1368+
BootstrapOverrideLld::None => None,
13691369
}
13701370
} else {
13711371
None

‎src/bootstrap/src/utils/change_tracker.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,4 +556,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
556556
severity: ChangeSeverity::Info,
557557
summary: "New option `build.windows-rc` that will override which resource compiler on Windows will be used to compile Rust.",
558558
},
559+
ChangeInfo {
560+
change_id: 99999,
561+
severity: ChangeSeverity::Warning,
562+
summary: "The `rust.use-lld` option has been renamed to `rust.bootstrap-override-lld`. Note that it only serves for overriding the linker used when building Rust code in bootstrap to be LLD.",
563+
},
559564
];

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /