{"id":"9245a0ccadab6066","repo":"rust-lang/cargo","slug":"jobs-may-not-be-0","errorCode":null,"errorMessage":"jobs may not be 0","messagePattern":"jobs may not be 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/build_config.rs","lineNumber":90,"sourceCode":"        jobs: Option<JobsConfig>,\n        keep_going: bool,\n        requested_targets: &[String],\n        intent: UserIntent,\n    ) -> CargoResult<BuildConfig> {\n        let cfg = gctx.build_config()?;\n        let requested_kinds = CompileKind::from_requested_targets(gctx, requested_targets)?;\n        if jobs.is_some() && gctx.jobserver_from_env().is_some() {\n            gctx.shell().warn(\n                \"a `-j` argument was passed to Cargo but Cargo is \\\n                 also configured with an external jobserver in \\\n                 its environment, ignoring the `-j` parameter\",\n            )?;\n        }\n        let jobs = match jobs.or(cfg.jobs.clone()) {\n            None => default_parallelism()?,\n            Some(value) => match value {\n                JobsConfig::Integer(j) => match j {\n                    0 => anyhow::bail!(\"jobs may not be 0\"),\n                    j if j < 0 => (default_parallelism()? as i32 + j).max(1) as u32,\n                    j => j as u32,\n                },\n                JobsConfig::String(j) => match j.as_str() {\n                    \"default\" => default_parallelism()?,\n                    _ => {\n                        anyhow::bail!(format!(\n                            \"could not parse `{j}`. Number of parallel jobs should be `default` or a number.\"\n                        ))\n                    }\n                },\n            },\n        };\n\n        // If sbom flag is set, it requires the unstable feature\n        let sbom = match (cfg.sbom, gctx.cli_unstable().sbom) {\n            (Some(sbom), true) => sbom,\n            (Some(_), false) => {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/compiler/build_config.rs#L72-L108","documentation":"In BuildConfig::new (build_config.rs:89-90), the `jobs` value is parsed from `-j <n>` or `build.jobs` config. An explicit integer of `0` is invalid because zero parallel jobs would build nothing, so Cargo bails with `jobs may not be 0`. Negative values are allowed (treated as relative to default parallelism) but zero is not.","triggerScenarios":"Passing `cargo build -j 0`, or setting `[build] jobs = 0` in config, or a computed job count that resolves to 0.","commonSituations":"CI scripts computing `-j` from a CPU count variable that is unset/0; `CARGO_BUILD_JOBS=0` in the environment; misconfigured `build.jobs`.","solutions":["Pass a positive integer: `cargo build -j 4`.","Omit `-j` to let Cargo use default parallelism (number of CPUs).","Use `-j default` or `build.jobs = \"default\"` explicitly.","Fix the CI variable that produced 0 (e.g. fall back to `nproc` when unset)."],"exampleFix":"// before\n$ CARGO_BUILD_JOBS=0 cargo build\nerror: jobs may not be 0\n\n// after\n$ cargo build -j 4","handlingStrategy":"validation","validationCode":"match jobs {\n    Some(JobsConfig::Integer(0)) => return Err(\"jobs may not be 0\"),\n    Some(JobsConfig::Integer(j)) if j < 0 => { /* relative */ }\n    _ => {}\n}","typeGuard":"fn jobs_is_valid(j: i64) -> bool {\n    j != 0\n}\n","tryCatchPattern":null,"preventionTips":["Default missing CPU-count variables to `nproc`/`num_cpus` in CI.","Validate -j/build.jobs is a positive integer or \"default\"."],"tags":["cargo","build","parallelism","config","argument"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}