Skip to content

Commit

Permalink
Auto merge of #9584 - henrifrancois:master, r=ehuss
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 17, 2021
2 parents 40df0f1 + 0663b71 commit d95b29b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ impl BuildConfig {
)?;
}
let jobs = jobs.or(cfg.jobs).unwrap_or(::num_cpus::get() as u32);
if jobs == 0 {
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 d95b29b

Please sign in to comment.