rust-lang/cargo · error
could not find specification for target `{target}`. Depend
Error message
could not find specification for target `{target}`.
Dependency `{dependency}` requires to build for target `{target}`. What it means
In get_sysroot_target_libdir (compilation.rs:488-515), Cargo needs target info for each CompileKind in the build. If `bcx.target_data.get_info(kind)` returns None, the target specification could not be loaded — typically the target triple is not installed or is unknown — and Cargo bails naming the missing target and the dependency that forced building for it.
Source
Thrown at src/compiler/compilation.rs:506
fn get_sysroot_target_libdir(
bcx: &BuildContext<'_, '_>,
) -> CargoResult<HashMap<CompileKind, PathBuf>> {
bcx.all_kinds
.iter()
.map(|&kind| {
let Some(info) = bcx.target_data.get_info(kind) else {
let target = match kind {
CompileKind::Host => "host".to_owned(),
CompileKind::Target(s) => s.short_name().to_owned(),
};
let dependency = bcx
.unit_graph
.iter()
.find_map(|(u, _)| (u.kind == kind).then_some(u.pkg.summary().package_id()))
.unwrap();
anyhow::bail!(
"could not find specification for target `{target}`.\n \
Dependency `{dependency}` requires to build for target `{target}`."
)
};
Ok((kind, info.sysroot_target_libdir.clone()))
})
.collect()
}
fn target_runner(
bcx: &BuildContext<'_, '_>,
kind: CompileKind,
) -> CargoResult<Option<(PathBuf, Vec<String>)>> {
if let Some(runner) = bcx.target_data.target_config(kind).runner.as_ref() {
let path = runner.val.path.clone().resolve_program(bcx.gctx);
return Ok(Some((path, runner.val.args.clone())));
}View on GitHub (pinned to 0e07a15537)
Solutions
- Install the target: `rustup target add <triple>`.
- Fix the triple spelling in `--target`, `[build] target`, or `target.<triple>.*` config.
- If using a custom JSON target, pass `--target path/to/target.json` and ensure the file exists.
- Remove/adjust the dependency that forces the unavailable target.
Example fix
// before $ cargo build --target aarch64-unknown-linux-gnu error: could not find specification for target `aarch64-unknown-linux-gnu`. // after $ rustup target add aarch64-unknown-linux-gnu && cargo build --target aarch64-unknown-linux-gnu
Defensive patterns
Strategy: validation
Validate before calling
let installed: Vec<String> = rustup_installed_targets();
if !installed.iter().any(|t| t == target) && !Path::new(target).is_file() {
return Err(format!("target `{target}` not installed/found; rustup target add {target}"));
} Type guard
fn target_available(triple: &str, installed: &[String], json_exists: bool) -> bool {
installed.iter().any(|t| t == triple) || json_exists
}
Prevention
- Pre-install all required targets in CI via `rustup target add`.
- Validate --target spelling against `rustup target list`.
- Resolve custom JSON target paths relative to the manifest.
When it happens
Trigger: A dependency or `--target <triple>` requires a target whose std/component is not installed, or whose custom target JSON cannot be found/parsed. The dependency's build-resolver forces the kind, but no target spec is registered for it.
Common situations: Cross-compiling without `rustup target add <triple>`; a dependency with a `target.<triple>.dependencies` entry for an unavailable target; a typo in the triple; a custom target JSON path that does not resolve.
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
- malformed output when learning about crate-type {} informati
- target must support `bin`
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/a252d45af7ada73c.json.
Report an issue: GitHub.