{"id":"f29cc8fc83ef0ecb","repo":"rust-lang/cargo","slug":"cannot-specify-both-metabuild-and-build","errorCode":null,"errorMessage":"cannot specify both `metabuild` and `build`","messagePattern":"cannot specify both `metabuild` and `build`","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/workspace/parser/targets.rs","lineNumber":105,"sourceCode":"\n    targets.extend(to_test_targets(\n        normalized_toml.test.as_deref().unwrap_or_default(),\n        package_root,\n        edition,\n        warnings,\n    )?);\n\n    targets.extend(to_bench_targets(\n        normalized_toml.bench.as_deref().unwrap_or_default(),\n        package_root,\n        edition,\n        warnings,\n    )?);\n\n    // processing the custom build script\n    if let Some(custom_build) = package.normalized_build().expect(\"previously normalized\") {\n        if metabuild.is_some() {\n            anyhow::bail!(\"cannot specify both `metabuild` and `build`\");\n        }\n        validate_unique_build_scripts(custom_build)?;\n        for script in custom_build {\n            let script_path = Path::new(script);\n            let name = format!(\n                \"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    }","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/parser/targets.rs#L87-L123","documentation":"Error \"cannot specify both `metabuild` and `build`\" thrown in rust-lang/cargo.","triggerScenarios":"Thrown at src/workspace/parser/targets.rs:105 when the library encounters an invalid state.","commonSituations":"Occurs when a manifest specifies both `metabuild` and a `build` script for the same package. Specify only one build mechanism: either the unstable `metabuild` key or a conventional `build` script path.","solutions":["Choose either `metabuild` or `build` in the target/manifest, not both.","Remove the `metabuild` key if a custom `build` script path is already specified."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}