Skip to content

Commit 778dc4d

Browse files
committed
refactor(toml): Move target build.rs logic next to use
1 parent 807d7ed commit 778dc4d

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,30 +1310,6 @@ impl schema::TomlManifest {
13101310
}
13111311
Ok(patch)
13121312
}
1313-
1314-
/// Returns the path to the build script if one exists for this crate.
1315-
fn maybe_custom_build(
1316-
&self,
1317-
build: &Option<schema::StringOrBool>,
1318-
package_root: &Path,
1319-
) -> Option<PathBuf> {
1320-
let build_rs = package_root.join("build.rs");
1321-
match *build {
1322-
// Explicitly no build script.
1323-
Some(schema::StringOrBool::Bool(false)) => None,
1324-
Some(schema::StringOrBool::Bool(true)) => Some(build_rs),
1325-
Some(schema::StringOrBool::String(ref s)) => Some(PathBuf::from(s)),
1326-
None => {
1327-
// If there is a `build.rs` file next to the `Cargo.toml`, assume it is
1328-
// a build script.
1329-
if build_rs.is_file() {
1330-
Some(build_rs)
1331-
} else {
1332-
None
1333-
}
1334-
}
1335-
}
1336-
}
13371313
}
13381314

13391315
struct Context<'a, 'b> {

src/cargo/util/toml/targets.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub(super) fn targets(
105105
)?);
106106

107107
// processing the custom build script
108-
if let Some(custom_build) = manifest.maybe_custom_build(custom_build, package_root) {
108+
if let Some(custom_build) = maybe_custom_build(custom_build, package_root) {
109109
if metabuild.is_some() {
110110
anyhow::bail!("cannot specify both `metabuild` and `build`");
111111
}
@@ -964,3 +964,23 @@ Cargo doesn't know which to use because multiple target files found at `{}` and
964964
(None, Some(_)) => unreachable!(),
965965
}
966966
}
967+
968+
/// Returns the path to the build script if one exists for this crate.
969+
fn maybe_custom_build(build: &Option<StringOrBool>, package_root: &Path) -> Option<PathBuf> {
970+
let build_rs = package_root.join("build.rs");
971+
match *build {
972+
// Explicitly no build script.
973+
Some(StringOrBool::Bool(false)) => None,
974+
Some(StringOrBool::Bool(true)) => Some(build_rs),
975+
Some(StringOrBool::String(ref s)) => Some(PathBuf::from(s)),
976+
None => {
977+
// If there is a `build.rs` file next to the `Cargo.toml`, assume it is
978+
// a build script.
979+
if build_rs.is_file() {
980+
Some(build_rs)
981+
} else {
982+
None
983+
}
984+
}
985+
}
986+
}

0 commit comments

Comments
 (0)