{"id":"c4562d271c3b9445","repo":"rust-lang/cargo","slug":"running-a-script-not-depending-on-an-actual-script","errorCode":null,"errorMessage":"running a script not depending on an actual script","messagePattern":"running a script not depending on an actual script","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/custom_build.rs","lineNumber":340,"sourceCode":"}\n\n/// Constructs the unit of work of running a build script.\n///\n/// The construction includes:\n///\n/// * Set environment variables for the build script run.\n/// * Create the output dir (`OUT_DIR`) for the build script output.\n/// * Determine if the build script needs a re-run.\n/// * Run the build script and store its output.\nfn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResult<Job> {\n    assert!(unit.mode.is_run_custom_build());\n    let bcx = &build_runner.bcx;\n    let dependencies = build_runner.unit_deps(unit);\n    let build_script_unit = dependencies\n        .iter()\n        .find(|d| !d.unit.mode.is_run_custom_build() && d.unit.target.is_custom_build())\n        .map(|d| &d.unit)\n        .expect(\"running a script not depending on an actual script\");\n    let script_dir = build_runner.files().build_script_dir(build_script_unit);\n\n    let script_out_dir = if bcx.gctx.cli_unstable().build_dir_new_layout {\n        build_runner.files().out_dir_new_layout(unit)\n    } else {\n        build_runner.files().build_script_out_dir(unit)\n    };\n\n    if let Some(deps) = unit.pkg.manifest().metabuild() {\n        prepare_metabuild(build_runner, build_script_unit, deps)?;\n    }\n\n    // Building the command to execute\n    let bin_name = if bcx.gctx.cli_unstable().build_dir_new_layout {\n        unit.target.crate_name()\n    } else {\n        unit.target.name().to_string()\n    };","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/compiler/custom_build.rs#L322-L358","documentation":"`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.","triggerScenarios":"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`.","commonSituations":"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.","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."],"exampleFix":"// before\nlet build_script_unit = dependencies\n    .iter()\n    .find(|d| !d.unit.mode.is_run_custom_build() && d.unit.target.is_custom_build())\n    .map(|d| &d.unit)\n    .expect(\"running a script not depending on an actual script\");\n// after\nlet build_script_unit = dependencies\n    .iter()\n    .find(|d| !d.unit.mode.is_run_custom_build() && d.unit.target.is_custom_build())\n    .map(|d| &d.unit)\n    .ok_or_else(|| anyhow::anyhow!(\"RunCustomBuild unit `{}` is missing its build-script dependency\", unit.pkg.package_id()))?;","handlingStrategy":"validation","validationCode":"// (cargo-internal) before scheduling RunCustomBuild, assert the build-script dep edge exists:\n// assert!(unit_deps.iter().any(|d| d.unit.target.is_custom_build() && !d.unit.mode.is_run_custom_build()));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cargo","build-scripts","unit-graph","metabuild","internal-invariant"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}