Skip to content

Commit 667d659

Browse files
committed
bootstrap: allow setting --jobs in config.toml
1 parent e92993d commit 667d659

File tree

5 files changed

+74
-3
lines changed

5 files changed

+74
-3
lines changed

config.example.toml

+5
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,11 @@
414414
# Specify the location of the Android NDK. Used when targeting Android.
415415
#android-ndk = "/path/to/android-ndk-r26d"
416416

417+
# Number of parallel jobs to be used for building and testing. If set to `0` or
418+
# omitted, it will be automatically determined. This is the `-j`/`--jobs` flag
419+
# passed to cargo invocations.
420+
#jobs = 0
421+
417422
# =============================================================================
418423
# General install configuration options
419424
# =============================================================================

src/bootstrap/src/core/config/config.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ define_config! {
891891
metrics: Option<bool> = "metrics",
892892
android_ndk: Option<PathBuf> = "android-ndk",
893893
optimized_compiler_builtins: Option<bool> = "optimized-compiler-builtins",
894+
jobs: Option<u32> = "jobs",
894895
}
895896
}
896897

@@ -1289,7 +1290,7 @@ impl Config {
12891290
config.rustc_error_format = flags.rustc_error_format;
12901291
config.json_output = flags.json_output;
12911292
config.on_fail = flags.on_fail;
1292-
config.jobs = Some(threads_from_config(flags.jobs as u32));
1293+
12931294
config.cmd = flags.cmd;
12941295
config.incremental = flags.incremental;
12951296
config.dry_run = if flags.dry_run { DryRun::UserSelected } else { DryRun::Disabled };
@@ -1511,8 +1512,11 @@ impl Config {
15111512
metrics: _,
15121513
android_ndk,
15131514
optimized_compiler_builtins,
1515+
jobs,
15141516
} = toml.build.unwrap_or_default();
15151517

1518+
config.jobs = Some(threads_from_config(flags.jobs.unwrap_or(jobs.unwrap_or(0))));
1519+
15161520
if let Some(file_build) = build {
15171521
config.build = TargetSelection::from_user(&file_build);
15181522
};

src/bootstrap/src/core/config/flags.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,10 @@ pub struct Flags {
110110
short,
111111
long,
112112
value_hint = clap::ValueHint::Other,
113-
default_value_t = std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get),
114113
value_name = "JOBS"
115114
)]
116115
/// number of jobs to run in parallel
117-
pub jobs: usize,
116+
pub jobs: Option<u32>,
118117
// This overrides the deny-warnings configuration option,
119118
// which passes -Dwarnings to the compiler invocations.
120119
#[arg(global = true, long)]

src/bootstrap/src/core/config/tests.rs

+58
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,61 @@ fn parse_rust_std_features_empty() {
352352
fn parse_rust_std_features_invalid() {
353353
parse("rust.std-features = \"backtrace\"");
354354
}
355+
356+
#[test]
357+
fn parse_jobs() {
358+
assert_eq!(parse("build.jobs = 1").jobs, Some(1));
359+
}
360+
361+
#[test]
362+
fn jobs_precedence() {
363+
// `--jobs` should take precedence over using `--set build.jobs`.
364+
365+
let config = Config::parse_inner(
366+
Flags::parse(&[
367+
"check".to_owned(),
368+
"--config=/does/not/exist".to_owned(),
369+
"--jobs=67890".to_owned(),
370+
"--set=build.jobs=12345".to_owned(),
371+
]),
372+
|&_| toml::from_str(""),
373+
);
374+
assert_eq!(config.jobs, Some(67890));
375+
376+
// `--set build.jobs` should take precedence over `config.toml`.
377+
let config = Config::parse_inner(
378+
Flags::parse(&[
379+
"check".to_owned(),
380+
"--config=/does/not/exist".to_owned(),
381+
"--set=build.jobs=12345".to_owned(),
382+
]),
383+
|&_| {
384+
toml::from_str(
385+
r#"
386+
[build]
387+
jobs = 67890
388+
"#,
389+
)
390+
},
391+
);
392+
assert_eq!(config.jobs, Some(12345));
393+
394+
// `--jobs` > `--set build.jobs` > `config.toml`
395+
let config = Config::parse_inner(
396+
Flags::parse(&[
397+
"check".to_owned(),
398+
"--jobs=123".to_owned(),
399+
"--config=/does/not/exist".to_owned(),
400+
"--set=build.jobs=456".to_owned(),
401+
]),
402+
|&_| {
403+
toml::from_str(
404+
r#"
405+
[build]
406+
jobs = 789
407+
"#,
408+
)
409+
},
410+
);
411+
assert_eq!(config.jobs, Some(123));
412+
}

src/bootstrap/src/utils/change_tracker.rs

+5
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
275275
severity: ChangeSeverity::Info,
276276
summary: "New option `./x setup editor` added, replacing `./x setup vscode` and adding support for vim, emacs and helix.",
277277
},
278+
ChangeInfo {
279+
change_id: 131838,
280+
severity: ChangeSeverity::Info,
281+
summary: "Allow setting `--jobs` in config.toml with `build.jobs`.",
282+
},
278283
];

0 commit comments

Comments
 (0)