{"record":{"id":"6fe3d9b9f3fcae7b","repo":"rust-lang/rust","slug":"found-no-binary-in-cargo-output","errorCode":null,"errorMessage":"found no binary in cargo output","messagePattern":"found no binary in cargo output","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/tools/miri/miri-script/src/util.rs","lineNumber":215,"sourceCode":"            .args(&[\"--all-targets\", \"--message-format=json\"]);\n        let output = cmd.output()?;\n        let mut bin = None;\n        for line in output.stdout.lines() {\n            let line = line?;\n            if line.starts_with(\"{\") {\n                let json: serde_json::Value = serde_json::from_str(&line)?;\n                if json[\"reason\"] == \"compiler-artifact\"\n                    && !json[\"profile\"][\"test\"].as_bool().unwrap()\n                    && !json[\"executable\"].is_null()\n                {\n                    if bin.is_some() {\n                        bail!(\"found two binaries in cargo output\");\n                    }\n                    bin = Some(PathBuf::from(json[\"executable\"].as_str().unwrap()))\n                }\n            }\n        }\n        bin.ok_or_else(|| anyhow!(\"found no binary in cargo output\"))\n    }\n\n    pub fn check(\n        &self,\n        crate_dir: impl AsRef<OsStr>,\n        features: &[String],\n        args: &[String],\n    ) -> Result<()> {\n        self.cargo_cmd(crate_dir, \"check\", features).arg(\"--all-targets\").args(args).run()?;\n        Ok(())\n    }\n\n    pub fn doc(\n        &self,\n        crate_dir: impl AsRef<OsStr>,\n        features: &[String],\n        args: &[String],\n    ) -> Result<()> {","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/tools/miri/miri-script/src/util.rs#L197-L233","documentation":"Returned by build_get_binary when parsing cargo's --message-format=json output yields no compiler-artifact message with a non-null executable. The helper expects exactly one binary and errors if zero match (a separate error covers two).","triggerScenarios":"Calling build_get_binary on a crate_dir whose cargo build produces no executable artifact — e.g. the crate is a library, a proc-macro, or all its targets are filtered out (test profile, or only examples/benches that the filter excludes). Also if the build failed silently upstream and emitted no artifact lines.","commonSituations":"Pointing miri-script at a lib crate instead of a binary crate; the binary lives in a workspace member not selected by the build; --all-targets produced only test artifacts which are skipped by the profile.test filter; a misconfigured feature flag that disables the bin target.","solutions":["Confirm the crate_dir actually defines a [[bin]] target with cargo metadata --no-deps.","Ensure features passed to build_get_binary enable (not disable) the binary target.","Run the same cargo build --message-format=json manually and grep for compiler-artifact + executable to see what cargo reports.","If the build failed, fix the underlying compile error first — no artifact is emitted on failure."],"exampleFix":"// before\nbin.ok_or_else(|| anyhow!(\"found no binary in cargo output\"))\n\n// after: include how many artifact lines were seen for diagnosis\nbin.ok_or_else(|| {\n    anyhow!(\"found no binary in cargo output \\\n             (saw {artifacts_seen} compiler-artifact lines, \\\n             {nontest_exec} with non-test executables)\",\n        artifacts_seen, nontest_exec)\n})","handlingStrategy":"validation","validationCode":"// Confirm the crate exposes a bin target before building for a binary:\nfn has_bin_target(crate_dir: &Path) -> bool {\n    let o = std::process::Command::new(\"cargo\")\n        .args([\"metadata\", \"--no-deps\", \"--format-version=1\"])\n        .current_dir(crate_dir).output();\n    matches!(o, Ok(out) if String::from_utf8_lossy(&out.stdout).contains(\"\\\"kind\\\": [\\\"bin\\\"]\")))\n}","typeGuard":"null","tryCatchPattern":"match util.build_get_binary(crate_dir, features) {\n    Ok(bin) => Ok(bin),\n    Err(e) if e.to_string().contains(\"found no binary\") => {\n        eprintln!(\"{crate_dir:?} has no bin target; point miri-script at a binary crate\");\n        Err(e)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Verify the crate_dir defines a [[bin]] target with `cargo metadata --no-deps`.","Make sure features enable (not disable) the binary target.","Fix upstream compile errors first — a failed build emits no artifact."],"tags":["miri","cargo","build-artifact","json"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}