{"id":"a252d45af7ada73c","repo":"rust-lang/cargo","slug":"could-not-find-specification-for-target-target","errorCode":null,"errorMessage":"could not find specification for target `{target}`.\n  Dependency `{dependency}` requires to build for target `{target}`.","messagePattern":"could not find specification for target `(.+?)`\\.\n  Dependency `(.+?)` requires to build for target `(.+?)`\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/compilation.rs","lineNumber":506,"sourceCode":"fn get_sysroot_target_libdir(\n    bcx: &BuildContext<'_, '_>,\n) -> CargoResult<HashMap<CompileKind, PathBuf>> {\n    bcx.all_kinds\n        .iter()\n        .map(|&kind| {\n            let Some(info) = bcx.target_data.get_info(kind) else {\n                let target = match kind {\n                    CompileKind::Host => \"host\".to_owned(),\n                    CompileKind::Target(s) => s.short_name().to_owned(),\n                };\n\n                let dependency = bcx\n                    .unit_graph\n                    .iter()\n                    .find_map(|(u, _)| (u.kind == kind).then_some(u.pkg.summary().package_id()))\n                    .unwrap();\n\n                anyhow::bail!(\n                    \"could not find specification for target `{target}`.\\n  \\\n                    Dependency `{dependency}` requires to build for target `{target}`.\"\n                )\n            };\n\n            Ok((kind, info.sysroot_target_libdir.clone()))\n        })\n        .collect()\n}\n\nfn target_runner(\n    bcx: &BuildContext<'_, '_>,\n    kind: CompileKind,\n) -> CargoResult<Option<(PathBuf, Vec<String>)>> {\n    if let Some(runner) = bcx.target_data.target_config(kind).runner.as_ref() {\n        let path = runner.val.path.clone().resolve_program(bcx.gctx);\n        return Ok(Some((path, runner.val.args.clone())));\n    }","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/compiler/compilation.rs#L488-L524","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n$ cargo build --target aarch64-unknown-linux-gnu\nerror: could not find specification for target `aarch64-unknown-linux-gnu`.\n\n// after\n$ rustup target add aarch64-unknown-linux-gnu && cargo build --target aarch64-unknown-linux-gnu","handlingStrategy":"validation","validationCode":"let installed: Vec<String> = rustup_installed_targets();\nif !installed.iter().any(|t| t == target) && !Path::new(target).is_file() {\n    return Err(format!(\"target `{target}` not installed/found; rustup target add {target}\"));\n}","typeGuard":"fn target_available(triple: &str, installed: &[String], json_exists: bool) -> bool {\n    installed.iter().any(|t| t == triple) || json_exists\n}\n","tryCatchPattern":null,"preventionTips":["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."],"tags":["cargo","build","cross-compile","toolchain","target"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}