Skip to content

Commit e2682dc

Browse files
authored
Unrolled build for #146155
Rollup merge of #146155 - Shourya742:2025-09-03-make-test-run-parallel, r=Kobzol Make bootstrap self test parallel This PR refactors the bootstrap self test: 1. Replaced the hardcoded --test-threads=1 with std::thread::available_parallelism(), allowing tests to run with the maximum concurrency supported by the system. 2. Replaced custom hacks around OUT_DIR with TempDir and introduced TestCtx to simplify configuration setup. r? `@Kobzol`
2 parents 9385c64 + 9f3fe40 commit e2682dc

File tree

3 files changed

+25
-45
lines changed

3 files changed

+25
-45
lines changed

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3294,9 +3294,7 @@ impl Step for Bootstrap {
32943294
.env("INSTA_WORKSPACE_ROOT", &builder.src)
32953295
.env("RUSTC_BOOTSTRAP", "1");
32963296

3297-
// bootstrap tests are racy on directory creation so just run them one at a time.
3298-
// Since there's not many this shouldn't be a problem.
3299-
run_cargo_test(cargo, &["--test-threads=1"], &[], None, host, builder);
3297+
run_cargo_test(cargo, &[], &[], None, host, builder);
33003298
}
33013299

33023300
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {

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

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::core::build_steps::doc::DocumentationFormat;
1010
use crate::core::config::Config;
1111
use crate::utils::cache::ExecutedStep;
1212
use crate::utils::helpers::get_host_target;
13-
use crate::utils::tests::ConfigBuilder;
1413
use crate::utils::tests::git::{GitCtx, git_test};
14+
use crate::utils::tests::{ConfigBuilder, TestCtx};
1515

1616
static TEST_TRIPLE_1: &str = "i686-unknown-haiku";
1717
static TEST_TRIPLE_2: &str = "i686-unknown-hurd-gnu";
@@ -22,38 +22,13 @@ fn configure(cmd: &str, host: &[&str], target: &[&str]) -> Config {
2222
}
2323

2424
fn configure_with_args(cmd: &[&str], host: &[&str], target: &[&str]) -> Config {
25-
let cmd = cmd.iter().copied().map(String::from).collect::<Vec<_>>();
26-
let mut config = Config::parse(Flags::parse(&cmd));
27-
// don't save toolstates
28-
config.save_toolstates = None;
29-
config.set_dry_run(DryRun::SelfCheck);
30-
31-
// Ignore most submodules, since we don't need them for a dry run, and the
32-
// tests run much faster without them.
33-
//
34-
// The src/doc/book submodule is needed because TheBook step tries to
35-
// access files even during a dry-run (may want to consider just skipping
36-
// that in a dry run).
37-
let submodule_build = Build::new(Config {
38-
// don't include LLVM, so CI doesn't require ninja/cmake to be installed
39-
rust_codegen_backends: vec![],
40-
..Config::parse(Flags::parse(&["check".to_owned()]))
41-
});
42-
submodule_build.require_submodule("src/doc/book", None);
43-
config.submodules = Some(false);
44-
45-
config.ninja_in_file = false;
46-
// try to avoid spurious failures in dist where we create/delete each others file
47-
// HACK: rather than pull in `tempdir`, use the one that cargo has conveniently created for us
48-
let dir = Path::new(env!("OUT_DIR"))
49-
.join("tmp-rustbuild-tests")
50-
.join(&thread::current().name().unwrap_or("unknown").replace(":", "-"));
51-
t!(fs::create_dir_all(&dir));
52-
config.out = dir;
53-
config.host_target = TargetSelection::from_user(TEST_TRIPLE_1);
54-
config.hosts = host.iter().map(|s| TargetSelection::from_user(s)).collect();
55-
config.targets = target.iter().map(|s| TargetSelection::from_user(s)).collect();
56-
config
25+
TestCtx::new()
26+
.config(cmd[0])
27+
.args(&cmd[1..])
28+
.hosts(host)
29+
.targets(target)
30+
.args(&["--build", TEST_TRIPLE_1])
31+
.create_config()
5732
}
5833

5934
fn first<A, B>(v: Vec<(A, B)>) -> Vec<A> {
@@ -547,8 +522,8 @@ mod snapshot {
547522

548523
use crate::core::build_steps::{compile, dist, doc, test, tool};
549524
use crate::core::builder::tests::{
550-
RenderConfig, TEST_TRIPLE_1, TEST_TRIPLE_2, TEST_TRIPLE_3, configure, configure_with_args,
551-
first, host_target, render_steps, run_build,
525+
RenderConfig, TEST_TRIPLE_1, TEST_TRIPLE_2, TEST_TRIPLE_3, configure, first, host_target,
526+
render_steps, run_build,
552527
};
553528
use crate::core::builder::{Builder, Kind, StepDescription, StepMetadata};
554529
use crate::core::config::TargetSelection;

src/bootstrap/src/utils/cc_detect/tests.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::{env, iter};
33

44
use super::*;
55
use crate::core::config::{Target, TargetSelection};
6-
use crate::{Build, Config, Flags};
6+
use crate::utils::tests::TestCtx;
7+
use crate::{Build, Config, Flags, t};
78

89
#[test]
910
fn test_ndk_compiler_c() {
@@ -68,7 +69,8 @@ fn test_language_clang() {
6869

6970
#[test]
7071
fn test_new_cc_build() {
71-
let build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
72+
let config = TestCtx::new().config("build").create_config();
73+
let build = Build::new(config);
7274
let target = TargetSelection::from_user("x86_64-unknown-linux-gnu");
7375
let cfg = new_cc_build(&build, target.clone());
7476
let compiler = cfg.get_compiler();
@@ -77,7 +79,8 @@ fn test_new_cc_build() {
7779

7880
#[test]
7981
fn test_default_compiler_wasi() {
80-
let mut build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
82+
let config = TestCtx::new().config("build").create_config();
83+
let mut build = Build::new(config);
8184
let target = TargetSelection::from_user("wasm32-wasi");
8285
let wasi_sdk = PathBuf::from("/wasi-sdk");
8386
build.wasi_sdk_path = Some(wasi_sdk.clone());
@@ -98,7 +101,8 @@ fn test_default_compiler_wasi() {
98101

99102
#[test]
100103
fn test_default_compiler_fallback() {
101-
let build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
104+
let config = TestCtx::new().config("build").create_config();
105+
let build = Build::new(config);
102106
let target = TargetSelection::from_user("x86_64-unknown-linux-gnu");
103107
let mut cfg = cc::Build::new();
104108
let result = default_compiler(&mut cfg, Language::C, target, &build);
@@ -107,7 +111,8 @@ fn test_default_compiler_fallback() {
107111

108112
#[test]
109113
fn test_find_target_with_config() {
110-
let mut build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
114+
let config = TestCtx::new().config("build").create_config();
115+
let mut build = Build::new(config);
111116
let target = TargetSelection::from_user("x86_64-unknown-linux-gnu");
112117
let mut target_config = Target::default();
113118
target_config.cc = Some(PathBuf::from("dummy-cc"));
@@ -128,7 +133,8 @@ fn test_find_target_with_config() {
128133

129134
#[test]
130135
fn test_find_target_without_config() {
131-
let mut build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
136+
let config = TestCtx::new().config("build").create_config();
137+
let mut build = Build::new(config);
132138
let target = TargetSelection::from_user("x86_64-unknown-linux-gnu");
133139
build.config.target_config.clear();
134140
fill_target_compiler(&mut build, target.clone());
@@ -141,7 +147,8 @@ fn test_find_target_without_config() {
141147

142148
#[test]
143149
fn test_find() {
144-
let mut build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
150+
let config = TestCtx::new().config("build").create_config();
151+
let mut build = Build::new(config);
145152
let target1 = TargetSelection::from_user("x86_64-unknown-linux-gnu");
146153
let target2 = TargetSelection::from_user("x86_64-unknown-openbsd");
147154
build.targets.push(target1.clone());

0 commit comments

Comments
 (0)