Skip to content

Commit 40c6ae8

Browse files
committed
add test for lld opt in and also add thread_local defined state to change opt in targets
1 parent 07ac02a commit 40c6ae8

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

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

Lines changed: 23 additions & 1 deletion
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};
@@ -1631,7 +1632,6 @@ mod snapshot {
16311632
#[test]
16321633
fn doc_core_no_std_target() {
16331634
let ctx = TestCtx::new();
1634-
16351635
insta::assert_snapshot!(
16361636
ctx.config("doc")
16371637
.path("core")
@@ -1644,6 +1644,28 @@ mod snapshot {
16441644
");
16451645
}
16461646

1647+
#[test]
1648+
fn test_lld_opt_in() {
1649+
let target: &'static str = Box::leak(Box::new(host_target()));
1650+
let slice: &'static [&'static str] = Box::leak(Box::new([target]));
1651+
1652+
with_lld_opt_in_targets(slice, || {
1653+
let ctx = TestCtx::new();
1654+
1655+
insta::assert_snapshot!(
1656+
ctx.config("doc")
1657+
.path("core")
1658+
.override_target_no_std(&host_target())
1659+
.render_steps(), @r"
1660+
[build] llvm <host>
1661+
[build] rustc 0 <host> -> rustc 1 <host>
1662+
[build] rustc 0 <host> -> LldWrapper 1 <host>
1663+
[build] rustdoc 0 <host>
1664+
[doc] std 1 <host> crates=[core]
1665+
");
1666+
});
1667+
}
1668+
16471669
#[test]
16481670
fn doc_library_no_std_target() {
16491671
let ctx = TestCtx::new();

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,25 @@ pub(crate) fn validate_codegen_backends(backends: Vec<String>, section: &str) ->
413413
fn default_lld_opt_in_targets() -> &'static [&'static str] {
414414
&["x86_64-unknown-linux-gnu"]
415415
}
416+
417+
#[cfg(test)]
418+
thread_local! {
419+
static TEST_LLD_OPT_IN_TARGETS: std::cell::RefCell<Option<&'static [&'static str]>> = std::cell::RefCell::new(None);
420+
}
421+
416422
#[cfg(test)]
417423
fn default_lld_opt_in_targets() -> &'static [&'static str] {
418-
&[]
424+
TEST_LLD_OPT_IN_TARGETS.with(|cell| cell.borrow().unwrap_or(&[]))
425+
}
426+
427+
#[cfg(test)]
428+
pub fn with_lld_opt_in_targets<R>(targets: &'static [&'static str], f: impl FnOnce() -> R) -> R {
429+
TEST_LLD_OPT_IN_TARGETS.with(|cell| {
430+
let prev = cell.replace(Some(targets));
431+
let result = f();
432+
cell.replace(prev);
433+
result
434+
})
419435
}
420436

421437
impl Config {

0 commit comments

Comments
 (0)