Skip to content

Commit dd948f9

Browse files
committed
Thread --jobs from bootstrap -> compiletest -> run-make-support
1 parent 4fa80a5 commit dd948f9

File tree

8 files changed

+40
-1
lines changed

8 files changed

+40
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,8 @@ Please disable assertions with `rust.debug-assertions = false`.
22652265
cmd.arg("--with-std-remap-debuginfo");
22662266
}
22672267

2268+
cmd.arg("--jobs").arg(builder.jobs().to_string());
2269+
22682270
let mut llvm_components_passed = false;
22692271
let mut copts_passed = false;
22702272
if builder.config.llvm_enabled(test_compiler.host) {

src/tools/compiletest/src/common.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,11 @@ pub struct Config {
715715
pub override_codegen_backend: Option<String>,
716716
/// Whether to ignore `//@ ignore-backends`.
717717
pub bypass_ignore_backends: bool,
718+
719+
/// Number of parallel jobs configured for the build.
720+
///
721+
/// This is forwarded from bootstrap's `jobs` configuration.
722+
pub jobs: u32,
718723
}
719724

720725
impl Config {

src/tools/compiletest/src/directives/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ impl ConfigBuilder {
225225
"--nightly-branch=",
226226
"--git-merge-commit-email=",
227227
"--minicore-path=",
228+
"--jobs=0",
228229
];
229230
let mut args: Vec<String> = args.iter().map(ToString::to_string).collect();
230231

src/tools/compiletest/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ fn parse_config(args: Vec<String>) -> Config {
218218
"the codegen backend to use instead of the default one",
219219
"CODEGEN BACKEND [NAME | PATH]",
220220
)
221-
.optflag("", "bypass-ignore-backends", "ignore `//@ ignore-backends` directives");
221+
.optflag("", "bypass-ignore-backends", "ignore `//@ ignore-backends` directives")
222+
.reqopt("", "jobs", "number of parallel jobs bootstrap was configured with", "JOBS");
222223

223224
let (argv0, args_) = args.split_first().unwrap();
224225
if args.len() == 1 || args[1] == "-h" || args[1] == "--help" {
@@ -363,6 +364,11 @@ fn parse_config(args: Vec<String>) -> Config {
363364
let build_test_suite_root = opt_path(matches, "build-test-suite-root");
364365
assert!(build_test_suite_root.starts_with(&build_root));
365366

367+
let jobs = match matches.opt_str("jobs") {
368+
Some(jobs) => jobs.parse::<u32>().expect("expected `--jobs` to be an `u32`"),
369+
None => panic!("`--jobs` is required"),
370+
};
371+
366372
Config {
367373
bless: matches.opt_present("bless"),
368374
fail_fast: matches.opt_present("fail-fast")
@@ -481,6 +487,8 @@ fn parse_config(args: Vec<String>) -> Config {
481487
default_codegen_backend,
482488
override_codegen_backend,
483489
bypass_ignore_backends: matches.opt_present("bypass-ignore-backends"),
490+
491+
jobs,
484492
}
485493
}
486494

src/tools/compiletest/src/runtest/run_make.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ impl TestCx<'_> {
249249
cmd.env("__STD_REMAP_DEBUGINFO_ENABLED", "1");
250250
}
251251

252+
// Used for `run_make_support::env::jobs`.
253+
cmd.env("__BOOTSTRAP_JOBS", self.config.jobs.to_string());
254+
252255
// We don't want RUSTFLAGS set from the outside to interfere with
253256
// compiler flags set in the test cases:
254257
cmd.env_remove("RUSTFLAGS");

src/tools/compiletest/src/rustdoc_gui_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,6 @@ fn incomplete_config_for_rustdoc_gui_test() -> Config {
139139
default_codegen_backend: CodegenBackend::Llvm,
140140
override_codegen_backend: None,
141141
bypass_ignore_backends: Default::default(),
142+
jobs: Default::default(),
142143
}
143144
}

src/tools/run-make-support/src/env.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,17 @@ pub fn set_current_dir<P: AsRef<std::path::Path>>(dir: P) {
4949
std::env::set_current_dir(dir.as_ref())
5050
.expect(&format!("could not set current directory to \"{}\"", dir.as_ref().display()));
5151
}
52+
53+
/// Number of parallel jobs bootstrap was configured with.
54+
///
55+
/// This may fallback to [`std::thread::available_parallelism`] when no explicit jobs count has been
56+
/// configured. Refer to bootstrap's jobs fallback logic.
57+
#[track_caller]
58+
pub fn jobs() -> u32 {
59+
std::env::var_os("__BOOTSTRAP_JOBS")
60+
.expect("`__BOOTSTRAP_JOBS` must be set by `compiletest`")
61+
.to_str()
62+
.expect("`__BOOTSTRAP_JOBS` must be a valid string")
63+
.parse::<u32>()
64+
.expect("`__BOOTSTRAP_JOBS` must be a valid `u32`")
65+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//! Very basic smoke test to make sure `run_make_support::env::jobs` at least does not panic.
2+
3+
fn main() {
4+
println!("{}", run_make_support::env::jobs());
5+
}

0 commit comments

Comments
 (0)