Skip to content

Commit

Permalink
Auto merge of #9584 - henrifrancois:master, r=Eh2406
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jun 14, 2021
2 parents 3b17193 + 39572e2 commit 165b9c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ impl BuildConfig {
its environment, ignoring the `-j` parameter",
)?;
}
let jobs = jobs.or(cfg.jobs).unwrap_or(::num_cpus::get() as u32);
let jobs = match jobs.or(cfg.jobs) {
None => ::num_cpus::get() as u32,
Some(j) if j != 0 => (::num_cpus::get() as u32).max(j),
Some(_) => anyhow::bail!("jobs may not be 0"),
};

Ok(BuildConfig {
requested_kinds,
Expand Down
18 changes: 18 additions & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4802,6 +4802,24 @@ fn good_cargo_config_jobs() {
p.cargo("build -v").run();
}

#[cargo_test]
fn invalid_cargo_config_jobs() {
let p = project()
.file("src/lib.rs", "")
.file(
".cargo/config",
r#"
[build]
jobs = 0
"#,
)
.build();
p.cargo("build -v")
.with_status(101)
.with_stderr_contains("error: jobs may not be 0")
.run();
}

#[cargo_test]
fn invalid_jobs() {
let p = project()
Expand Down

0 comments on commit 165b9c0

Please sign in to comment.