Skip to content

Commit 165b9c0

Browse files
committed
Auto merge of #9584 - henrifrancois:master, r=Eh2406
Handle "jobs = 0" case in cargo config files Cargo hangs without output if the jobs argument under build in a cargo/config file is set to 0. This PR handles this case by providing an appropriate error. Closes #9219
2 parents 3b17193 + 39572e2 commit 165b9c0

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/cargo/core/compiler/build_config.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ impl BuildConfig {
6868
its environment, ignoring the `-j` parameter",
6969
)?;
7070
}
71-
let jobs = jobs.or(cfg.jobs).unwrap_or(::num_cpus::get() as u32);
71+
let jobs = match jobs.or(cfg.jobs) {
72+
None => ::num_cpus::get() as u32,
73+
Some(j) if j != 0 => (::num_cpus::get() as u32).max(j),
74+
Some(_) => anyhow::bail!("jobs may not be 0"),
75+
};
7276

7377
Ok(BuildConfig {
7478
requested_kinds,

tests/testsuite/build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4802,6 +4802,24 @@ fn good_cargo_config_jobs() {
48024802
p.cargo("build -v").run();
48034803
}
48044804

4805+
#[cargo_test]
4806+
fn invalid_cargo_config_jobs() {
4807+
let p = project()
4808+
.file("src/lib.rs", "")
4809+
.file(
4810+
".cargo/config",
4811+
r#"
4812+
[build]
4813+
jobs = 0
4814+
"#,
4815+
)
4816+
.build();
4817+
p.cargo("build -v")
4818+
.with_status(101)
4819+
.with_stderr_contains("error: jobs may not be 0")
4820+
.run();
4821+
}
4822+
48054823
#[cargo_test]
48064824
fn invalid_jobs() {
48074825
let p = project()

0 commit comments

Comments
 (0)