diff --git a/src/cargo/core/compiler/build_config.rs b/src/cargo/core/compiler/build_config.rs index 885b124b976..5d4d754bff1 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::JobsConfig; 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 { + JobsConfig::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, + }, + JobsConfig::String(j) => match j.as_str() { + "default" => default_parallelism()?, + _ => { + anyhow::bail!( + format!("could not parse `{j}`. Number of parallel jobs should be `default` or a number.")) + } + }, + }, }; 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 bac3f0278d8..273bce28492 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::JobsConfig; 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(JobsConfig::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 f80848c7596..37bc6bd0767 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::JobsConfig; 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