Skip to content

Commit

Permalink
bootstrap: allow setting --jobs in config.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
jieyouxu committed Oct 17, 2024
1 parent 03983fb commit 6a6d20f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@
# Specify the location of the Android NDK. Used when targeting Android.
#android-ndk = "/path/to/android-ndk-r26d"

# Number of parallel jobs to be used for building and testing. If set to `0` or
# omitted, it will be automatically determined.
#jobs = 0

# =============================================================================
# General install configuration options
# =============================================================================
Expand Down
8 changes: 8 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@ define_config! {
metrics: Option<bool> = "metrics",
android_ndk: Option<PathBuf> = "android-ndk",
optimized_compiler_builtins: Option<bool> = "optimized-compiler-builtins",
jobs: Option<u32> = "jobs",
}
}

Expand Down Expand Up @@ -1511,6 +1512,7 @@ impl Config {
metrics: _,
android_ndk,
optimized_compiler_builtins,
jobs,
} = toml.build.unwrap_or_default();

if let Some(file_build) = build {
Expand Down Expand Up @@ -1621,6 +1623,12 @@ impl Config {
// Verbose flag is a good default for `rust.verbose-tests`.
config.verbose_tests = config.is_verbose();

if let Some(jobs) = jobs {
if jobs > 0 {
config.jobs = Some(jobs);
}
}

if let Some(install) = toml.install {
let Install { prefix, sysconfdir, docdir, bindir, libdir, mandir, datadir } = install;
config.prefix = prefix.map(PathBuf::from);
Expand Down
9 changes: 9 additions & 0 deletions src/bootstrap/src/core/config/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ fn override_toml() {
"--set=rust.deny-warnings=false".to_owned(),
"--set=build.gdb=\"bar\"".to_owned(),
"--set=build.tools=[\"cargo\"]".to_owned(),
"--set=build.jobs=1".to_owned(),
"--set=llvm.build-config={\"foo\" = \"bar\"}".to_owned(),
"--set=target.x86_64-unknown-linux-gnu.runner=bar".to_owned(),
"--set=target.x86_64-unknown-linux-gnu.rpath=false".to_owned(),
Expand All @@ -139,6 +140,7 @@ deny-warnings = true
[build]
gdb = "foo"
tools = []
jobs = 2
[llvm]
download-ci-llvm = false
Expand Down Expand Up @@ -171,6 +173,7 @@ runner = "x86_64-runner"
Some(["cargo".to_string()].into_iter().collect()),
"setting list value"
);
assert_eq!(config.jobs, Some(1));
assert_eq!(
config.llvm_build_config,
[("foo".to_string(), "bar".to_string())].into_iter().collect(),
Expand Down Expand Up @@ -352,3 +355,9 @@ fn parse_rust_std_features_empty() {
fn parse_rust_std_features_invalid() {
parse("rust.std-features = \"backtrace\"");
}

#[test]
fn parse_jobs_zero() {
assert_eq!(parse("build.jobs = 0").jobs, None);
assert_eq!(parse("build.jobs = 1").jobs, Some(1));
}
5 changes: 5 additions & 0 deletions src/bootstrap/src/utils/change_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Info,
summary: "New option `./x setup editor` added, replacing `./x setup vscode` and adding support for vim, emacs and helix.",
},
ChangeInfo {
change_id: 131838,
severity: ChangeSeverity::Info,
summary: "Allow setting `--jobs` in config.toml with `build.jobs`.",
},
];

0 comments on commit 6a6d20f

Please sign in to comment.