{"record":{"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/42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9/src/compiler/compilation.rs#L488-L524","documentation":"A dependency requires building for a target (`CompileKind::Target(s)` or Host) whose spec is not present in `target_data`. Cargo resolved the unit graph but cannot find a target specification (no rustc target spec loaded for that triple), so it bails with the dependency and target names.","triggerScenarios":"Passing `--target <triple>` for an unknown/uninstalled target; a dependency's build-script or proc-macro forces a kind whose spec wasn't loaded; `.cargo/config.toml` references a target not installed via rustup.","commonSituations":"Forgetting `rustup target add <triple>`; typos in `build.target`; custom target JSON path wrong; CI missing target components.","solutions":["Install the target: `rustup target add <triple>`.","Verify the triple spelling matches `rustc --print=target-list`.","For custom targets, pass the full path: `--target ./specs/foo.json`.","Remove or correct the `build.target` entry in `.cargo/config.toml`."],"exampleFix":"// before\ncargo build --target aarch64-unkown-linux-gnu   # typo\n\n// after\nrustup target add aarch64-unknown-linux-gnu\ncargo build --target aarch64-unknown-linux-gnu","handlingStrategy":"validation","validationCode":"fn target_installed(triple: &str) -> bool {\n    let out = std::process::Command::new(\"rustup\").args([\"target\", \"list\", \"--installed\"]).output();\n    matches!(out, Ok(o) if String::from_utf8_lossy(&o.stdout).lines().any(|l| l.trim()==triple))\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Run `rustup target list --installed` in CI boot and assert the required triple.","Use `rustc --print=target-list` to confirm spelling before passing `--target`.","Keep a project-level `rust-toolchain.toml` that lists required components."],"tags":["cargo","target","cross-compile","rustup","dependency"],"backgroundTag":null,"analyzedSha":"42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}