rust-lang/cargo · error

cannot produce {} for `{}` as the target `{}` does not suppo

Error message

cannot produce {} for `{}` as the target `{}` does not support these crate types

What it means

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.

Source

Thrown at src/compiler/build_runner/compilation_files.rs:671

    /// Computes the actual, full pathnames for all the files generated by rustc.
    ///
    /// The `OutputFile` also contains the paths where those files should be
    /// "uplifted" to.
    fn calc_outputs_rustc(
        &self,
        unit: &Unit,
        bcx: &BuildContext<'a, 'gctx>,
    ) -> CargoResult<Vec<OutputFile>> {
        let out_dir = self.output_dir(unit);

        let info = bcx.target_data.info(unit.kind);
        let triple = bcx.target_data.short_name(&unit.kind);
        let (file_types, unsupported) =
            info.rustc_outputs(unit.mode, unit.target.kind(), triple, bcx.gctx)?;
        if file_types.is_empty() {
            if !unsupported.is_empty() {
                let unsupported_strs: Vec<_> = unsupported.iter().map(|ct| ct.as_str()).collect();
                anyhow::bail!(
                    "cannot produce {} for `{}` as the target `{}` \
                     does not support these crate types",
                    unsupported_strs.join(", "),
                    unit.pkg,
                    triple,
                )
            }
            anyhow::bail!(
                "cannot compile `{}` as the target `{}` does not \
                 support any of the output crate types",
                unit.pkg,
                triple,
            );
        }

        // Convert FileType to OutputFile.
        let mut outputs = Vec::new();
        for file_type in file_types {

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Remove or gate the unsupported crate-type for that target (e.g. use `[target.'cfg(...)'.lib]` or conditional `crate-type`).
  2. Switch the crate-type to one the target supports (e.g. `staticlib`, `rlib`).
  3. Pick a target triple that supports the requested output (e.g. a gnu/linux triple for cdylib).

Example fix

// before (Cargo.toml)
[lib]
crate-type = ["cdylib"]
// building for a target without dynamic lib support -> error

// after
[lib]
crate-type = ["staticlib"]
Defensive patterns

Strategy: validation

Validate before calling

// Validate crate-type vs target capabilities before building
let unsupported = unsupported_crate_types_for(triple);
for ct in &crate_types {
    if unsupported.contains(ct) {
        return Err(format!("target {triple} cannot produce {ct}"));
    }
}

Type guard

fn crate_type_supported(kind: &str, triple: &str) -> bool {
    !unsupported_crate_types_for(triple).contains(&kind)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/6c3d450e485a33e5.json. Report an issue: GitHub.