{"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":671,"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, bcx.gctx)?;\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":653,"sourceCodeEnd":689,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/compiler/build_runner/compilation_files.rs#L653-L689","documentation":"In calc_outputs_rustc (compilation_files.rs:666-678), Cargo computes the file types rustc will produce for a unit. If `rustc_outputs` returns no producible file types but there ARE unsupported crate types (e.g. the package requests `crate-type = [\"cdylib\",\"bin\"]` but the target triple can't produce cdylib), Cargo bails naming the unsupported crate types, the package, and the target.","triggerScenarios":"A package whose `[lib] crate-type` includes a type the target does not support (e.g. `cdylib` on a target without dynamic library support, or `dylib` on a `*-none`/bare-metal target), while at least one requested type is in the unsupported list.","commonSituations":"Cross-compiling a cdylib crate to a bare-metal or wasm target that lacks that output kind; enabling `crate-type` values conditionally without gating on target; depending on a crate that forces an unsupported type.","solutions":["Remove or gate the unsupported crate-type for that target (e.g. use `[target.'cfg(...)'.lib]` or conditional `crate-type`).","Switch the crate-type to one the target supports (e.g. `staticlib`, `rlib`).","Pick a target triple that supports the requested output (e.g. a gnu/linux triple for cdylib)."],"exampleFix":"// before (Cargo.toml)\n[lib]\ncrate-type = [\"cdylib\"]\n// building for a target without dynamic lib support -> error\n\n// after\n[lib]\ncrate-type = [\"staticlib\"]","handlingStrategy":"validation","validationCode":"// Validate crate-type vs target capabilities before building\nlet unsupported = unsupported_crate_types_for(triple);\nfor ct in &crate_types {\n    if unsupported.contains(ct) {\n        return Err(format!(\"target {triple} cannot produce {ct}\"));\n    }\n}","typeGuard":"fn crate_type_supported(kind: &str, triple: &str) -> bool {\n    !unsupported_crate_types_for(triple).contains(&kind)\n}\n","tryCatchPattern":null,"preventionTips":["Gate crate-type on target with cfg-conditionals in Cargo.toml.","Maintain a target capability matrix for cross builds.","Prefer target-portable crate-types (rlib, staticlib) when possible."],"tags":["cargo","build","crate-type","cross-compile","target"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}