Skip to content

Commit 902bd62

Browse files
committed
Add MultipleScript (error on stable, error about not implemented on nightly)
1 parent f82860e commit 902bd62

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

crates/cargo-util-schemas/manifest.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,13 @@
549549
{
550550
"description": "Path of Build Script if there's just one script.",
551551
"type": "string"
552+
},
553+
{
554+
"description": "Vector of paths if multiple build script are to be used.",
555+
"type": "array",
556+
"items": {
557+
"type": "string"
558+
}
552559
}
553560
]
554561
},

crates/cargo-util-schemas/src/manifest/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ impl TomlPackage {
260260
TomlPackageBuild::Auto(false) => Ok(None),
261261
TomlPackageBuild::Auto(true) => Err(UnresolvedError),
262262
TomlPackageBuild::SingleScript(value) => Ok(Some(std::slice::from_ref(value))),
263+
TomlPackageBuild::MultipleScript(scripts) => Ok(Some(scripts)),
263264
}
264265
}
265266

@@ -1710,6 +1711,9 @@ pub enum TomlPackageBuild {
17101711

17111712
/// Path of Build Script if there's just one script.
17121713
SingleScript(String),
1714+
1715+
/// Vector of paths if multiple build script are to be used.
1716+
MultipleScript(Vec<String>),
17131717
}
17141718

17151719
impl<'de> Deserialize<'de> for TomlPackageBuild {
@@ -1720,6 +1724,7 @@ impl<'de> Deserialize<'de> for TomlPackageBuild {
17201724
UntaggedEnumVisitor::new()
17211725
.bool(|b| Ok(TomlPackageBuild::Auto(b)))
17221726
.string(|s| Ok(TomlPackageBuild::SingleScript(s.to_owned())))
1727+
.seq(|value| value.deserialize().map(TomlPackageBuild::MultipleScript))
17231728
.deserialize(deserializer)
17241729
}
17251730
}

src/cargo/util/toml/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ fn normalize_toml(
344344
is_embedded,
345345
gctx,
346346
&inherit,
347+
features,
347348
)?;
348349
let package_name = &normalized_package
349350
.normalized_name()
@@ -607,6 +608,7 @@ fn normalize_package_toml<'a>(
607608
is_embedded: bool,
608609
gctx: &GlobalContext,
609610
inherit: &dyn Fn() -> CargoResult<&'a InheritableFields>,
611+
features: &Features,
610612
) -> CargoResult<Box<manifest::TomlPackage>> {
611613
let package_root = manifest_file.parent().unwrap();
612614

@@ -672,7 +674,10 @@ fn normalize_package_toml<'a>(
672674
let build = if is_embedded {
673675
Some(TomlPackageBuild::Auto(false))
674676
} else {
675-
targets::normalize_build(original_package.build.as_ref(), package_root)
677+
if let Some(TomlPackageBuild::MultipleScript(_)) = original_package.build {
678+
features.require(Feature::multiple_build_scripts())?;
679+
}
680+
targets::normalize_build(original_package.build.as_ref(), package_root)?
676681
};
677682
let metabuild = original_package.metabuild.clone();
678683
let default_target = original_package.default_target.clone();

src/cargo/util/toml/targets.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ pub(super) fn to_targets(
105105
if metabuild.is_some() {
106106
anyhow::bail!("cannot specify both `metabuild` and `build`");
107107
}
108+
if custom_build.len() > 1 {
109+
anyhow::bail!("multiple build scripts feature is not implemented yet! ")
110+
}
108111
let custom_build = Path::new(&custom_build[0]);
109112
let name = format!(
110113
"build-script-{}",
@@ -1079,30 +1082,33 @@ Cargo doesn't know which to use because multiple target files found at `{}` and
10791082
pub fn normalize_build(
10801083
build: Option<&TomlPackageBuild>,
10811084
package_root: &Path,
1082-
) -> Option<TomlPackageBuild> {
1085+
) -> CargoResult<Option<TomlPackageBuild>> {
10831086
const BUILD_RS: &str = "build.rs";
10841087
match build {
10851088
None => {
10861089
// If there is a `build.rs` file next to the `Cargo.toml`, assume it is
10871090
// a build script.
10881091
let build_rs = package_root.join(BUILD_RS);
10891092
if build_rs.is_file() {
1090-
Some(TomlPackageBuild::SingleScript(BUILD_RS.to_owned()))
1093+
Ok(Some(TomlPackageBuild::SingleScript(BUILD_RS.to_owned())))
10911094
} else {
1092-
Some(TomlPackageBuild::Auto(false))
1095+
Ok(Some(TomlPackageBuild::Auto(false)))
10931096
}
10941097
}
10951098
// Explicitly no build script.
1096-
Some(TomlPackageBuild::Auto(false)) => build.cloned(),
1099+
Some(TomlPackageBuild::Auto(false)) => Ok(build.cloned()),
10971100
Some(TomlPackageBuild::SingleScript(build_file)) => {
10981101
let build_file = paths::normalize_path(Path::new(build_file));
10991102
let build = build_file.into_os_string().into_string().expect(
11001103
"`build_file` started as a String and `normalize_path` shouldn't have changed that",
11011104
);
1102-
Some(TomlPackageBuild::SingleScript(build))
1105+
Ok(Some(TomlPackageBuild::SingleScript(build)))
11031106
}
11041107
Some(TomlPackageBuild::Auto(true)) => {
1105-
Some(TomlPackageBuild::SingleScript(BUILD_RS.to_owned()))
1108+
Ok(Some(TomlPackageBuild::SingleScript(BUILD_RS.to_owned())))
1109+
}
1110+
Some(TomlPackageBuild::MultipleScript(_scripts)) => {
1111+
anyhow::bail!("multiple build scripts feature is not implemented yet!");
11061112
}
11071113
}
11081114
}

tests/testsuite/bad_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2733,7 +2733,7 @@ fn bad_opt_level() {
27332733
p.cargo("check")
27342734
.with_status(101)
27352735
.with_stderr_data(str![[r#"
2736-
[ERROR] invalid type: integer `3`, expected a boolean or string
2736+
[ERROR] invalid type: integer `3`, expected a boolean, string or array
27372737
--> Cargo.toml:7:25
27382738
|
27392739
7 | build = 3

0 commit comments

Comments
 (0)