From 90574f08f8b88ed0f77b6a76f89502c368ab4efa Mon Sep 17 00:00:00 2001 From: Henri Francois Date: Mon, 14 Jun 2021 11:22:22 -0400 Subject: [PATCH 1/2] Handling job=0 argument in cargo config files. --- src/cargo/core/compiler/build_config.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/compiler/build_config.rs b/src/cargo/core/compiler/build_config.rs index 4b488261ccf..366fe5e1af8 100644 --- a/src/cargo/core/compiler/build_config.rs +++ b/src/cargo/core/compiler/build_config.rs @@ -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, From 39572e25dc697a92ae28a3189a2f605981ddc32e Mon Sep 17 00:00:00 2001 From: Henri Francois Date: Mon, 14 Jun 2021 12:51:28 -0400 Subject: [PATCH 2/2] Added test for case when cargo config file has jobs argument set to 0 --- tests/testsuite/build.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 5b2f3786bd5..549c5850b1b 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -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()