Skip to content

Commit 40fbf42

Browse files
committed
refactor(build): use platforms to verify RUSTUP_OVERRIDE_BUILD_TRIPLE
1 parent 221fd61 commit 40fbf42

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ trycmd = "0.15.0"
126126

127127
[build-dependencies]
128128
once_cell.workspace = true
129+
platforms = "3.4"
129130
regex = "1"
130131

131132
[workspace]

build.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
use std::env;
22

3-
include!("src/dist/triple.rs");
3+
use platforms::Platform;
44

5-
fn from_build() -> Result<PartialTargetTriple, String> {
5+
fn from_build() -> Result<String, String> {
66
let triple =
77
env::var("RUSTUP_OVERRIDE_BUILD_TRIPLE").unwrap_or_else(|_| env::var("TARGET").unwrap());
8-
PartialTargetTriple::new(&triple).ok_or(triple)
8+
if Platform::ALL.iter().any(|p| p.target_triple == triple) {
9+
Ok(triple)
10+
} else {
11+
Err(triple)
12+
}
913
}
1014

1115
fn main() {
1216
println!("cargo:rerun-if-env-changed=RUSTUP_OVERRIDE_BUILD_TRIPLE");
1317
println!("cargo:rerun-if-env-changed=TARGET");
1418
match from_build() {
15-
Ok(triple) => eprintln!("Computed build based partial target triple: {triple:#?}"),
19+
Ok(triple) => eprintln!("Computed build based on target triple: {triple:#?}"),
1620
Err(s) => {
17-
eprintln!("Unable to parse target '{s}' as a PartialTargetTriple");
21+
eprintln!("Unable to parse target '{s}' as a known target triple");
1822
eprintln!(
19-
"If you are attempting to bootstrap a new target you may need to adjust the\n\
20-
permitted values found in src/dist/triple.rs"
23+
"If you are attempting to bootstrap a new target, you might need to update `platforms` to a newer version"
2124
);
2225
std::process::abort();
2326
}

0 commit comments

Comments
 (0)