rust-lang/cargo · error

cannot compile `{}` as the target `{}` does not support any

Error message

cannot compile `{}` as the target `{}` does not support any of the output crate types

What it means

In calc_outputs_rustc (compilation_files.rs:679-684), the fallback arm of the empty-outputs check: rustc produces NO file types for the unit's target kind, and the unsupported list is empty (so there is nothing specific to name). Cargo reports the target supports none of the output crate types at all.

Source

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

    ) -> 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 {
            let meta = self.metas[unit];
            let meta_opt = meta.c_extra_filename().map(|h| h.to_string());
            let path = out_dir.join(file_type.output_filename(&unit.target, meta_opt.as_deref()));

            // If, the `different_binary_name` feature is enabled, the name of the hardlink will
            // be the name of the binary provided by the user in `Cargo.toml`.
            let hardlink = self.uplift_to(unit, &file_type, &path, bcx);
            let export_path = if unit.target.is_custom_build() {

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Verify the unit's kind (bin/lib/example) is buildable for the target triple.
  2. For proc-macros, build for the host (do not pass `--target`, or use the host triple).
  3. If using a custom target JSON, ensure `data-layout`/`llvm-target`/output fields are correct.
  4. Drop `--target` or switch to a compatible triple.

Example fix

// before
$ cargo build --target thumbv6m-none-eabi --example my-example
error: cannot compile `my-crate` as the target `thumbv6m-none-eabi` does not support any of the output crate types

// after
$ cargo build --example my-example   // build for host
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the unit kind is buildable for the target
if is_proc_macro(&unit) && unit.kind != CompileKind::Host {
    return Err("proc-macros must build for the host target");
}
if !kind_supported_for(unit.target.kind(), triple) {
    return Err(format!("target {triple} supports none of {:?}", unit.target.kind()));
}

Type guard

fn kind_buildable_for(kind: &TargetKind, triple: &str) -> bool {
    supported_kinds_for(triple).iter().any(|k| k == kind)
}

Prevention

When it happens

Trigger: A unit whose target/kind combination yields zero producible output file types on the selected target, with no specific unsupported entry to enumerate — e.g. trying to build a `bin` target on a target/configuration where no bin output type is available, or an example/procmacro on a target that cannot emit those.

Common situations: Building an inappropriate target kind for a triple (e.g. a proc-macro for a non-host target); a misconfigured custom target JSON missing output flavor mappings; `cargo build --target` with a kind incompatible with that triple.

Related errors


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