rust-lang/cargo · error
target must support `bin`
Error message
target must support `bin`
What it means
`bin_target_destination` asks `info.rustc_outputs(CompileMode::Build, &TargetKind::Bin, ...).expect("target must support \`bin\`")` for the file types a target produces for a binary. The call has already been used to build bins for this target elsewhere, so it is expected to yield `Some`. The panic means rustc reported that this target does not produce any output file types for `bin` — i.e. the target cannot emit binaries.
Source
Thrown at src/compiler/build_runner/compilation_files.rs:425
pub fn bin_link_for_target(
&self,
target: &Target,
kind: CompileKind,
bcx: &BuildContext<'_, '_>,
) -> CargoResult<Option<PathBuf>> {
assert!(target.is_bin());
let Some(dest) = self.layout(kind).artifact_dir().map(|v| v.dest()) else {
return Ok(None);
};
let info = bcx.target_data.info(kind);
let (file_types, _) = info
.rustc_outputs(
CompileMode::Build,
&TargetKind::Bin,
bcx.target_data.short_name(&kind),
bcx.gctx,
)
.expect("target must support `bin`");
let file_type = file_types
.iter()
.find(|file_type| file_type.flavor == FileFlavor::Normal)
.expect("target must support `bin`");
Ok(Some(dest.join(file_type.uplift_filename(target))))
}
/// Returns the filenames that the given unit will generate.
///
/// Note: It is not guaranteed that all of the files will be generated.
pub(super) fn outputs(
&self,
unit: &Unit,
bcx: &BuildContext<'a, 'gctx>,
) -> CargoResult<Arc<Vec<OutputFile>>> {
self.outputs[unit]View on GitHub (pinned to 0e07a15537)
Solutions
- Confirm the target actually supports binaries: `rustc --print target-list` and the target's `target-pointer-width`/`os` spec.
- If using a custom JSON target, ensure its `arch`/`os`/`linker-flavor` produce a binary file type, or avoid `--artifact-dir` uplift for it.
- Pin a toolchain where this target was known to work.
Example fix
// before
let (file_types, _) = info
.rustc_outputs(CompileMode::Build, &TargetKind::Bin, bcx.target_data.short_name(&kind), bcx.gctx)
.expect("target must support `bin`");
// after
let (file_types, _) = info
.rustc_outputs(CompileMode::Build, &TargetKind::Bin, bcx.target_data.short_name(&kind), bcx.gctx)
.ok_or_else(|| anyhow::anyhow!("target `{}` does not support `bin` artifacts", bcx.target_data.short_name(&kind)))?; Defensive patterns
Strategy: validation
Validate before calling
// Confirm the target triple supports binaries before requesting artifact-dir uplift
use std::process::Command;
fn target_supports_bin(target: &str) -> bool {
let out = Command::new("rustc").args(["--print", "target-list"]).output();
matches!(out, Ok(o) if String::from_utf8_lossy(&o.stdout).lines().any(|l| l == target))
} Prevention
- Validate custom JSON targets include binary-producing `linker-flavor`/`os`.
- Avoid `--artifact-dir` uplift for tier-3 targets you have not tested.
- Pin a toolchain known to support your target.
When it happens
Trigger: A target triple whose rustc target spec declares no binary file types (a `no-bin` target spec, or a target whose only outputs are libraries); an `--artifact-dir` uplift requested for a bin on a target that does not support bin artifacts; mismatched rustc/target-data after a partial sysroot change.
Common situations: Using a custom target JSON (`--target ./spec.json`) that omits binary output; cross-compiling to a tier-3 / bare-metal target that lacks bin support; nightly target-spec changes that altered binary emission.
Related errors
- output of --print={request} missing when learning about targ
- cannot produce {} for `{}` as the target `{}` does not suppo
- cannot compile `{}` as the target `{}` does not support any
- could not find specification for target `{target}`. Depend
- dependency `{}` in package `{}` requires a `{}` artifact to
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/5a191ed9dc42dfbf.json.
Report an issue: GitHub.