{"record":{"id":"6c3d450e485a33e5","repo":"rust-lang/cargo","slug":"cannot-produce-for-as-the-target-does","errorCode":null,"errorMessage":"cannot produce {} for `{}` as the target `{}` does not support these crate types","messagePattern":"cannot produce (.+?) for `(.+?)` as the target `(.+?)` does not support these crate types","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/build_runner/compilation_files.rs","lineNumber":676,"sourceCode":"    /// Computes the actual, full pathnames for all the files generated by rustc.\n    ///\n    /// The `OutputFile` also contains the paths where those files should be\n    /// \"uplifted\" to.\n    fn calc_outputs_rustc(\n        &self,\n        unit: &Unit,\n        bcx: &BuildContext<'a, 'gctx>,\n    ) -> CargoResult<Vec<OutputFile>> {\n        let out_dir = self.output_dir(unit);\n\n        let info = bcx.target_data.info(unit.kind);\n        let triple = bcx.target_data.short_name(&unit.kind);\n        let (file_types, unsupported) =\n            info.rustc_outputs(unit.mode, unit.target.kind(), triple)?;\n        if file_types.is_empty() {\n            if !unsupported.is_empty() {\n                let unsupported_strs: Vec<_> = unsupported.iter().map(|ct| ct.as_str()).collect();\n                anyhow::bail!(\n                    \"cannot produce {} for `{}` as the target `{}` \\\n                     does not support these crate types\",\n                    unsupported_strs.join(\", \"),\n                    unit.pkg,\n                    triple,\n                )\n            }\n            anyhow::bail!(\n                \"cannot compile `{}` as the target `{}` does not \\\n                 support any of the output crate types\",\n                unit.pkg,\n                triple,\n            );\n        }\n\n        // Convert FileType to OutputFile.\n        let mut outputs = Vec::new();\n        for file_type in file_types {","sourceCodeStart":658,"sourceCodeEnd":694,"githubUrl":"https://github.com/rust-lang/cargo/blob/42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9/src/compiler/build_runner/compilation_files.rs#L658-L694","documentation":"The requested unit's target supports some crate types but none of the ones the package declared (e.g. it asked for `cdylib` but the target only produces `bin`/`rlib`). `rustc_outputs` returned a non-empty `unsupported` list and an empty `file_types` list, so Cargo reports exactly which requested types the target rejects.","triggerScenarios":"Declaring `crate-type = [\"cdylib\", \"dylib\"]` in `Cargo.toml` and building for a target like `wasm32-wasi` or a bare-metal target that doesn't support dynamic libraries; mixing `bin` and `cdylib` for an embedded target.","commonSituations":"Cross-compiling a library meant for desktop to `*-none-*` or UEFI targets; conditional crate types without per-target Cargo config; inheriting a workspace crate-type for an unsupported target.","solutions":["Scope crate types per target using `[lib] crate-type` overrides or `cargo:rustc-crate-type` rules in `.cargo/config.toml` per-target sections.","Drop the unsupported crate type from the package or move it behind a feature flag.","Switch to a target that supports the requested output types (e.g. a GNU/Linux or MSVC triple for `dylib`).","Verify with `rustc --print=crate-types --target <triple>` what the target actually supports."],"exampleFix":"// before\n# Cargo.toml\n[lib]\ncrate-type = [\"cdylib\"]\n\n// after (per-target override in .cargo/config.toml)\n[target.wasm32-unknown-unknown]\n# build as rlib instead, or conditionally compile","handlingStrategy":"validation","validationCode":"fn target_supports_crate_type(triple: &str, ct: &str) -> bool {\n    let out = std::process::Command::new(\"rustc\").arg(\"--print=crate-types\").arg(format!(\"--target={triple}\")).output();\n    matches!(out, Ok(o) if String::from_utf8_lossy(&o.stdout).lines().any(|l| l.trim()==ct))\n}","typeGuard":"fn is_supported(ct: &str, supported: &[&str]) -> bool { supported.contains(&ct) }","tryCatchPattern":"null","preventionTips":["Gate crate types behind per-target config.","Document the supported targets in the package README.","Run `cargo build --target <t>` in CI for every supported target."],"tags":["cargo","crate-type","cross-compile","target","linker"],"backgroundTag":null,"analyzedSha":"42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}