Skip to content

Commit 80e147a

Browse files
committed
fix(dist/triple): ensure dist::triple::known is up to date with platforms
1 parent 24a3860 commit 80e147a

File tree

4 files changed

+229
-17
lines changed

4 files changed

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

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)