Skip to content

Commit c19aae9

Browse files
committed
fix(dist/triple): ensure dist::triple::known is up to date with platforms
1 parent 850a14a commit c19aae9

File tree

4 files changed

+231
-17
lines changed

4 files changed

+231
-17
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,15 @@ version = "0.52.0"
119119

120120
[dev-dependencies]
121121
enum-map = "2.5.0"
122+
platforms.workspace = true
122123
proptest.workspace = true
123124
rustup-macros.workspace = true
124125
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
125126
trycmd = "0.15.0"
126127

127128
[build-dependencies]
128129
once_cell.workspace = true
129-
platforms = "3.4"
130+
platforms.workspace = true
130131
regex = "1"
131132

132133
[workspace]
@@ -139,6 +140,7 @@ once_cell = "1.18.0"
139140
opentelemetry = "0.23"
140141
opentelemetry_sdk = { version = "0.23", features = ["rt-tokio"] }
141142
opentelemetry-otlp = "0.16"
143+
platforms = "3.4"
142144
proptest = "1.1.0"
143145
rustup-macros = { path = "rustup-macros" }
144146
tempfile = "3.8"

src/dist/triple/known.rs

Lines changed: 133 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,159 @@
11
pub static LIST_ARCHS: &[&str] = &[
2-
"i386",
3-
"i586",
4-
"i686",
5-
"x86_64",
2+
"aarch64",
3+
"aarch64_be",
64
"arm",
5+
"arm64_32",
6+
"arm64e",
7+
"arm64ec",
8+
"armeb",
9+
"armebv7r",
10+
"armv4t",
11+
"armv5te",
12+
"armv6",
13+
"armv6k",
714
"armv7",
15+
"armv7a",
16+
"armv7k",
17+
"armv7r",
818
"armv7s",
9-
"aarch64",
19+
"armv8r",
20+
"avr",
21+
"bpfeb",
22+
"bpfel",
23+
"csky",
24+
"hexagon",
25+
"i386",
26+
"i586",
27+
"i686",
28+
"loongarch64",
29+
"m68k",
1030
"mips",
11-
"mipsel",
1231
"mips64",
1332
"mips64el",
33+
"mipsel",
34+
"mipsisa32r6",
35+
"mipsisa32r6el",
36+
"mipsisa64r6",
37+
"mipsisa64r6el",
38+
"msp430",
39+
"nvptx64",
1440
"powerpc",
1541
"powerpc64",
1642
"powerpc64le",
43+
"riscv32gc",
44+
"riscv32i",
45+
"riscv32im",
46+
"riscv32ima",
47+
"riscv32imac",
48+
"riscv32imafc",
49+
"riscv32imc",
50+
"riscv64",
1751
"riscv64gc",
52+
"riscv64imac",
1853
"s390x",
19-
"loongarch64",
54+
"sparc",
55+
"sparc64",
56+
"sparcv9",
57+
"thumbv4t",
58+
"thumbv5te",
59+
"thumbv6m",
60+
"thumbv7a",
61+
"thumbv7em",
62+
"thumbv7m",
63+
"thumbv7neon",
64+
"thumbv8m.base",
65+
"thumbv8m.main",
66+
"wasm32",
67+
"wasm64",
68+
"x86_64",
69+
"x86_64h",
2070
];
2171
pub static LIST_OSES: &[&str] = &[
22-
"pc-windows",
23-
"unknown-linux",
2472
"apple-darwin",
25-
"unknown-netbsd",
2673
"apple-ios",
74+
"apple-tvos",
75+
"apple-watchos",
76+
"esp-espidf",
77+
"fortanix-unknown",
78+
"fuchsia",
79+
"ibm-aix",
80+
"kmc-solid_asp3",
2781
"linux",
28-
"rumprun-netbsd",
82+
"nintendo-3ds",
83+
"nintendo-switch",
84+
"none",
85+
"nvidia-cuda",
86+
"openwrt-linux",
87+
"pc-nto",
88+
"pc-solaris",
89+
"pc-windows",
90+
"risc0-zkvm",
91+
"sony-psp",
92+
"sony-psx",
93+
"sony-vita",
94+
"sun-solaris",
95+
"unikraft-linux",
96+
"unknown-dragonfly",
97+
"unknown-emscripten",
2998
"unknown-freebsd",
99+
"unknown-fuchsia",
100+
"unknown-gnu",
101+
"unknown-haiku",
102+
"unknown-hermit",
103+
"unknown-hurd",
30104
"unknown-illumos",
105+
"unknown-l4re",
106+
"unknown-linux",
107+
"unknown-netbsd",
108+
"unknown-none",
109+
"unknown-nto",
110+
"unknown-openbsd",
111+
"unknown-redox",
112+
"unknown-teeos",
113+
"unknown-uefi",
114+
"unknown-unknown",
115+
"unknown-xous",
116+
"uwp-windows",
117+
"wasi",
118+
"wasip1",
119+
"wasip1-threads",
120+
"wasip2",
121+
"win7-windows",
122+
"wrs-vxworks",
31123
];
32124
pub static LIST_ENVS: &[&str] = &[
125+
"android",
126+
"androideabi",
127+
"atmega328",
128+
"eabi",
129+
"eabihf",
130+
"elf",
131+
"freestanding",
33132
"gnu",
34-
"gnux32",
35-
"msvc",
133+
"gnu_ilp32",
134+
"gnuabi64",
135+
"gnuabiv2",
136+
"gnuabiv2hf",
36137
"gnueabi",
37138
"gnueabihf",
38-
"gnuabi64",
39-
"androideabi",
40-
"android",
139+
"gnullvm",
140+
"gnuspe",
141+
"gnux32",
142+
"macabi",
143+
"msvc",
41144
"musl",
145+
"muslabi64",
146+
"musleabi",
147+
"musleabihf",
148+
"newlibeabihf",
149+
"ohos",
150+
"qnx700",
151+
"qnx710",
152+
"sgx",
153+
"sim",
154+
"softfloat",
155+
"spe",
156+
"uclibc",
157+
"uclibceabi",
158+
"uclibceabihf",
42159
];

