Skip to content

Commit 2cebb03

Browse files
authored
Unrolled build for #144126
Rollup merge of #144126 - Shourya742:2025-06-18-fix-target-config-issue, r=Kobzol Fix empty target_config in apply_rust_config bootstrap This PR fixes the issue of an empty target_config in apply_rust_config, which was caused by the ordering of TOML config parsing. This was inadvertently introduced during the last config refactor. The test and the corresponding configuration order have been corrected in this PR. r? ```@Kobzol```
2 parents c0b282f + fb10084 commit 2cebb03

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

src/bootstrap/src/core/builder/tests.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ mod snapshot {
642642
};
643643
use crate::core::builder::{Builder, Kind, StepDescription, StepMetadata};
644644
use crate::core::config::TargetSelection;
645+
use crate::core::config::toml::rust::with_lld_opt_in_targets;
645646
use crate::utils::cache::Cache;
646647
use crate::utils::helpers::get_host_target;
647648
use crate::utils::tests::{ConfigBuilder, TestCtx};
@@ -1652,6 +1653,21 @@ mod snapshot {
16521653
");
16531654
}
16541655

1656+
#[test]
1657+
fn test_lld_opt_in() {
1658+
with_lld_opt_in_targets(vec![host_target()], || {
1659+
let ctx = TestCtx::new();
1660+
insta::assert_snapshot!(
1661+
ctx.config("build")
1662+
.path("compiler")
1663+
.render_steps(), @r"
1664+
[build] llvm <host>
1665+
[build] rustc 0 <host> -> rustc 1 <host>
1666+
[build] rustc 0 <host> -> LldWrapper 1 <host>
1667+
");
1668+
});
1669+
}
1670+
16551671
#[test]
16561672
fn doc_library_no_std_target() {
16571673
let ctx = TestCtx::new();

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ impl Config {
942942
config.rust_profile_use = flags_rust_profile_use;
943943
config.rust_profile_generate = flags_rust_profile_generate;
944944

945+
config.apply_target_config(toml.target);
945946
config.apply_rust_config(toml.rust, flags_warnings);
946947

947948
config.reproducible_artifacts = flags_reproducible_artifact;
@@ -967,8 +968,6 @@ impl Config {
967968

968969
config.apply_gcc_config(toml.gcc);
969970

970-
config.apply_target_config(toml.target);
971-
972971
match ccache {
973972
Some(StringOrBool::String(ref s)) => config.ccache = Some(s.to_string()),
974973
Some(StringOrBool::Bool(true)) => {

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,31 @@ pub(crate) fn validate_codegen_backends(backends: Vec<String>, section: &str) ->
410410
backends
411411
}
412412

413+
#[cfg(not(test))]
414+
fn default_lld_opt_in_targets() -> Vec<String> {
415+
vec!["x86_64-unknown-linux-gnu".to_string()]
416+
}
417+
418+
#[cfg(test)]
419+
thread_local! {
420+
static TEST_LLD_OPT_IN_TARGETS: std::cell::RefCell<Option<Vec<String>>> = std::cell::RefCell::new(None);
421+
}
422+
423+
#[cfg(test)]
424+
fn default_lld_opt_in_targets() -> Vec<String> {
425+
TEST_LLD_OPT_IN_TARGETS.with(|cell| cell.borrow().clone()).unwrap_or_default()
426+
}
427+
428+
#[cfg(test)]
429+
pub fn with_lld_opt_in_targets<R>(targets: Vec<String>, f: impl FnOnce() -> R) -> R {
430+
TEST_LLD_OPT_IN_TARGETS.with(|cell| {
431+
let prev = cell.replace(Some(targets));
432+
let result = f();
433+
cell.replace(prev);
434+
result
435+
})
436+
}
437+
413438
impl Config {
414439
pub fn apply_rust_config(&mut self, toml_rust: Option<Rust>, warnings: Warnings) {
415440
let mut debug = None;
@@ -617,12 +642,13 @@ impl Config {
617642
// thus, disabled
618643
// - similarly, lld will not be built nor used by default when explicitly asked not to, e.g.
619644
// when the config sets `rust.lld = false`
620-
if self.host_target.triple == "x86_64-unknown-linux-gnu" && self.hosts == [self.host_target]
645+
if default_lld_opt_in_targets().contains(&self.host_target.triple.to_string())
646+
&& self.hosts == [self.host_target]
621647
{
622648
let no_llvm_config = self
623649
.target_config
624650
.get(&self.host_target)
625-
.is_some_and(|target_config| target_config.llvm_config.is_none());
651+
.is_none_or(|target_config| target_config.llvm_config.is_none());
626652
let enable_lld = self.llvm_from_ci || no_llvm_config;
627653
// Prefer the config setting in case an explicit opt-out is needed.
628654
self.lld_enabled = lld_enabled.unwrap_or(enable_lld);

0 commit comments

Comments
 (0)