diff --git a/src/cargo/core/compiler/build_config.rs b/src/cargo/core/compiler/build_config.rs
index 885b124b9767..425035f85f63 100644
--- a/src/cargo/core/compiler/build_config.rs
+++ b/src/cargo/core/compiler/build_config.rs
@@ -1,4 +1,5 @@
use crate::core::compiler::CompileKind;
+use crate::util::config::JobsValue;
use crate::util::interning::InternedString;
use crate::util::{CargoResult, Config, RustfixDiagnosticServer};
use anyhow::{bail, Context as _};
@@ -64,7 +65,7 @@ impl BuildConfig {
/// * `target.$target.libfoo.metadata`
pub fn new(
config: &Config,
- jobs: Option,
+ jobs: Option,
keep_going: bool,
requested_targets: &[String],
mode: CompileMode,
@@ -78,11 +79,22 @@ impl BuildConfig {
its environment, ignoring the `-j` parameter",
)?;
}
- let jobs = match jobs.or(cfg.jobs) {
+ let jobs = match jobs.or(cfg.jobs.clone()) {
None => default_parallelism()?,
- Some(0) => anyhow::bail!("jobs may not be 0"),
- Some(j) if j < 0 => (default_parallelism()? as i32 + j).max(1) as u32,
- Some(j) => j as u32,
+ Some(value) => match value {
+ JobsValue::Integer(j) => match j {
+ 0 => anyhow::bail!("jobs may not be 0"),
+ j if j < 0 => (default_parallelism()? as i32 + j).max(1) as u32,
+ j => j as u32,
+ },
+ JobsValue::String(j) => match j.as_str() {
+ "default" => default_parallelism()?,
+ _ => {
+ anyhow::bail!(
+ format!("Invalid value: could not parse `{}`. Value should be `default` or a number.", j))
+ }
+ },
+ },
};
if config.cli_unstable().build_std.is_some() && requested_kinds[0].is_host() {
diff --git a/src/cargo/ops/cargo_fetch.rs b/src/cargo/ops/cargo_fetch.rs
index bac3f0278d8b..affc6777cd5b 100644
--- a/src/cargo/ops/cargo_fetch.rs
+++ b/src/cargo/ops/cargo_fetch.rs
@@ -2,6 +2,7 @@ use crate::core::compiler::standard_lib;
use crate::core::compiler::{BuildConfig, CompileMode, RustcTargetData};
use crate::core::{PackageSet, Resolve, Workspace};
use crate::ops;
+use crate::util::config::JobsValue;
use crate::util::CargoResult;
use crate::util::Config;
use std::collections::HashSet;
@@ -20,7 +21,7 @@ pub fn fetch<'a>(
ws.emit_warnings()?;
let (mut packages, resolve) = ops::resolve_ws(ws)?;
- let jobs = Some(1);
+ let jobs = Some(JobsValue::Integer(1));
let keep_going = false;
let config = ws.config();
let build_config = BuildConfig::new(
diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs
index f80848c75960..8bfd8f04d61a 100644
--- a/src/cargo/ops/cargo_package.rs
+++ b/src/cargo/ops/cargo_package.rs
@@ -13,6 +13,7 @@ use crate::core::{registry::PackageRegistry, resolver::HasDevUnits};
use crate::core::{Feature, Shell, Verbosity, Workspace};
use crate::core::{Package, PackageId, PackageSet, Resolve, SourceId};
use crate::sources::PathSource;
+use crate::util::config::JobsValue;
use crate::util::errors::CargoResult;
use crate::util::toml::TomlManifest;
use crate::util::{self, human_readable_bytes, restricted_names, Config, FileLock};
@@ -31,7 +32,7 @@ pub struct PackageOpts<'cfg> {
pub check_metadata: bool,
pub allow_dirty: bool,
pub verify: bool,
- pub jobs: Option,
+ pub jobs: Option,
pub keep_going: bool,
pub to_package: ops::Packages,
pub targets: Vec,
@@ -198,7 +199,7 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult
Number of parallel jobs to run. May also be specified with the
build.jobsconfig value. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+default, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
Number of parallel jobs to run. May also be specified with the
build.jobsconfig value. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+default, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
Number of parallel jobs to run. May also be specified with the
build.jobsconfig value. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+default, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
diff --git a/src/doc/src/commands/cargo-run.md b/src/doc/src/commands/cargo-run.md
index f6f5ec2a3438..aa2fdf5b13ba 100644
--- a/src/doc/src/commands/cargo-run.md
+++ b/src/doc/src/commands/cargo-run.md
@@ -299,7 +299,8 @@ requires the -Z unstable-options flag to enable (see
Number of parallel jobs to run. May also be specified with the
build.jobsconfig value. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+default, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
diff --git a/src/doc/src/commands/cargo-rustc.md b/src/doc/src/commands/cargo-rustc.md
index 946298af9148..ca1caf420ef1 100644
--- a/src/doc/src/commands/cargo-rustc.md
+++ b/src/doc/src/commands/cargo-rustc.md
@@ -396,7 +396,8 @@ requires the -Z unstable-options flag to enable (see
Number of parallel jobs to run. May also be specified with the
build.jobsconfig value. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+default, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
diff --git a/src/doc/src/commands/cargo-rustdoc.md b/src/doc/src/commands/cargo-rustdoc.md
index 8467da2a32c0..6b23e351293c 100644
--- a/src/doc/src/commands/cargo-rustdoc.md
+++ b/src/doc/src/commands/cargo-rustdoc.md
@@ -376,7 +376,8 @@ requires the -Z unstable-options flag to enable (see
Number of parallel jobs to run. May also be specified with the
build.jobsconfig value. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+default, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
diff --git a/src/doc/src/commands/cargo-test.md b/src/doc/src/commands/cargo-test.md
index 24fcc70ffa75..28568b39068a 100644
--- a/src/doc/src/commands/cargo-test.md
+++ b/src/doc/src/commands/cargo-test.md
@@ -503,7 +503,8 @@ includes an option to control the number of threads used:
Number of parallel jobs to run. May also be specified with the
build.jobsconfig value. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+default, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
diff --git a/src/etc/man/cargo-bench.1 b/src/etc/man/cargo-bench.1
index 44ff593fdd80..4fef5515b491 100644
--- a/src/etc/man/cargo-bench.1
+++ b/src/etc/man/cargo-bench.1
@@ -497,7 +497,8 @@ Rust test harness runs benchmarks serially in a single thread.
Number of parallel jobs to run. May also be specified with the
\fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+\fBdefault\fR, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
.RE
.sp
diff --git a/src/etc/man/cargo-build.1 b/src/etc/man/cargo-build.1
index 80ae4ac90924..872819770f02 100644
--- a/src/etc/man/cargo-build.1
+++ b/src/etc/man/cargo-build.1
@@ -412,7 +412,8 @@ Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fR for details.
Number of parallel jobs to run. May also be specified with the
\fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+\fBdefault\fR, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
.RE
.sp
diff --git a/src/etc/man/cargo-check.1 b/src/etc/man/cargo-check.1
index cf7a66d89d72..20b34238db2f 100644
--- a/src/etc/man/cargo-check.1
+++ b/src/etc/man/cargo-check.1
@@ -393,7 +393,8 @@ Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fR for details.
Number of parallel jobs to run. May also be specified with the
\fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+\fBdefault\fR, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
.RE
.sp
diff --git a/src/etc/man/cargo-doc.1 b/src/etc/man/cargo-doc.1
index 63ce2a05036b..930e259bbffa 100644
--- a/src/etc/man/cargo-doc.1
+++ b/src/etc/man/cargo-doc.1
@@ -360,7 +360,8 @@ Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fR for details.
Number of parallel jobs to run. May also be specified with the
\fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+\fBdefault\fR, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
.RE
.sp
diff --git a/src/etc/man/cargo-fix.1 b/src/etc/man/cargo-fix.1
index 51b1e3fd64ea..4b1edfd5a3f4 100644
--- a/src/etc/man/cargo-fix.1
+++ b/src/etc/man/cargo-fix.1
@@ -488,7 +488,8 @@ Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fR for details.
Number of parallel jobs to run. May also be specified with the
\fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+\fBdefault\fR, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
.RE
.sp
diff --git a/src/etc/man/cargo-install.1 b/src/etc/man/cargo-install.1
index a9eb6266b898..535ced2c67c0 100644
--- a/src/etc/man/cargo-install.1
+++ b/src/etc/man/cargo-install.1
@@ -338,7 +338,8 @@ May also be specified with the \fBnet.offline\fR \fIconfig value\fR \&. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+\fBdefault\fR, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
.RE
.sp
diff --git a/src/etc/man/cargo-package.1 b/src/etc/man/cargo-package.1
index 9f4847d7d12c..e65255f84d67 100644
--- a/src/etc/man/cargo-package.1
+++ b/src/etc/man/cargo-package.1
@@ -234,7 +234,8 @@ May also be specified with the \fBnet.offline\fR \fIconfig value\fR \&. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+\fBdefault\fR, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
.RE
.sp
diff --git a/src/etc/man/cargo-publish.1 b/src/etc/man/cargo-publish.1
index a54a7bcda601..38a9bb14a033 100644
--- a/src/etc/man/cargo-publish.1
+++ b/src/etc/man/cargo-publish.1
@@ -184,7 +184,8 @@ May also be specified with the \fBnet.offline\fR \fIconfig value\fR \&. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+\fBdefault\fR, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
.RE
.sp
diff --git a/src/etc/man/cargo-run.1 b/src/etc/man/cargo-run.1
index 7a85298ccd45..d12e88b8521f 100644
--- a/src/etc/man/cargo-run.1
+++ b/src/etc/man/cargo-run.1
@@ -297,7 +297,8 @@ Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fR for details.
Number of parallel jobs to run. May also be specified with the
\fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+\fBdefault\fR, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
.RE
.sp
diff --git a/src/etc/man/cargo-rustc.1 b/src/etc/man/cargo-rustc.1
index 6e901d9ecade..3311db9036d2 100644
--- a/src/etc/man/cargo-rustc.1
+++ b/src/etc/man/cargo-rustc.1
@@ -411,7 +411,8 @@ Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fR for details.
Number of parallel jobs to run. May also be specified with the
\fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+\fBdefault\fR, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
.RE
.sp
diff --git a/src/etc/man/cargo-rustdoc.1 b/src/etc/man/cargo-rustdoc.1
index 0c9a0e74a7d6..2547dac554f8 100644
--- a/src/etc/man/cargo-rustdoc.1
+++ b/src/etc/man/cargo-rustdoc.1
@@ -379,7 +379,8 @@ Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fR for details.
Number of parallel jobs to run. May also be specified with the
\fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+\fBdefault\fR, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
.RE
.sp
diff --git a/src/etc/man/cargo-test.1 b/src/etc/man/cargo-test.1
index 1ee2f76727fd..b7b3195ad007 100644
--- a/src/etc/man/cargo-test.1
+++ b/src/etc/man/cargo-test.1
@@ -523,7 +523,8 @@ cargo test \-j 2 \-\- \-\-test\-threads=2
Number of parallel jobs to run. May also be specified with the
\fBbuild.jobs\fR \fIconfig value\fR \&. Defaults to
the number of logical CPUs. If negative, it sets the maximum number of
-parallel jobs to the number of logical CPUs plus provided value.
+parallel jobs to the number of logical CPUs plus provided value. If
+\fBdefault\fR, it sets the number of parallel jobs to the number of logical CPUs.
Should not be 0.
.RE
.sp
diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs
index 6dbef022e954..03cb494fe232 100644
--- a/tests/testsuite/build.rs
+++ b/tests/testsuite/build.rs
@@ -5566,6 +5566,8 @@ fn good_jobs() {
p.cargo("build --jobs 1").run();
p.cargo("build --jobs -1").run();
+
+ p.cargo("build --jobs default").run();
}
#[cargo_test]
@@ -5599,8 +5601,8 @@ fn invalid_jobs() {
.run();
p.cargo("build --jobs over9000")
- .with_status(1)
- .with_stderr("error: Invalid value: could not parse `over9000` as a number")
+ .with_status(101)
+ .with_stderr("error: Invalid value: could not parse `over9000`. Value should be `default` or a number.")
.run();
}