Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/directives/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
10 changes: 9 additions & 1 deletion src/tools/compiletest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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,
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/tools/compiletest/src/runtest/run_make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/rustdoc_gui_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
14 changes: 14 additions & 0 deletions src/tools/run-make-support/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`")
}
5 changes: 5 additions & 0 deletions tests/run-make/compiletest-self-test/jobs/rmake.rs
Original file line number Diff line number Diff line change
@@ -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());
}
Loading