rust-lang/cargo · error
running a script not depending on an actual script
Error message
running a script not depending on an actual script
What it means
`build_work` finds the build-script unit among a `RunCustomBuild` unit's dependencies via `.find(...).expect("running a script not depending on an actual script")`. A unit scheduled to run a custom build (`unit.mode.is_run_custom_build()`) must, by Cargo's unit-graph construction, have exactly one dependency that is the compiled build script. The panic fires when that dependency edge is missing — the build graph was constructed incorrectly.
Source
Thrown at src/compiler/custom_build.rs:340
}
/// Constructs the unit of work of running a build script.
///
/// The construction includes:
///
/// * Set environment variables for the build script run.
/// * Create the output dir (`OUT_DIR`) for the build script output.
/// * Determine if the build script needs a re-run.
/// * Run the build script and store its output.
fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResult<Job> {
assert!(unit.mode.is_run_custom_build());
let bcx = &build_runner.bcx;
let dependencies = build_runner.unit_deps(unit);
let build_script_unit = dependencies
.iter()
.find(|d| !d.unit.mode.is_run_custom_build() && d.unit.target.is_custom_build())
.map(|d| &d.unit)
.expect("running a script not depending on an actual script");
let script_dir = build_runner.files().build_script_dir(build_script_unit);
let script_out_dir = if bcx.gctx.cli_unstable().build_dir_new_layout {
build_runner.files().out_dir_new_layout(unit)
} else {
build_runner.files().build_script_out_dir(unit)
};
if let Some(deps) = unit.pkg.manifest().metabuild() {
prepare_metabuild(build_runner, build_script_unit, deps)?;
}
// Building the command to execute
let bin_name = if bcx.gctx.cli_unstable().build_dir_new_layout {
unit.target.crate_name()
} else {
unit.target.name().to_string()
};View on GitHub (pinned to 0e07a15537)
Solutions
- Run `cargo clean` to discard any corrupt unit-graph cache and rebuild.
- Update Cargo — unit-graph construction bugs are fixed quickly upstream.
- Minimise the crate's `build.rs`/metabuild usage to isolate whether a specific declaration triggers it; report upstream.
Example fix
// before
let build_script_unit = dependencies
.iter()
.find(|d| !d.unit.mode.is_run_custom_build() && d.unit.target.is_custom_build())
.map(|d| &d.unit)
.expect("running a script not depending on an actual script");
// after
let build_script_unit = dependencies
.iter()
.find(|d| !d.unit.mode.is_run_custom_build() && d.unit.target.is_custom_build())
.map(|d| &d.unit)
.ok_or_else(|| anyhow::anyhow!("RunCustomBuild unit `{}` is missing its build-script dependency", unit.pkg.package_id()))?; Defensive patterns
Strategy: validation
Validate before calling
// (cargo-internal) before scheduling RunCustomBuild, assert the build-script dep edge exists: // assert!(unit_deps.iter().any(|d| d.unit.target.is_custom_build() && !d.unit.mode.is_run_custom_build()));
Prevention
- Run `cargo clean` to discard any corrupt unit-graph state.
- Update Cargo — unit-graph bugs are fixed quickly.
- Isolate whether a specific `build.rs`/metabuild triggers the bug and report it.
When it happens
Trigger: A malformed unit graph where a `RunCustomBuild` unit lacks its compiled-build-script dependency; metabuild setup that failed to insert the script unit; concurrent graph mutation; a Cargo bug in `UnitGraph` construction for crates with `build.rs`.
Common situations: Crate with a `build.rs` (or metabuild) built on a Cargo with a unit-graph regression; `cargo build` after partial `target/` corruption; mixing `cargo` library embedding with its build pipeline.
Related errors
- has_custom_build should have RunCustomBuild
- output must exist after running
- required(true)
- a file should always have a parent
- already loaded without errors
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/c4562d271c3b9445.json.
Report an issue: GitHub.