Thread --jobs from bootstrap -> compiletest -> run-make-support

This commit is contained in:
Jieyou Xu 2026-01-06 09:42:42 +08:00
parent 4fa80a5e73
commit dd948f96f3
No known key found for this signature in database
GPG key ID: 36D068BDB127FD95
8 changed files with 40 additions and 1 deletions

View file

@ -2265,6 +2265,8 @@ Please disable assertions with `rust.debug-assertions = false`.
cmd.arg("--with-std-remap-debuginfo");
}
cmd.arg("--jobs").arg(builder.jobs().to_string());
let mut llvm_components_passed = false;
let mut copts_passed = false;
if builder.config.llvm_enabled(test_compiler.host) {

View file

@ -715,6 +715,11 @@ pub struct Config {
pub override_codegen_backend: Option<String>,
/// Whether to ignore `//@ ignore-backends`.
pub bypass_ignore_backends: bool,
/// Number of parallel jobs configured for the build.
///
/// This is forwarded from bootstrap's `jobs` configuration.
pub jobs: u32,
}
impl Config {

View file

@ -225,6 +225,7 @@ impl ConfigBuilder {
"--nightly-branch=",
"--git-merge-commit-email=",
"--minicore-path=",
"--jobs=0",
];
let mut args: Vec<String> = args.iter().map(ToString::to_string).collect();

View file

@ -218,7 +218,8 @@ fn parse_config(args: Vec<String>) -> Config {
"the codegen backend to use instead of the default one",
"CODEGEN BACKEND [NAME | PATH]",
)
.optflag("", "bypass-ignore-backends", "ignore `//@ ignore-backends` directives");
.optflag("", "bypass-ignore-backends", "ignore `//@ ignore-backends` directives")
.reqopt("", "jobs", "number of parallel jobs bootstrap was configured with", "JOBS");
let (argv0, args_) = args.split_first().unwrap();
if args.len() == 1 || args[1] == "-h" || args[1] == "--help" {
@ -363,6 +364,11 @@ fn parse_config(args: Vec<String>) -> Config {
let build_test_suite_root = opt_path(matches, "build-test-suite-root");
assert!(build_test_suite_root.starts_with(&build_root));
let jobs = match matches.opt_str("jobs") {
Some(jobs) => jobs.parse::<u32>().expect("expected `--jobs` to be an `u32`"),
None => panic!("`--jobs` is required"),
};
Config {
bless: matches.opt_present("bless"),
fail_fast: matches.opt_present("fail-fast")
@ -481,6 +487,8 @@ fn parse_config(args: Vec<String>) -> Config {
default_codegen_backend,
override_codegen_backend,
bypass_ignore_backends: matches.opt_present("bypass-ignore-backends"),
jobs,
}
}

View file

@ -249,6 +249,9 @@ impl TestCx<'_> {
cmd.env("__STD_REMAP_DEBUGINFO_ENABLED", "1");
}
// Used for `run_make_support::env::jobs`.
cmd.env("__BOOTSTRAP_JOBS", self.config.jobs.to_string());
// We don't want RUSTFLAGS set from the outside to interfere with
// compiler flags set in the test cases:
cmd.env_remove("RUSTFLAGS");

View file

@ -139,5 +139,6 @@ fn incomplete_config_for_rustdoc_gui_test() -> Config {
default_codegen_backend: CodegenBackend::Llvm,
override_codegen_backend: None,
bypass_ignore_backends: Default::default(),
jobs: Default::default(),
}
}

View file

@ -49,3 +49,17 @@ pub fn set_current_dir<P: AsRef<std::path::Path>>(dir: P) {
std::env::set_current_dir(dir.as_ref())
.expect(&format!("could not set current directory to \"{}\"", dir.as_ref().display()));
}
/// Number of parallel jobs bootstrap was configured with.
///
/// This may fallback to [`std::thread::available_parallelism`] when no explicit jobs count has been
/// configured. Refer to bootstrap's jobs fallback logic.
#[track_caller]
pub fn jobs() -> u32 {
std::env::var_os("__BOOTSTRAP_JOBS")
.expect("`__BOOTSTRAP_JOBS` must be set by `compiletest`")
.to_str()
.expect("`__BOOTSTRAP_JOBS` must be a valid string")
.parse::<u32>()
.expect("`__BOOTSTRAP_JOBS` must be a valid `u32`")
}

View file

@ -0,0 +1,5 @@
//! Very basic smoke test to make sure `run_make_support::env::jobs` at least does not panic.
fn main() {
println!("{}", run_make_support::env::jobs());
}