tests/suite/known_triples.rs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
use std::{collections::BTreeSet, io::Write};
2+
3+
use platforms::Platform;
4+
5+
#[test]
6+
fn gen_known_triples() {
7+
let out_path = "src/dist/triple/known.rs";
8+
let existing = std::fs::read_to_string(out_path).unwrap();
9+
10+
let (mut archs, mut oses, mut envs) = (BTreeSet::new(), BTreeSet::new(), BTreeSet::new());
11+
for (arch, os, env) in Platform::ALL.iter().map(|p| parse_triple(p.target_triple)) {
12+
archs.insert(arch);
13+
oses.insert(os);
14+
if !env.is_empty() {
15+
envs.insert(env);
16+
}
17+
}
18+
19+
let expected = {
20+
let mut buf = String::new();
21+
22+
buf.push_str("pub static LIST_ARCHS: &[&str] = &[\n");
23+
for arch in archs {
24+
buf.push_str(&format!(" \"{arch}\",\n"));
25+
}
26+
buf.push_str("];\n");
27+
28+
buf.push_str("pub static LIST_OSES: &[&str] = &[\n");
29+
for os in oses {
30+
buf.push_str(&format!(" \"{os}\",\n"));
31+
}
32+
buf.push_str("];\n");
33+
34+
buf.push_str("pub static LIST_ENVS: &[&str] = &[\n");
35+
for env in envs {
36+
buf.push_str(&format!(" \"{env}\",\n"));
37+
}
38+
buf.push_str("];\n");
39+
40+
buf
41+
};
42+
43+
if expected != existing {
44+
let mut tmp_file = tempfile::NamedTempFile::new().unwrap();
45+
tmp_file.write_all(expected.as_bytes()).unwrap();
46+
std::fs::rename(tmp_file.path(), out_path).unwrap();
47+
panic!(
48+
"outdated generated code detected at `{out_path}`, the file has been updated in place"
49+
);
50+
}
51+
}
52+
53+
/// Parses the given triple into 3 parts (target architecture, OS and environment).
54+
///
55+
/// # Discussion
56+
///
57+
/// The current model of target triples in Rustup requires some non-code knowledge to correctly generate the list.
58+
/// For example, the parsing results of two 2-dash triples can be different:
59+
///
60+
/// ```jsonc
61+
/// { arch: aarch64, os: linux, env: android }
62+
/// { arch: aarch64, os: unknown-freebsd}
63+
/// ```
64+
///
65+
/// Thus, the following parsing scheme is used:
66+
///
67+
/// ```jsonc
68+
/// // for `x-y`
69+
/// { arch: x, os: y }
70+
///
71+
/// // special case for `x-y-w` where `y` is `none` or `linux`
72+
/// // e.g. `thumbv4t-none-eabi`, `i686-linux-android`
73+
/// // (should've been called `x-unknown-y-w`, but alas)
74+
/// { arch: x, os: y, env: w }
75+
///
76+
/// // for `x-y-z`
77+
/// { arch: x, os: y-z }
78+
///
79+
/// // for `x-y-z-w`
80+
/// { arch: x, os: y-z, env: w }
81+
/// ```
82+
fn parse_triple(triple: &str) -> (&str, &str, &str) {
83+
match triple.split('-').collect::<Vec<_>>()[..] {
84+
[arch, os] => (arch, os, ""),
85+
[arch, os @ ("none" | "linux"), env] => (arch, os, env),
86+
[arch, _, _] => (arch, &triple[(arch.len() + 1)..], ""),
87+
[arch, _, _, env] => (
88+
arch,
89+
&triple[(arch.len() + 1)..(triple.len() - env.len() - 1)],
90+
env,
91+
),
92+
_ => panic!("Internal error while parsing target triple `{triple}`, please file an issue at https://github.com/rust-lang/rustup/issues"),
93+
}
94+
}

tests/suite/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ mod cli_ui;
88
mod cli_v1;
99
mod cli_v2;
1010
mod dist_install;
11+
mod known_triples;

0 commit comments

Comments
 (0)