From 07cc897a4ffd0743f26c43a210089dedfc27fac2 Mon Sep 17 00:00:00 2001 From: Orson Peters Date: Mon, 1 Mar 2021 17:05:22 +0100 Subject: [PATCH 1/7] Added support for negative --jobs parameter, counting backwards from max CPUs. --- src/cargo/core/compiler/build_config.rs | 10 +++++++--- src/cargo/core/compiler/context/mod.rs | 6 +++--- src/cargo/core/compiler/timings.rs | 2 +- src/cargo/ops/cargo_package.rs | 2 +- src/cargo/ops/registry.rs | 2 +- src/cargo/util/command_prelude.rs | 17 +++++++++++++--- src/cargo/util/config/mod.rs | 2 +- tests/testsuite/bad_config.rs | 26 ------------------------- tests/testsuite/build.rs | 20 ++++++++++++++----- 9 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/cargo/core/compiler/build_config.rs b/src/cargo/core/compiler/build_config.rs index d0f5431a47e..d2c7398a08c 100644 --- a/src/cargo/core/compiler/build_config.rs +++ b/src/cargo/core/compiler/build_config.rs @@ -50,14 +50,14 @@ impl BuildConfig { /// * `target.$target.libfoo.metadata` pub fn new( config: &Config, - jobs: Option, + jobs: Option, requested_targets: &[String], mode: CompileMode, ) -> CargoResult { let cfg = config.build_config()?; let requested_kinds = CompileKind::from_requested_targets(config, requested_targets)?; if jobs == Some(0) { - anyhow::bail!("jobs must be at least 1") + anyhow::bail!("jobs must not be zero") } if jobs.is_some() && config.jobserver_from_env().is_some() { config.shell().warn( @@ -66,7 +66,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 i32 + j).max(1) as u32, + Some(j) => j as u32, + }; Ok(BuildConfig { requested_kinds, diff --git a/src/cargo/core/compiler/context/mod.rs b/src/cargo/core/compiler/context/mod.rs index cb1dbb6240b..dfb4ccf8e91 100644 --- a/src/cargo/core/compiler/context/mod.rs +++ b/src/cargo/core/compiler/context/mod.rs @@ -95,8 +95,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> { let jobserver = match bcx.config.jobserver_from_env() { Some(c) => c.clone(), None => { - let client = Client::new(bcx.build_config.jobs as usize) - .chain_err(|| "failed to create jobserver")?; + let client = + Client::new(bcx.jobs() as usize).chain_err(|| "failed to create jobserver")?; client.acquire_raw()?; client } @@ -558,7 +558,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { } pub fn new_jobserver(&mut self) -> CargoResult { - let tokens = self.bcx.build_config.jobs as usize; + let tokens = self.bcx.jobs() as usize; let client = Client::new(tokens).chain_err(|| "failed to create jobserver")?; // Drain the client fully diff --git a/src/cargo/core/compiler/timings.rs b/src/cargo/core/compiler/timings.rs index a206023a99e..4891526f20d 100644 --- a/src/cargo/core/compiler/timings.rs +++ b/src/cargo/core/compiler/timings.rs @@ -461,7 +461,7 @@ impl<'cfg> Timings<'cfg> { self.total_dirty, self.total_fresh + self.total_dirty, max_concurrency, - bcx.build_config.jobs, + bcx.jobs(), num_cpus::get(), self.start_str, total_time, diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index a07f9fe072d..8aadc6ec214 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -27,7 +27,7 @@ pub struct PackageOpts<'cfg> { pub check_metadata: bool, pub allow_dirty: bool, pub verify: bool, - pub jobs: Option, + pub jobs: Option, pub targets: Vec, pub features: Vec, pub all_features: bool, diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 7032ae13090..68e5479dc60 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -47,7 +47,7 @@ pub struct PublishOpts<'cfg> { pub index: Option, pub verify: bool, pub allow_dirty: bool, - pub jobs: Option, + pub jobs: Option, pub targets: Vec, pub dry_run: bool, pub registry: Option, diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 3d7268caac5..c72743aa4a0 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -67,7 +67,8 @@ pub trait AppExt: Sized { self._arg( opt("jobs", "Number of parallel jobs, defaults to # of CPUs") .short("j") - .value_name("N"), + .value_name("N") + .allow_hyphen_values(true), ) } @@ -287,6 +288,16 @@ pub trait ArgMatchesExt { Ok(arg) } + fn value_of_i32(&self, name: &str) -> CargoResult> { + let arg = match self._value_of(name) { + None => None, + Some(arg) => Some(arg.parse::().map_err(|_| { + clap::Error::value_validation_auto(format!("could not parse `{}` as a number", arg)) + })?), + }; + Ok(arg) + } + /// Returns value of the `name` command-line argument as an absolute path fn value_of_path(&self, name: &str, config: &Config) -> Option { self._value_of(name).map(|path| config.cwd().join(path)) @@ -320,8 +331,8 @@ pub trait ArgMatchesExt { Ok(ws) } - fn jobs(&self) -> CargoResult> { - self.value_of_u32("jobs") + fn jobs(&self) -> CargoResult> { + self.value_of_i32("jobs") } fn targets(&self) -> Vec { diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs index ecf21d1e810..73e4bc857d3 100644 --- a/src/cargo/util/config/mod.rs +++ b/src/cargo/util/config/mod.rs @@ -1874,7 +1874,7 @@ pub struct CargoBuildConfig { pub target_dir: Option, pub incremental: Option, pub target: Option, - pub jobs: Option, + pub jobs: Option, pub rustflags: Option, pub rustdocflags: Option, pub rustc_wrapper: Option, diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index e7a6b01c0e5..a8101d63909 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -138,32 +138,6 @@ Caused by: .run(); } -#[cargo_test] -fn bad_cargo_config_jobs() { - let p = project() - .file("src/lib.rs", "") - .file( - ".cargo/config", - r#" - [build] - jobs = -1 - "#, - ) - .build(); - p.cargo("build -v") - .with_status(101) - .with_stderr( - "\ -[ERROR] error in [..].cargo/config: \ -could not load config key `build.jobs` - -Caused by: - invalid value: integer `-1`, expected u32 -", - ) - .run(); -} - #[cargo_test] fn invalid_global_config() { let p = project() diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 35feb0fcdd6..9f9e25dad08 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -4719,6 +4719,18 @@ fn good_cargo_config_jobs() { p.cargo("build -v").run(); } +#[cargo_test] +fn good_jobs() { + let p = project() + .file("Cargo.toml", &basic_bin_manifest("foo")) + .file("src/foo.rs", &main_file(r#""i am foo""#, &[])) + .build(); + + p.cargo("build --jobs 1").run(); + + p.cargo("build --jobs -1").run(); +} + #[cargo_test] fn invalid_jobs() { let p = project() @@ -4726,11 +4738,9 @@ fn invalid_jobs() { .file("src/foo.rs", &main_file(r#""i am foo""#, &[])) .build(); - p.cargo("build --jobs -1") - .with_status(1) - .with_stderr_contains( - "error: Found argument '-1' which wasn't expected, or isn't valid in this context", - ) + p.cargo("build --jobs 0") + .with_status(101) + .with_stderr_contains("error: jobs must not be zero") .run(); p.cargo("build --jobs over9000") From e6516053f2e1f4ca62ad9830f25425a8f191dcca Mon Sep 17 00:00:00 2001 From: Yerkebulan Tulibergenov Date: Sun, 10 Jul 2022 14:52:05 -0700 Subject: [PATCH 2/7] fix value_of_i32 --- src/cargo/util/command_prelude.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index aa0dca80b5f..5d197b9f117 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -331,7 +331,10 @@ pub trait ArgMatchesExt { let arg = match self._value_of(name) { None => None, Some(arg) => Some(arg.parse::().map_err(|_| { - clap::Error::value_validation_auto(format!("could not parse `{}` as a number", arg)) + clap::Error::raw( + clap::ErrorKind::ValueValidation, + format!("Invalid value: could not parse `{}` as a number", arg), + ) })?), }; Ok(arg) From e9fb8499ec9fffb642f58ed6ca65305432762e36 Mon Sep 17 00:00:00 2001 From: Yerkebulan Tulibergenov Date: Sun, 10 Jul 2022 16:02:31 -0700 Subject: [PATCH 3/7] update config.md --- src/doc/src/reference/config.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/doc/src/reference/config.md b/src/doc/src/reference/config.md index f4749457e7a..552a0b5b820 100644 --- a/src/doc/src/reference/config.md +++ b/src/doc/src/reference/config.md @@ -344,7 +344,9 @@ The `[build]` table controls build-time operations and compiler settings. * Default: number of logical CPUs * Environment: `CARGO_BUILD_JOBS` -Sets the maximum number of compiler processes to run in parallel. +Sets the maximum number of compiler processes to run in parallel. If negative, +it sets the maximum number of compiler processes to the number of logical CPUs +plus provided value. Should not be 0. Can be overridden with the `--jobs` CLI option. From 5b76fb3d2b0b3e71c5b4d190f0b3bb6f1305045c Mon Sep 17 00:00:00 2001 From: Yerkebulan Tulibergenov Date: Sun, 10 Jul 2022 16:06:25 -0700 Subject: [PATCH 4/7] update man pages --- src/doc/man/generated_txt/cargo-bench.txt | 4 +++- src/doc/man/generated_txt/cargo-build.txt | 4 +++- src/doc/man/generated_txt/cargo-check.txt | 4 +++- src/doc/man/generated_txt/cargo-doc.txt | 4 +++- src/doc/man/generated_txt/cargo-fix.txt | 4 +++- src/doc/man/generated_txt/cargo-install.txt | 4 +++- src/doc/man/generated_txt/cargo-package.txt | 4 +++- src/doc/man/generated_txt/cargo-publish.txt | 4 +++- src/doc/man/generated_txt/cargo-run.txt | 4 +++- src/doc/man/generated_txt/cargo-rustc.txt | 4 +++- src/doc/man/generated_txt/cargo-rustdoc.txt | 4 +++- src/doc/man/generated_txt/cargo-test.txt | 4 +++- src/doc/man/includes/options-jobs.md | 4 +++- src/doc/src/commands/cargo-bench.md | 4 +++- src/doc/src/commands/cargo-build.md | 4 +++- src/doc/src/commands/cargo-check.md | 4 +++- src/doc/src/commands/cargo-doc.md | 4 +++- src/doc/src/commands/cargo-fix.md | 4 +++- src/doc/src/commands/cargo-install.md | 4 +++- src/doc/src/commands/cargo-package.md | 4 +++- src/doc/src/commands/cargo-publish.md | 4 +++- src/doc/src/commands/cargo-run.md | 4 +++- src/doc/src/commands/cargo-rustc.md | 4 +++- src/doc/src/commands/cargo-rustdoc.md | 4 +++- src/doc/src/commands/cargo-test.md | 4 +++- src/etc/man/cargo-bench.1 | 4 +++- src/etc/man/cargo-build.1 | 4 +++- src/etc/man/cargo-check.1 | 4 +++- src/etc/man/cargo-doc.1 | 4 +++- src/etc/man/cargo-fix.1 | 4 +++- src/etc/man/cargo-install.1 | 4 +++- src/etc/man/cargo-package.1 | 4 +++- src/etc/man/cargo-publish.1 | 4 +++- src/etc/man/cargo-run.1 | 4 +++- src/etc/man/cargo-rustc.1 | 4 +++- src/etc/man/cargo-rustdoc.1 | 4 +++- src/etc/man/cargo-test.1 | 4 +++- 37 files changed, 111 insertions(+), 37 deletions(-) diff --git a/src/doc/man/generated_txt/cargo-bench.txt b/src/doc/man/generated_txt/cargo-bench.txt index 01afc593cac..0203c082951 100644 --- a/src/doc/man/generated_txt/cargo-bench.txt +++ b/src/doc/man/generated_txt/cargo-bench.txt @@ -372,7 +372,9 @@ OPTIONS Number of parallel jobs to run. May also be specified with the build.jobs config value . Defaults to - the number of CPUs. + the number of logical CPUs. If negative, it sets the maximum number + of parallel jobs to the number of logical CPUs plus provided value. + Should not be 0. --keep-going Build as many crates in the dependency graph as possible, rather diff --git a/src/doc/man/generated_txt/cargo-build.txt b/src/doc/man/generated_txt/cargo-build.txt index 17802b7fe6d..2fafce309fe 100644 --- a/src/doc/man/generated_txt/cargo-build.txt +++ b/src/doc/man/generated_txt/cargo-build.txt @@ -317,7 +317,9 @@ OPTIONS Number of parallel jobs to run. May also be specified with the build.jobs config value . Defaults to - the number of CPUs. + the number of logical CPUs. If negative, it sets the maximum number + of parallel jobs to the number of logical CPUs plus provided value. + Should not be 0. --keep-going Build as many crates in the dependency graph as possible, rather diff --git a/src/doc/man/generated_txt/cargo-check.txt b/src/doc/man/generated_txt/cargo-check.txt index 2efb2edc87e..dee68368845 100644 --- a/src/doc/man/generated_txt/cargo-check.txt +++ b/src/doc/man/generated_txt/cargo-check.txt @@ -302,7 +302,9 @@ OPTIONS Number of parallel jobs to run. May also be specified with the build.jobs config value . Defaults to - the number of CPUs. + the number of logical CPUs. If negative, it sets the maximum number + of parallel jobs to the number of logical CPUs plus provided value. + Should not be 0. --keep-going Build as many crates in the dependency graph as possible, rather diff --git a/src/doc/man/generated_txt/cargo-doc.txt b/src/doc/man/generated_txt/cargo-doc.txt index b57035384c1..b127c7d88f3 100644 --- a/src/doc/man/generated_txt/cargo-doc.txt +++ b/src/doc/man/generated_txt/cargo-doc.txt @@ -273,7 +273,9 @@ OPTIONS Number of parallel jobs to run. May also be specified with the build.jobs config value . Defaults to - the number of CPUs. + the number of logical CPUs. If negative, it sets the maximum number + of parallel jobs to the number of logical CPUs plus provided value. + Should not be 0. --keep-going Build as many crates in the dependency graph as possible, rather diff --git a/src/doc/man/generated_txt/cargo-fix.txt b/src/doc/man/generated_txt/cargo-fix.txt index c5520bb6e34..5688ff8b9d0 100644 --- a/src/doc/man/generated_txt/cargo-fix.txt +++ b/src/doc/man/generated_txt/cargo-fix.txt @@ -375,7 +375,9 @@ OPTIONS Number of parallel jobs to run. May also be specified with the build.jobs config value . Defaults to - the number of CPUs. + the number of logical CPUs. If negative, it sets the maximum number + of parallel jobs to the number of logical CPUs plus provided value. + Should not be 0. --keep-going Build as many crates in the dependency graph as possible, rather diff --git a/src/doc/man/generated_txt/cargo-install.txt b/src/doc/man/generated_txt/cargo-install.txt index f835b6f0c4a..477e93b7a1a 100644 --- a/src/doc/man/generated_txt/cargo-install.txt +++ b/src/doc/man/generated_txt/cargo-install.txt @@ -255,7 +255,9 @@ OPTIONS Number of parallel jobs to run. May also be specified with the build.jobs config value . Defaults to - the number of CPUs. + the number of logical CPUs. If negative, it sets the maximum number + of parallel jobs to the number of logical CPUs plus provided value. + Should not be 0. --keep-going Build as many crates in the dependency graph as possible, rather diff --git a/src/doc/man/generated_txt/cargo-package.txt b/src/doc/man/generated_txt/cargo-package.txt index 89a6b652d93..c53e1bdd444 100644 --- a/src/doc/man/generated_txt/cargo-package.txt +++ b/src/doc/man/generated_txt/cargo-package.txt @@ -187,7 +187,9 @@ OPTIONS Number of parallel jobs to run. May also be specified with the build.jobs config value . Defaults to - the number of CPUs. + the number of logical CPUs. If negative, it sets the maximum number + of parallel jobs to the number of logical CPUs plus provided value. + Should not be 0. --keep-going Build as many crates in the dependency graph as possible, rather diff --git a/src/doc/man/generated_txt/cargo-publish.txt b/src/doc/man/generated_txt/cargo-publish.txt index fc63a9c0a2d..a3e93e73274 100644 --- a/src/doc/man/generated_txt/cargo-publish.txt +++ b/src/doc/man/generated_txt/cargo-publish.txt @@ -154,7 +154,9 @@ OPTIONS Number of parallel jobs to run. May also be specified with the build.jobs config value . Defaults to - the number of CPUs. + the number of logical CPUs. If negative, it sets the maximum number + of parallel jobs to the number of logical CPUs plus provided value. + Should not be 0. --keep-going Build as many crates in the dependency graph as possible, rather diff --git a/src/doc/man/generated_txt/cargo-run.txt b/src/doc/man/generated_txt/cargo-run.txt index 2d0e607b7b3..01c8ae118c1 100644 --- a/src/doc/man/generated_txt/cargo-run.txt +++ b/src/doc/man/generated_txt/cargo-run.txt @@ -218,7 +218,9 @@ OPTIONS Number of parallel jobs to run. May also be specified with the build.jobs config value . Defaults to - the number of CPUs. + the number of logical CPUs. If negative, it sets the maximum number + of parallel jobs to the number of logical CPUs plus provided value. + Should not be 0. --keep-going Build as many crates in the dependency graph as possible, rather diff --git a/src/doc/man/generated_txt/cargo-rustc.txt b/src/doc/man/generated_txt/cargo-rustc.txt index b0f2ff3f622..a09a266f9ba 100644 --- a/src/doc/man/generated_txt/cargo-rustc.txt +++ b/src/doc/man/generated_txt/cargo-rustc.txt @@ -306,7 +306,9 @@ OPTIONS Number of parallel jobs to run. May also be specified with the build.jobs config value . Defaults to - the number of CPUs. + the number of logical CPUs. If negative, it sets the maximum number + of parallel jobs to the number of logical CPUs plus provided value. + Should not be 0. --keep-going Build as many crates in the dependency graph as possible, rather diff --git a/src/doc/man/generated_txt/cargo-rustdoc.txt b/src/doc/man/generated_txt/cargo-rustdoc.txt index b45e229a8a9..c6a4a814b37 100644 --- a/src/doc/man/generated_txt/cargo-rustdoc.txt +++ b/src/doc/man/generated_txt/cargo-rustdoc.txt @@ -289,7 +289,9 @@ OPTIONS Number of parallel jobs to run. May also be specified with the build.jobs config value . Defaults to - the number of CPUs. + the number of logical CPUs. If negative, it sets the maximum number + of parallel jobs to the number of logical CPUs plus provided value. + Should not be 0. --keep-going Build as many crates in the dependency graph as possible, rather diff --git a/src/doc/man/generated_txt/cargo-test.txt b/src/doc/man/generated_txt/cargo-test.txt index d0fe9df36a0..7277e58a381 100644 --- a/src/doc/man/generated_txt/cargo-test.txt +++ b/src/doc/man/generated_txt/cargo-test.txt @@ -392,7 +392,9 @@ OPTIONS Number of parallel jobs to run. May also be specified with the build.jobs config value . Defaults to - the number of CPUs. + the number of logical CPUs. If negative, it sets the maximum number + of parallel jobs to the number of logical CPUs plus provided value. + Should not be 0. --keep-going Build as many crates in the dependency graph as possible, rather diff --git a/src/doc/man/includes/options-jobs.md b/src/doc/man/includes/options-jobs.md index 7dc00e3de83..274263866d4 100644 --- a/src/doc/man/includes/options-jobs.md +++ b/src/doc/man/includes/options-jobs.md @@ -1,5 +1,7 @@ {{#option "`-j` _N_" "`--jobs` _N_"}} Number of parallel jobs to run. May also be specified with the `build.jobs` [config value](../reference/config.html). Defaults to -the number of CPUs. +the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0. {{/option}} diff --git a/src/doc/src/commands/cargo-bench.md b/src/doc/src/commands/cargo-bench.md index 69bee8ddb92..1e3e3d4a2fa 100644 --- a/src/doc/src/commands/cargo-bench.md +++ b/src/doc/src/commands/cargo-bench.md @@ -447,7 +447,9 @@ Rust test harness runs benchmarks serially in a single thread.
--jobs N
Number of parallel jobs to run. May also be specified with the build.jobs config value. Defaults to -the number of CPUs.
+the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0.
--keep-going
diff --git a/src/doc/src/commands/cargo-build.md b/src/doc/src/commands/cargo-build.md index 3f473de7a7d..753cf9c4d62 100644 --- a/src/doc/src/commands/cargo-build.md +++ b/src/doc/src/commands/cargo-build.md @@ -387,7 +387,9 @@ for more information about how toolchain overrides work.
--jobs N
Number of parallel jobs to run. May also be specified with the build.jobs config value. Defaults to -the number of CPUs.
+the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0.
--keep-going
diff --git a/src/doc/src/commands/cargo-check.md b/src/doc/src/commands/cargo-check.md index 7ea0651901a..ec713d3a742 100644 --- a/src/doc/src/commands/cargo-check.md +++ b/src/doc/src/commands/cargo-check.md @@ -368,7 +368,9 @@ for more information about how toolchain overrides work.
--jobs N
Number of parallel jobs to run. May also be specified with the build.jobs config value. Defaults to -the number of CPUs.
+the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0.
--keep-going
diff --git a/src/doc/src/commands/cargo-doc.md b/src/doc/src/commands/cargo-doc.md index b28020c9d74..eee17d3fd70 100644 --- a/src/doc/src/commands/cargo-doc.md +++ b/src/doc/src/commands/cargo-doc.md @@ -342,7 +342,9 @@ for more information about how toolchain overrides work.
--jobs N
Number of parallel jobs to run. May also be specified with the build.jobs config value. Defaults to -the number of CPUs.
+the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0.
--keep-going
diff --git a/src/doc/src/commands/cargo-fix.md b/src/doc/src/commands/cargo-fix.md index d75d81a44bf..e1fcc76236f 100644 --- a/src/doc/src/commands/cargo-fix.md +++ b/src/doc/src/commands/cargo-fix.md @@ -448,7 +448,9 @@ for more information about how toolchain overrides work.
--jobs N
Number of parallel jobs to run. May also be specified with the build.jobs config value. Defaults to -the number of CPUs.
+the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0.
--keep-going
diff --git a/src/doc/src/commands/cargo-install.md b/src/doc/src/commands/cargo-install.md index fc6678ff3e6..d982ec94bd7 100644 --- a/src/doc/src/commands/cargo-install.md +++ b/src/doc/src/commands/cargo-install.md @@ -293,7 +293,9 @@ offline.

--jobs N
Number of parallel jobs to run. May also be specified with the build.jobs config value. Defaults to -the number of CPUs.
+the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0.
--keep-going
diff --git a/src/doc/src/commands/cargo-package.md b/src/doc/src/commands/cargo-package.md index 568880a0d48..bfae8c1691d 100644 --- a/src/doc/src/commands/cargo-package.md +++ b/src/doc/src/commands/cargo-package.md @@ -225,7 +225,9 @@ offline.

--jobs N
Number of parallel jobs to run. May also be specified with the build.jobs config value. Defaults to -the number of CPUs.
+the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0.
--keep-going
diff --git a/src/doc/src/commands/cargo-publish.md b/src/doc/src/commands/cargo-publish.md index e4489416e06..133d7619bc5 100644 --- a/src/doc/src/commands/cargo-publish.md +++ b/src/doc/src/commands/cargo-publish.md @@ -191,7 +191,9 @@ offline.

--jobs N
Number of parallel jobs to run. May also be specified with the build.jobs config value. Defaults to -the number of CPUs.
+the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0.
--keep-going
diff --git a/src/doc/src/commands/cargo-run.md b/src/doc/src/commands/cargo-run.md index e0fa5ccac3e..5b5f79f2fbe 100644 --- a/src/doc/src/commands/cargo-run.md +++ b/src/doc/src/commands/cargo-run.md @@ -281,7 +281,9 @@ for more information about how toolchain overrides work.
--jobs N
Number of parallel jobs to run. May also be specified with the build.jobs config value. Defaults to -the number of CPUs.
+the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0.
--keep-going
diff --git a/src/doc/src/commands/cargo-rustc.md b/src/doc/src/commands/cargo-rustc.md index 7396d679e2e..ba42ca43e2e 100644 --- a/src/doc/src/commands/cargo-rustc.md +++ b/src/doc/src/commands/cargo-rustc.md @@ -370,7 +370,9 @@ for more information about how toolchain overrides work.
--jobs N
Number of parallel jobs to run. May also be specified with the build.jobs config value. Defaults to -the number of CPUs.
+the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0.
--keep-going
diff --git a/src/doc/src/commands/cargo-rustdoc.md b/src/doc/src/commands/cargo-rustdoc.md index 1fe506d108e..5ae475d7972 100644 --- a/src/doc/src/commands/cargo-rustdoc.md +++ b/src/doc/src/commands/cargo-rustdoc.md @@ -361,7 +361,9 @@ for more information about how toolchain overrides work.
--jobs N
Number of parallel jobs to run. May also be specified with the build.jobs config value. Defaults to -the number of CPUs.
+the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0.
--keep-going
diff --git a/src/doc/src/commands/cargo-test.md b/src/doc/src/commands/cargo-test.md index 9ff65a10723..ca40d80f6ab 100644 --- a/src/doc/src/commands/cargo-test.md +++ b/src/doc/src/commands/cargo-test.md @@ -473,7 +473,9 @@ includes an option to control the number of threads used:
--jobs N
Number of parallel jobs to run. May also be specified with the build.jobs config value. Defaults to -the number of CPUs.
+the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0.
--keep-going
diff --git a/src/etc/man/cargo-bench.1 b/src/etc/man/cargo-bench.1 index 002f7562a21..18b6fc8a794 100644 --- a/src/etc/man/cargo-bench.1 +++ b/src/etc/man/cargo-bench.1 @@ -469,7 +469,9 @@ Rust test harness runs benchmarks serially in a single thread. .RS 4 Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to -the number of CPUs. +the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0. .RE .sp \fB\-\-keep\-going\fR diff --git a/src/etc/man/cargo-build.1 b/src/etc/man/cargo-build.1 index edbc8f90b61..34b0d52335d 100644 --- a/src/etc/man/cargo-build.1 +++ b/src/etc/man/cargo-build.1 @@ -396,7 +396,9 @@ Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fR for details. .RS 4 Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to -the number of CPUs. +the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0. .RE .sp \fB\-\-keep\-going\fR diff --git a/src/etc/man/cargo-check.1 b/src/etc/man/cargo-check.1 index a8ecef5f7b1..b1018202932 100644 --- a/src/etc/man/cargo-check.1 +++ b/src/etc/man/cargo-check.1 @@ -377,7 +377,9 @@ Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fR for details. .RS 4 Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to -the number of CPUs. +the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0. .RE .sp \fB\-\-keep\-going\fR diff --git a/src/etc/man/cargo-doc.1 b/src/etc/man/cargo-doc.1 index 5d3ffc2dd2a..b49c4f2e8bf 100644 --- a/src/etc/man/cargo-doc.1 +++ b/src/etc/man/cargo-doc.1 @@ -344,7 +344,9 @@ Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fR for details. .RS 4 Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to -the number of CPUs. +the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0. .RE .sp \fB\-\-keep\-going\fR diff --git a/src/etc/man/cargo-fix.1 b/src/etc/man/cargo-fix.1 index 3aaa1f89bce..e103de2d068 100644 --- a/src/etc/man/cargo-fix.1 +++ b/src/etc/man/cargo-fix.1 @@ -472,7 +472,9 @@ Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fR for details. .RS 4 Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to -the number of CPUs. +the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0. .RE .sp \fB\-\-keep\-going\fR diff --git a/src/etc/man/cargo-install.1 b/src/etc/man/cargo-install.1 index 72fc87ff136..7f2db3f5fe9 100644 --- a/src/etc/man/cargo-install.1 +++ b/src/etc/man/cargo-install.1 @@ -325,7 +325,9 @@ May also be specified with the \fBnet.offline\fR \fIconfig value\fR \&. Defaults to -the number of CPUs. +the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0. .RE .sp \fB\-\-keep\-going\fR diff --git a/src/etc/man/cargo-package.1 b/src/etc/man/cargo-package.1 index 6e451ada63b..ce7f7ae64e0 100644 --- a/src/etc/man/cargo-package.1 +++ b/src/etc/man/cargo-package.1 @@ -233,7 +233,9 @@ May also be specified with the \fBnet.offline\fR \fIconfig value\fR \&. Defaults to -the number of CPUs. +the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0. .RE .sp \fB\-\-keep\-going\fR diff --git a/src/etc/man/cargo-publish.1 b/src/etc/man/cargo-publish.1 index aa2490ed0eb..0b065510634 100644 --- a/src/etc/man/cargo-publish.1 +++ b/src/etc/man/cargo-publish.1 @@ -183,7 +183,9 @@ May also be specified with the \fBnet.offline\fR \fIconfig value\fR \&. Defaults to -the number of CPUs. +the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0. .RE .sp \fB\-\-keep\-going\fR diff --git a/src/etc/man/cargo-run.1 b/src/etc/man/cargo-run.1 index 241e0b2e161..c1902aa822f 100644 --- a/src/etc/man/cargo-run.1 +++ b/src/etc/man/cargo-run.1 @@ -277,7 +277,9 @@ Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fR for details. .RS 4 Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to -the number of CPUs. +the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0. .RE .sp \fB\-\-keep\-going\fR diff --git a/src/etc/man/cargo-rustc.1 b/src/etc/man/cargo-rustc.1 index 07076e24463..6e24e8fd65f 100644 --- a/src/etc/man/cargo-rustc.1 +++ b/src/etc/man/cargo-rustc.1 @@ -381,7 +381,9 @@ Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fR for details. .RS 4 Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to -the number of CPUs. +the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0. .RE .sp \fB\-\-keep\-going\fR diff --git a/src/etc/man/cargo-rustdoc.1 b/src/etc/man/cargo-rustdoc.1 index 34a37d52f61..d5bc15d8f36 100644 --- a/src/etc/man/cargo-rustdoc.1 +++ b/src/etc/man/cargo-rustdoc.1 @@ -363,7 +363,9 @@ Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fR for details. .RS 4 Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to -the number of CPUs. +the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0. .RE .sp \fB\-\-keep\-going\fR diff --git a/src/etc/man/cargo-test.1 b/src/etc/man/cargo-test.1 index 00fe416d5a2..3c12b2d8b6b 100644 --- a/src/etc/man/cargo-test.1 +++ b/src/etc/man/cargo-test.1 @@ -494,7 +494,9 @@ cargo test \-j 2 \-\- \-\-test\-threads=2 .RS 4 Number of parallel jobs to run. May also be specified with the \fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to -the number of CPUs. +the number of logical CPUs. If negative, it sets the maximum number of +parallel jobs to the number of logical CPUs plus provided value. +Should not be 0. .RE .sp \fB\-\-keep\-going\fR From 81f78af15264b2d2bdb02e6477395df7337f7d26 Mon Sep 17 00:00:00 2001 From: Yerkebulan Tulibergenov Date: Sun, 10 Jul 2022 16:13:39 -0700 Subject: [PATCH 5/7] make consistent error message --- src/cargo/core/compiler/build_config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/core/compiler/build_config.rs b/src/cargo/core/compiler/build_config.rs index b2c8f28fdc8..1aca44b802d 100644 --- a/src/cargo/core/compiler/build_config.rs +++ b/src/cargo/core/compiler/build_config.rs @@ -64,7 +64,7 @@ impl BuildConfig { let cfg = config.build_config()?; let requested_kinds = CompileKind::from_requested_targets(config, requested_targets)?; if jobs == Some(0) { - anyhow::bail!("jobs must not be zero") + anyhow::bail!("jobs may not be 0") } if jobs.is_some() && config.jobserver_from_env().is_some() { config.shell().warn( From 2a75b44bc5c866753d50d63ca4df5d8465029b0b Mon Sep 17 00:00:00 2001 From: Yerkebulan Tulibergenov Date: Sun, 10 Jul 2022 16:31:24 -0700 Subject: [PATCH 6/7] fix the test --- tests/testsuite/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index e951e038584..68e20666107 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -5455,7 +5455,7 @@ fn invalid_jobs() { p.cargo("build --jobs 0") .with_status(101) - .with_stderr_contains("error: jobs must not be zero") + .with_stderr_contains("error: jobs may not be 0") .run(); p.cargo("build --jobs over9000") From 7c932a471327ec30d78293da044bbd34122b40f4 Mon Sep 17 00:00:00 2001 From: Yerkebulan Tulibergenov Date: Sun, 31 Jul 2022 14:34:34 -0700 Subject: [PATCH 7/7] remove duplicate check --- src/cargo/core/compiler/build_config.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/cargo/core/compiler/build_config.rs b/src/cargo/core/compiler/build_config.rs index 1aca44b802d..51c9bf77871 100644 --- a/src/cargo/core/compiler/build_config.rs +++ b/src/cargo/core/compiler/build_config.rs @@ -63,9 +63,6 @@ impl BuildConfig { ) -> CargoResult { let cfg = config.build_config()?; let requested_kinds = CompileKind::from_requested_targets(config, requested_targets)?; - if jobs == Some(0) { - anyhow::bail!("jobs may not be 0") - } if jobs.is_some() && config.jobserver_from_env().is_some() { config.shell().warn( "a `-j` argument was passed to Cargo but Cargo is \