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 .package
.as_mut() .as_mut()
.expect("venedored manifests must have packages"); .expect("venedored manifests must have packages");
// Validates if build script file exists. If not, warn and ignore. // Validates if build script file is included in package. If not, warn and ignore.
if let Some(TomlPackageBuild::SingleScript(path)) = &package.build { if let Some(custom_build_scripts) = package.normalized_build().expect("previously normalized") {
let path = paths::normalize_path(Path::new(path)); let mut included_scripts = Vec::new();
let included = packaged_files.contains(&path); for script in custom_build_scripts {
let build = if included { let path = paths::normalize_path(Path::new(script));
let path = path let included = packaged_files.contains(&path);
.into_os_string() if included {
.into_string() let path = path
.map_err(|_err| anyhow::format_err!("non-UTF8 `package.build`"))?; .into_os_string()
let path = crate::util::toml::normalize_path_string_sep(path); .into_string()
TomlPackageBuild::SingleScript(path) .map_err(|_err| anyhow::format_err!("non-UTF8 `package.build`"))?;
} else { let path = crate::util::toml::normalize_path_string_sep(path);
gctx.shell().warn(format!( included_scripts.push(path);
"ignoring `package.build` as `{}` is not included in the published package", } else {
path.display() gctx.shell().warn(format!(
))?; "ignoring `package.build` entry `{}` as it is not included in the published package",
TomlPackageBuild::Auto(false) path.display()
}; ))?;
package.build = Some(build); }
}
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 { 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` [UPDATING] git repository `[ROOTURL]/dep`
[LOCKING] 1 package to latest [..] compatible version [LOCKING] 1 package to latest [..] compatible version
Vendoring dep v0.1.0 ([ROOTURL]/dep#[..]) ([ROOT]/home/.cargo/git/checkouts/dep-[HASH]/[..]) to vendor/dep 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: To use vendored sources, add this to your .cargo/config.toml for this project:
@ -381,10 +382,7 @@ edition = "2024"
name = "dep" name = "dep"
version = "0.1.0" version = "0.1.0"
authors = [] authors = []
build = [ build = "build1.rs"
"build1.rs",
"build2.rs",
]
include = [ include = [
"src/main.rs", "src/main.rs",
"build1.rs", "build1.rs",