rust-lang/cargo · error

cannot produce for ` ` as the target ` ` does not support…

Error message

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

What it means

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.

Solutions

  1. Scope crate types per target using `[lib] crate-type` overrides or `cargo:rustc-crate-type` rules in `.cargo/config.toml` per-target sections.
  2. Drop the unsupported crate type from the package or move it behind a feature flag.
  3. Switch to a target that supports the requested output types (e.g. a GNU/Linux or MSVC triple for `dylib`).
  4. Verify with `rustc --print=crate-types --target <triple>` what the target actually supports.

Example fix

// before
# Cargo.toml
[lib]
crate-type = ["cdylib"]

// after (per-target override in .cargo/config.toml)
[target.wasm32-unknown-unknown]
# build as rlib instead, or conditionally compile
Defensive patterns

Strategy: validation

Validate before calling

fn target_supports_crate_type(triple: &str, ct: &str) -> bool {
    let out = std::process::Command::new("rustc").arg("--print=crate-types").arg(format!("--target={triple}")).output();
    matches!(out, Ok(o) if String::from_utf8_lossy(&o.stdout).lines().any(|l| l.trim()==ct))
}

Type guard

fn is_supported(ct: &str, supported: &[&str]) -> bool { supported.contains(&ct) }

Try / catch

null

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of rust-lang/cargo@42eee92bc9 (2026-08-11). Data as JSON: /api/errors/6c3d450e485a33e5. Report an issue: GitHub.

Appendix: source

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

    /// 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)?;
        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 42eee92bc9)