{"record":{"id":"3f1ac8f5f36d8bb2","repo":"rust-lang/cargo","slug":"metabuild-package-must-be-specified-in-build","errorCode":null,"errorMessage":"metabuild package `{}` must be specified in `build-dependencies`","messagePattern":"metabuild package `(.+?)` must be specified in `build-dependencies`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/workspace/parser/targets.rs","lineNumber":129,"sourceCode":"                \"build-script-{}\",\n                script_path\n                    .file_stem()\n                    .and_then(|s| s.to_str())\n                    .expect(\"previously normalized\")\n            );\n            targets.push(Target::custom_build_target(\n                &name,\n                package_root.join(script_path),\n                edition,\n            ));\n        }\n    }\n    if let Some(metabuild) = metabuild {\n        // Verify names match available build deps.\n        let bdeps = normalized_toml.build_dependencies.as_ref();\n        for name in &metabuild.0 {\n            if !bdeps.map_or(false, |bd| bd.contains_key(name.as_str())) {\n                anyhow::bail!(\n                    \"metabuild package `{}` must be specified in `build-dependencies`\",\n                    name\n                );\n            }\n        }\n\n        targets.push(Target::metabuild_target(&format!(\n            \"metabuild-{}\",\n            package.normalized_name().expect(\"previously normalized\")\n        )));\n    }\n\n    Ok(targets)\n}\n\n#[tracing::instrument(skip_all)]\npub fn normalize_lib(\n    original_lib: Option<&TomlLibTarget>,","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/rust-lang/cargo/blob/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/workspace/parser/targets.rs#L111-L147","documentation":"Every crate named in `metabuild` must also appear under `[build-dependencies]`, because Cargo compiles those crates as part of the build script generation phase. The parser iterates `metabuild.0` and checks `normalized_toml.build_dependencies` contains each name via `bd.contains_key(name.as_str())`. A missing entry means Cargo has no way to fetch and compile the metabuild generator.","triggerScenarios":"Cargo.toml has `[package] metabuild = [\"foo\"]` but `[build-dependencies]` either is absent or has no `foo` key. The loop at targets.rs:128-135 fails the `map_or(false, ...)` membership test and bails.","commonSituations":"Typo between the metabuild name and the build-dependency key. Forgetting to add the build-dependency after enabling metabuild. Renaming a crate but not updating both sections.","solutions":["Add the missing crate to `[build-dependencies]` with a compatible version, e.g. `foo = \"1.0\"`.","Verify the spelling in `metabuild` exactly matches the dependency key.","Run `cargo fetch` to confirm the dependency resolves."],"exampleFix":"# before\n[package]\nmetabuild = [\"foo\"]\n\n# after\n[package]\nmetabuild = [\"foo\"]\n[build-dependencies]\nfoo = \"1.0\"","handlingStrategy":"validation","validationCode":"fn metabuild_deps_satisfied(manifest: &Value) -> bool {\n    let metabuild: Vec<String> = manifest\n        .get(\"package\").and_then(|p| p.get(\"metabuild\"))\n        .and_then(|m| m.as_array())\n        .map(|a| a.iter().filter_map(|v| v.as_str().map(String::from)).collect())\n        .unwrap_or_default();\n    if metabuild.is_empty() { return true; }\n    let bdeps = manifest.get(\"build-dependencies\");\n    metabuild.iter().all(|name| {\n        bdeps.and_then(|b| b.as_table()).map_or(false, |t| t.contains_key(name))\n    })\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always add a metabuild crate to `[build-dependencies]` in the same edit.","Keep metabuild names and build-dependency keys in sync during renames.","Lint manifests for orphaned metabuild references."],"tags":["cargo","config","metabuild","dependencies","manifest"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}