rust-lang/rust · error · anyhow::Error
found no binary in cargo output
Error message
found no binary in cargo output
What it means
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).
Source
Thrown at src/tools/miri/miri-script/src/util.rs:215
.args(&["--all-targets", "--message-format=json"]);
let output = cmd.output()?;
let mut bin = None;
for line in output.stdout.lines() {
let line = line?;
if line.starts_with("{") {
let json: serde_json::Value = serde_json::from_str(&line)?;
if json["reason"] == "compiler-artifact"
&& !json["profile"]["test"].as_bool().unwrap()
&& !json["executable"].is_null()
{
if bin.is_some() {
bail!("found two binaries in cargo output");
}
bin = Some(PathBuf::from(json["executable"].as_str().unwrap()))
}
}
}
bin.ok_or_else(|| anyhow!("found no binary in cargo output"))
}
pub fn check(
&self,
crate_dir: impl AsRef<OsStr>,
features: &[String],
args: &[String],
) -> Result<()> {
self.cargo_cmd(crate_dir, "check", features).arg("--all-targets").args(args).run()?;
Ok(())
}
pub fn doc(
&self,
crate_dir: impl AsRef<OsStr>,
features: &[String],
args: &[String],
) -> Result<()> {View on GitHub (pinned to 7088e4b63a)
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.
Example fix
// before
bin.ok_or_else(|| anyhow!("found no binary in cargo output"))
// after: include how many artifact lines were seen for diagnosis
bin.ok_or_else(|| {
anyhow!("found no binary in cargo output \
(saw {artifacts_seen} compiler-artifact lines, \
{nontest_exec} with non-test executables)",
artifacts_seen, nontest_exec)
}) Defensive patterns
Strategy: validation
Validate before calling
// Confirm the crate exposes a bin target before building for a binary:
fn has_bin_target(crate_dir: &Path) -> bool {
let o = std::process::Command::new("cargo")
.args(["metadata", "--no-deps", "--format-version=1"])
.current_dir(crate_dir).output();
matches!(o, Ok(out) if String::from_utf8_lossy(&out.stdout).contains("\"kind\": [\"bin\"]")))
} Type guard
null
Try / catch
match util.build_get_binary(crate_dir, features) {
Ok(bin) => Ok(bin),
Err(e) if e.to_string().contains("found no binary") => {
eprintln!("{crate_dir:?} has no bin target; point miri-script at a binary crate");
Err(e)
}
Err(e) => Err(e),
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cargo invocation has failed: ${err}
- No compilation artifacts
- Multiple compilation artifacts are not supported.
- no cargo executable found at `{}`
- Unable to parse transfer manifest
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/6fe3d9b9f3fcae7b.
Report an issue: GitHub.