{"id":"5a191ed9dc42dfbf","repo":"rust-lang/cargo","slug":"target-must-support-bin","errorCode":null,"errorMessage":"target must support `bin`","messagePattern":"target must support `bin`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/build_runner/compilation_files.rs","lineNumber":425,"sourceCode":"    pub fn bin_link_for_target(\n        &self,\n        target: &Target,\n        kind: CompileKind,\n        bcx: &BuildContext<'_, '_>,\n    ) -> CargoResult<Option<PathBuf>> {\n        assert!(target.is_bin());\n        let Some(dest) = self.layout(kind).artifact_dir().map(|v| v.dest()) else {\n            return Ok(None);\n        };\n        let info = bcx.target_data.info(kind);\n        let (file_types, _) = info\n            .rustc_outputs(\n                CompileMode::Build,\n                &TargetKind::Bin,\n                bcx.target_data.short_name(&kind),\n                bcx.gctx,\n            )\n            .expect(\"target must support `bin`\");\n\n        let file_type = file_types\n            .iter()\n            .find(|file_type| file_type.flavor == FileFlavor::Normal)\n            .expect(\"target must support `bin`\");\n\n        Ok(Some(dest.join(file_type.uplift_filename(target))))\n    }\n\n    /// Returns the filenames that the given unit will generate.\n    ///\n    /// Note: It is not guaranteed that all of the files will be generated.\n    pub(super) fn outputs(\n        &self,\n        unit: &Unit,\n        bcx: &BuildContext<'a, 'gctx>,\n    ) -> CargoResult<Arc<Vec<OutputFile>>> {\n        self.outputs[unit]","sourceCodeStart":407,"sourceCodeEnd":443,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/compiler/build_runner/compilation_files.rs#L407-L443","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nlet (file_types, _) = info\n    .rustc_outputs(CompileMode::Build, &TargetKind::Bin, bcx.target_data.short_name(&kind), bcx.gctx)\n    .expect(\"target must support `bin`\");\n// after\nlet (file_types, _) = info\n    .rustc_outputs(CompileMode::Build, &TargetKind::Bin, bcx.target_data.short_name(&kind), bcx.gctx)\n    .ok_or_else(|| anyhow::anyhow!(\"target `{}` does not support `bin` artifacts\", bcx.target_data.short_name(&kind)))?;","handlingStrategy":"validation","validationCode":"// Confirm the target triple supports binaries before requesting artifact-dir uplift\nuse std::process::Command;\nfn target_supports_bin(target: &str) -> bool {\n    let out = Command::new(\"rustc\").args([\"--print\", \"target-list\"]).output();\n    matches!(out, Ok(o) if String::from_utf8_lossy(&o.stdout).lines().any(|l| l == target))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cargo","target","cross-compile","binaries","internal-invariant"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}