1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
pub mod tier1;
pub mod tier2;
pub mod tier3;
#[cfg(feature = "std")]
mod req;
mod tier;
pub use self::tier::Tier;
#[cfg(feature = "std")]
pub use self::req::PlatformReq;
use crate::target::*;
use core::fmt;
#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct Platform {
pub target_triple: &'static str,
pub target_arch: Arch,
pub target_os: OS,
pub target_env: Option<Env>,
pub tier: Tier,
}
impl Platform {
pub fn find(target_triple: &str) -> Option<&'static Platform> {
Self::all()
.iter()
.find(|platform| platform.target_triple == target_triple)
}
pub fn guess_current() -> Option<&'static Platform> {
Self::all().iter().find(|platform| {
platform.target_arch == TARGET_ARCH
&& platform.target_env == TARGET_ENV
&& platform.target_os == TARGET_OS
})
}
pub const fn all() -> &'static [Platform] {
&[
tier1::I686_APPLE_DARWIN,
tier1::I686_PC_WINDOWS_GNU,
tier1::I686_PC_WINDOWS_MSVC,
tier1::I686_UNKNOWN_LINUX_GNU,
tier1::X86_64_APPLE_DARWIN,
tier1::X86_64_PC_WINDOWS_GNU,
tier1::X86_64_PC_WINDOWS_MSVC,
tier1::X86_64_UNKNOWN_LINUX_GNU,
tier2::AARCH64_APPLE_IOS,
tier2::AARCH64_PC_WINDOWS_MSVC,
tier2::AARCH64_LINUX_ANDROID,
tier2::AARCH64_FUCHSIA,
tier2::AARCH64_UNKNOWN_LINUX_GNU,
tier2::AARCH64_UNKNOWN_LINUX_MUSL,
tier2::ARM_LINUX_ANDROIDEABI,
tier2::ARM_UNKNOWN_LINUX_GNUEABI,
tier2::ARM_UNKNOWN_LINUX_GNUEABIHF,
tier2::ARM_UNKNOWN_LINUX_MUSLEABI,
tier2::ARM_UNKNOWN_LINUX_MUSLEABIHF,
tier2::ARMV5TE_UNKNOWN_LINUX_GNUEABI,
tier2::ARMV7_APPLE_IOS,
tier2::ARMV7_LINUX_ANDROIDEABI,
tier2::ARMV7_UNKNOWN_LINUX_GNUEABIHF,
tier2::ARMV7_UNKNOWN_LINUX_MUSLEABIHF,
tier2::ARMV7S_APPLE_IOS,
tier2::ASMJS_UNKNOWN_EMSCRIPTEN,
tier2::I386_APPLE_IOS,
tier2::I586_PC_WINDOWS_MSVC,
tier2::I586_UNKNOWN_LINUX_GNU,
tier2::I586_UNKNOWN_LINUX_MUSL,
tier2::I686_LINUX_ANDROID,
tier2::I686_UNKNOWN_FREEBSD,
tier2::I686_UNKNOWN_LINUX_MUSL,
tier2::MIPS_UNKNOWN_LINUX_GNU,
tier2::MIPS_UNKNOWN_LINUX_MUSL,
tier2::MIPS64_UNKNOWN_LINUX_GNUABI64,
tier2::MIPS64EL_UNKNOWN_LINUX_GNUABI64,
tier2::MIPSEL_UNKNOWN_LINUX_GNU,
tier2::MIPSEL_UNKNOWN_LINUX_MUSL,
tier2::POWERPC_UNKNOWN_LINUX_GNU,
tier2::POWERPC64_UNKNOWN_LINUX_GNU,
tier2::POWERPC64LE_UNKNOWN_LINUX_GNU,
tier2::S390X_UNKNOWN_LINUX_GNU,
tier2::SPARC64_UNKNOWN_LINUX_GNU,
tier2::SPARC64_SUN_SOLARIS,
tier2::WASM_UNKNOWN_UNKNOWN,
tier2::WASM_UNKNOWN_EMSCRIPTEN,
tier2::X86_64_APPLE_IOS,
tier2::X86_64_LINUX_ANDROID,
tier2::X86_64_RUMPRUN_NETBSD,
tier2::X86_64_SUN_SOLARIS,
tier2::X86_64_UNKNOWN_CLOUDABI,
tier2::X86_64_UNKNOWN_FREEBSD,
tier2::X86_64_FUCHSIA,
tier2::X86_64_UNKNOWN_LINUX_GNUX32,
tier2::X86_64_UNKNOWN_LINUX_MUSL,
tier2::X86_64_UNKNOWN_NETBSD,
tier2::X86_64_UNKNOWN_REDOX,
tier2::AARCH64_UNKNOWN_CLOUDABI,
tier2::ARMV7_UNKNOWN_CLOUDABI_EABIHF,
tier2::I686_UNKNOWN_CLOUDABI,
tier2::POWERPC_UNKNOWN_LINUX_GNUSPE,
tier2::SPARC_UNKNOWN_LINUX_GNU,
tier3::I686_UNKNOWN_HAIKU,
tier3::I686_UNKNOWN_NETBSD,
tier3::MIPS_UNKNOWN_LINUX_UCLIBC,
tier3::MIPSEL_UNKNOWN_LINUX_UCLIBC,
tier3::MSP430_NONE_ELF,
tier3::SPARC64_UNKNOWN_NETBSD,
tier3::THUMBV6M_NONE_EABI,
tier3::THUMBV7EM_NONE_EABI,
tier3::THUMBV7EM_NONE_EABIHF,
tier3::THUMBV7M_NONE_EABI,
tier3::X86_64_FORTANIX_UNKNOWN_SGX,
tier3::X86_64_UNKNOWN_BITRIG,
tier3::X86_64_UNKNOWN_DRAGONFLY,
tier3::X86_64_UNKNOWN_HAIKU,
tier3::X86_64_UNKNOWN_OPENBSD,
]
}
}
impl fmt::Display for Platform {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.target_triple)
}
}
#[cfg(all(test, feature = "std"))]
mod tests {
use super::Platform;
use std::collections::HashSet;
#[test]
fn no_dupes_test() {
let mut target_triples = HashSet::new();
for platform in Platform::all() {
assert!(
target_triples.insert(platform.target_triple),
"duplicate target triple: {}",
platform.target_triple
);
}
}
#[test]
fn guesses_current() {
assert!(Platform::guess_current().is_some());
}
}