Add multi-build script support to cargo vendor

This commit is contained in:
Naman Garg 2025-06-20 03:17:46 +05:30
parent 21c2f1615d
commit 5c7f68fe5d
No known key found for this signature in database
2 changed files with 27 additions and 23 deletions

View File

@ -514,25 +514,31 @@ fn prepare_toml_for_vendor(
.package
.as_mut()
.expect("venedored manifests must have packages");
// Validates if build script file exists. If not, warn and ignore.
if let Some(TomlPackageBuild::SingleScript(path)) = &package.build {
let path = paths::normalize_path(Path::new(path));
let included = packaged_files.contains(&path);
let build = if included {
let path = path
.into_os_string()
.into_string()
.map_err(|_err| anyhow::format_err!("non-UTF8 `package.build`"))?;
let path = crate::util::toml::normalize_path_string_sep(path);
TomlPackageBuild::SingleScript(path)
} else {
gctx.shell().warn(format!(
"ignoring `package.build` as `{}` is not included in the published package",
path.display()
))?;
TomlPackageBuild::Auto(false)
};
package.build = Some(build);
// Validates if build script file is included in package. If not, warn and ignore.
if let Some(custom_build_scripts) = package.normalized_build().expect("previously normalized") {
let mut included_scripts = Vec::new();
for script in custom_build_scripts {
let path = paths::normalize_path(Path::new(script));
let included = packaged_files.contains(&path);
if included {
let path = path
.into_os_string()
.into_string()
.map_err(|_err| anyhow::format_err!("non-UTF8 `package.build`"))?;
let path = crate::util::toml::normalize_path_string_sep(path);
included_scripts.push(path);
} else {
gctx.shell().warn(format!(
"ignoring `package.build` entry `{}` as it is not included in the published package",
path.display()
))?;
}
}
package.build = Some(match included_scripts.len() {
0 => TomlPackageBuild::Auto(false),
1 => TomlPackageBuild::SingleScript(included_scripts[0].clone()),
_ => TomlPackageBuild::MultipleScript(included_scripts),
});
}
let lib = if let Some(target) = &me.lib {

View File

@ -353,6 +353,7 @@ fn verify_vendor_multiple_build_scripts() {
[UPDATING] git repository `[ROOTURL]/dep`
[LOCKING] 1 package to latest [..] compatible version
Vendoring dep v0.1.0 ([ROOTURL]/dep#[..]) ([ROOT]/home/.cargo/git/checkouts/dep-[HASH]/[..]) to vendor/dep
[WARNING] ignoring `package.build` entry `build2.rs` as it is not included in the published package
To use vendored sources, add this to your .cargo/config.toml for this project:
@ -381,10 +382,7 @@ edition = "2024"
name = "dep"
version = "0.1.0"
authors = []
build = [
"build1.rs",
"build2.rs",
]
build = "build1.rs"
include = [
"src/main.rs",
"build1.rs",