Skip to content

Commit c01a8bd

Browse files
committed
Add multi-build script support to cargo vendor
1 parent 783c24b commit c01a8bd

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

src/cargo/ops/vendor.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -514,25 +514,31 @@ fn prepare_toml_for_vendor(
514514
.package
515515
.as_mut()
516516
.expect("venedored manifests must have packages");
517-
// Validates if build script file exists. If not, warn and ignore.
518-
if let Some(TomlPackageBuild::SingleScript(path)) = &package.build {
519-
let path = paths::normalize_path(Path::new(path));
520-
let included = packaged_files.contains(&path);
521-
let build = if included {
522-
let path = path
523-
.into_os_string()
524-
.into_string()
525-
.map_err(|_err| anyhow::format_err!("non-UTF8 `package.build`"))?;
526-
let path = crate::util::toml::normalize_path_string_sep(path);
527-
TomlPackageBuild::SingleScript(path)
528-
} else {
529-
gctx.shell().warn(format!(
530-
"ignoring `package.build` as `{}` is not included in the published package",
531-
path.display()
532-
))?;
533-
TomlPackageBuild::Auto(false)
534-
};
535-
package.build = Some(build);
517+
// Validates if build script file is included in package. If not, warn and ignore.
518+
if let Some(custom_build_scripts) = package.normalized_build().expect("previously normalized") {
519+
let mut included_scripts = Vec::new();
520+
for script in custom_build_scripts {
521+
let path = paths::normalize_path(Path::new(script));
522+
let included = packaged_files.contains(&path);
523+
if included {
524+
let path = path
525+
.into_os_string()
526+
.into_string()
527+
.map_err(|_err| anyhow::format_err!("non-UTF8 `package.build`"))?;
528+
let path = crate::util::toml::normalize_path_string_sep(path);
529+
included_scripts.push(path);
530+
} else {
531+
gctx.shell().warn(format!(
532+
"ignoring `package.build` entry `{}` as it is not included in the published package",
533+
path.display()
534+
))?;
535+
}
536+
}
537+
package.build = Some(match included_scripts.len() {
538+
0 => TomlPackageBuild::Auto(false),
539+
1 => TomlPackageBuild::SingleScript(included_scripts[0].clone()),
540+
_ => TomlPackageBuild::MultipleScript(included_scripts),
541+
});
536542
}
537543

538544
let lib = if let Some(target) = &me.lib {

tests/testsuite/build_scripts_multiple.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ fn verify_vendor_multiple_build_scripts() {
353353
[UPDATING] git repository `[ROOTURL]/dep`
354354
[LOCKING] 1 package to latest [..] compatible version
355355
Vendoring dep v0.1.0 ([ROOTURL]/dep#[..]) ([ROOT]/home/.cargo/git/checkouts/dep-[HASH]/[..]) to vendor/dep
356+
[WARNING] ignoring `package.build` entry `build2.rs` as it is not included in the published package
356357
To use vendored sources, add this to your .cargo/config.toml for this project:
357358
358359
@@ -381,10 +382,7 @@ edition = "2024"
381382
name = "dep"
382383
version = "0.1.0"
383384
authors = []
384-
build = [
385-
"build1.rs",
386-
"build2.rs",
387-
]
385+
build = "build1.rs"
388386
include = [
389387
"src/main.rs",
390388
"build1.rs",

0 commit comments

Comments
 (0)