rust-lang/cargo · error
invalid `package.build` file name
Error message
invalid `package.build` file name
What it means
`validate_build_name` checks that each path in `package.build` has a non-None `file_stem()`. A path with no stem (`""`, `"."`, `"/"`, trailing separator only) is meaningless as a build script name and is rejected before target generation.
Solutions
- Set `build` to a real script path such as `"build.rs"`.
- Remove the `build` key entirely to use the default `build.rs` convention.
- Validate the path is non-empty before writing the manifest.
Example fix
# before [package] build = "" # after [package] build = "build.rs"
Defensive patterns
Strategy: validation
Validate before calling
fn valid_build_name(build: &str) -> bool {
std::path::Path::new(build).file_stem().is_some()
}
// reject empty/dot/slash-only values before writing the manifest Prevention
- Never set `build` to an empty string or placeholder.
- Prefer omitting `build` to use the default `build.rs`.
- Sanitize templated manifest values before rendering.
When it happens
Trigger: `[package] build = ""`, `build = "."`, or any value whose `Path::file_stem()` returns `None`. The guard at targets.rs:1138 fires.
Common situations: Empty string from a templating/env-substitution mistake. Accidentally leaving `build` with a placeholder. Misconfigured build tooling that injects an empty path.
Related errors
- found build scripts with duplicate file stems, but all…
- cannot specify both `metabuild` and `build`
- found duplicate name , but all targets must have a unique…
- target .name is required
- target names cannot be empty
AI-assisted analysis of rust-lang/cargo@eb98b54bc9 (2026-08-11).
Data as JSON: /api/errors/e00d62de0e56e950.
Report an issue: GitHub.
Appendix: source
Thrown at src/workspace/parser/targets.rs:1136
"`build_file` started as a String and `normalize_path` shouldn't have changed that",
);
Ok(Some(TomlPackageBuild::SingleScript(build)))
}
Some(TomlPackageBuild::Auto(true)) => {
Ok(Some(TomlPackageBuild::SingleScript(BUILD_RS.to_owned())))
}
Some(TomlPackageBuild::MultipleScript(scripts)) => {
for script in scripts {
validate_build_name(script)?;
}
Ok(build.cloned())
}
}
}
fn validate_build_name(build: &str) -> CargoResult<()> {
if Path::new(build).file_stem().is_none() {
anyhow::bail!("invalid `package.build` file name");
}
Ok(())
}
fn name_or_panic(target: &TomlTarget) -> &str {
target
.name
.as_deref()
.unwrap_or_else(|| panic!("target name is required"))
}
fn validate_lib_name(target: &TomlTarget, warnings: &mut Vec<String>) -> CargoResult<()> {
validate_target_name(target, TARGET_KIND_HUMAN_LIB, TARGET_KIND_LIB, warnings)?;
let name = name_or_panic(target);
if name.contains('-') {
anyhow::bail!("library target names cannot contain hyphens: {}", name)
}
View on GitHub (pinned to eb98b54bc9)