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
Same code path as 23 but stricter: `rustc_outputs` returned empty `file_types` AND empty `unsupported`. The target produces none of the requested output types and Cargo cannot even enumerate which were rejected — it can only state the target supports no requested output crate type at all.
Solutions
- For proc-macro crates, ensure they build for the host: do not pass `--target` or add `package = { ... }` with a host-only build.
- Populate `[lib] crate-type` with at least `rlib`/`lib` which is universally supported.
- Switch to a well-formed target triple or fix the custom target JSON.
- Run `cargo build -vv` and check the underlying rustc invocation.
Example fix
// before [lib] crate-type = [] // after [lib] crate-type = ["rlib"]
Defensive patterns
Strategy: validation
Validate before calling
fn has_any_output_type(crate_types: &[String], target_supported: &[String]) -> bool {
crate_types.iter().any(|c| target_supported.iter().any(|s| s == c))
} Type guard
fn is_proc_macro_for_host(kind: CompileKind, target_kind: &str) -> bool {
target_kind == "proc-macro" && !kind.is_host()
} Try / catch
null
Prevention
- Always include a universally supported type like `rlib` in `crate-type`.
- Build proc-macro crates only for the host.
- Validate custom target JSON with `rustc --print=target-spec-json`.
When it happens
Trigger: Building a `[lib]` with `crate-type` entries that are universally unsupported by the target (e.g. requesting `proc-macro` for a non-host target, or all types filtered out by mode/target combination).
Common situations: Building proc-macro crates for a cross target (proc-macros must compile for the host); empty `crate-type = []` combined with an unusual mode; target spec missing `target-c-int-width`/data-layout causing rustc to refuse all outputs.
Related errors
- cannot produce for ` ` as the target ` ` does not support…
- cannot mix `proc-macro` crate type with others
- could not find specification for target
- library ` ` cannot set the crate type of both `dylib` and…
- malformed output when learning about crate-type
AI-assisted analysis of rust-lang/cargo@42eee92bc9 (2026-08-11).
Data as JSON: /api/errors/2076ca142a3f73aa.
Report an issue: GitHub.
Appendix: source
Thrown at src/compiler/build_runner/compilation_files.rs:684
) -> 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 {
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 42eee92bc9)