Debian Codegraph @

src/target/os.rs

raw
1 //! Operating systems
2
3 use crate::error::Error;
4 use core::{fmt, str::FromStr};
5
6 #[cfg(feature = "serde")]
7 use serde::{de, de::Error as DeError, ser, Deserialize, Serialize};
8
9 /// `target_os`: Operating system of the target.
10 ///
11 /// This value is closely related to the second and third element
12 /// of the platform target triple, though it is not identical.
13 #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
14 #[non_exhaustive]
15 pub enum OS {
16 /// `aix`
17 Aix,
18
19 /// `amdhsa`
20 Amdhsa,
21
22 /// `android`: Google's Android mobile operating system
23 Android,
24
25 /// `cuda`: CUDA parallel computing platform
26 Cuda,
27
28 /// `cygwin`
29 Cygwin,
30
31 /// `dragonfly`: DragonflyBSD
32 Dragonfly,
33
34 /// `emscripten`: The emscripten JavaScript transpiler
35 Emscripten,
36
37 /// `espidf`
38 Espidf,
39
40 /// `freebsd`: The FreeBSD operating system
41 FreeBSD,
42
43 /// `fuchsia`: Google's next-gen Rust OS
44 Fuchsia,
45
46 /// `haiku`: Haiku, an open source BeOS clone
47 Haiku,
48
49 /// `hermit`: HermitCore is a novel unikernel operating system targeting a scalable and predictable runtime behavior for HPC and cloud environments
50 Hermit,
51
52 /// `horizon`
53 Horizon,
54
55 /// `hurd`
56 Hurd,
57
58 /// `illumos`: illumos is a partly free and open-source Unix operating system based on OpenSolaris
59 IllumOS,
60
61 /// `ios`: Apple's iOS mobile operating system
62 #[allow(non_camel_case_types)]
63 iOS,
64
65 /// `l4re`
66 L4re,
67
68 /// `linux`: Linux
69 Linux,
70
71 /// `lynxos178`
72 Lynxos178,
73
74 /// `macos`: Apple's Mac OS X
75 MacOS,
76
77 /// `managarm`
78 Managarm,
79
80 /// `motor`
81 Motor,
82
83 /// `netbsd`: The NetBSD operating system
84 NetBSD,
85
86 /// `none`
87 None,
88
89 /// `nto`
90 Nto,
91
92 /// `nuttx`
93 Nuttx,
94
95 /// `openbsd`: The OpenBSD operating system
96 OpenBSD,
97
98 /// `psp`
99 Psp,
100
101 /// `psx`
102 Psx,
103
104 /// `redox`: Redox, a Unix-like OS written in Rust
105 Redox,
106
107 /// `rtems`
108 Rtems,
109
110 /// `solaris`: Oracle's (formerly Sun) Solaris operating system
111 Solaris,
112
113 /// `solid_asp3`
114 SolidAsp3,
115
116 /// `teeos`
117 TeeOS,
118
119 /// `trusty`
120 Trusty,
121
122 /// `tvos`
123 TvOS,
124
125 /// `uefi`
126 Uefi,
127
128 /// `unknown`
129 Unknown,
130
131 /// `vexos`
132 VexOS,
133
134 /// `visionos`
135 VisionOS,
136
137 /// `vita`
138 Vita,
139
140 /// `vxworks`: VxWorks is a deterministic, priority-based preemptive RTOS with low latency and minimal jitter
141 VxWorks,
142
143 /// `wasi`: The WebAssembly System Interface
144 Wasi,
145
146 /// `watchos`
147 WatchOS,
148
149 /// `windows`: Microsoft's Windows operating system
150 Windows,
151
152 /// `xous`
153 Xous,
154
155 /// `zkvm`
156 Zkvm,
157 }
158
159 impl OS {
160 /// String representing this `OS` which matches `#[cfg(target_os)]`
161 pub fn as_str(self) -> &'static str {
162 match self {
163 OS::Aix => "aix",
164 OS::Amdhsa => "amdhsa",
165 OS::Android => "android",
166 OS::Cuda => "cuda",
167 OS::Cygwin => "cygwin",
168 OS::Dragonfly => "dragonfly",
169 OS::Emscripten => "emscripten",
170 OS::Espidf => "espidf",
171 OS::FreeBSD => "freebsd",
172 OS::Fuchsia => "fuchsia",
173 OS::Haiku => "haiku",
174 OS::Hermit => "hermit",
175 OS::Horizon => "horizon",
176 OS::Hurd => "hurd",
177 OS::IllumOS => "illumos",
178 OS::iOS => "ios",
179 OS::L4re => "l4re",
180 OS::Linux => "linux",
181 OS::Lynxos178 => "lynxos178",
182 OS::MacOS => "macos",
183 OS::Managarm => "managarm",
184 OS::Motor => "motor",
185 OS::NetBSD => "netbsd",
186 OS::None => "none",
187 OS::Nto => "nto",
188 OS::Nuttx => "nuttx",
189 OS::OpenBSD => "openbsd",
190 OS::Psp => "psp",
191 OS::Psx => "psx",
192 OS::Redox => "redox",
193 OS::Rtems => "rtems",
194 OS::Solaris => "solaris",
195 OS::SolidAsp3 => "solid_asp3",
196 OS::TeeOS => "teeos",
197 OS::Trusty => "trusty",
198 OS::TvOS => "tvos",
199 OS::Uefi => "uefi",
200 OS::Unknown => "unknown",
201 OS::VexOS => "vexos",
202 OS::VisionOS => "visionos",
203 OS::Vita => "vita",
204 OS::VxWorks => "vxworks",
205 OS::Wasi => "wasi",
206 OS::WatchOS => "watchos",
207 OS::Windows => "windows",
208 OS::Xous => "xous",
209 OS::Zkvm => "zkvm",
210 }
211 }
212 }
213
214 impl FromStr for OS {
215 type Err = Error;
216
217 /// Create a new `OS` from the given string
218 fn from_str(name: &str) -> Result<Self, Self::Err> {
219 let result = match name {
220 "aix" => OS::Aix,
221 "amdhsa" => OS::Amdhsa,
222 "android" => OS::Android,
223 "cuda" => OS::Cuda,
224 "cygwin" => OS::Cygwin,
225 "dragonfly" => OS::Dragonfly,
226 "emscripten" => OS::Emscripten,
227 "espidf" => OS::Espidf,
228 "freebsd" => OS::FreeBSD,
229 "fuchsia" => OS::Fuchsia,
230 "haiku" => OS::Haiku,
231 "hermit" => OS::Hermit,
232 "horizon" => OS::Horizon,
233 "hurd" => OS::Hurd,
234 "illumos" => OS::IllumOS,
235 "ios" => OS::iOS,
236 "l4re" => OS::L4re,
237 "linux" => OS::Linux,
238 "lynxos178" => OS::Lynxos178,
239 "macos" => OS::MacOS,
240 "managarm" => OS::Managarm,
241 "motor" => OS::Motor,
242 "netbsd" => OS::NetBSD,
243 "none" => OS::None,
244 "nto" => OS::Nto,
245 "nuttx" => OS::Nuttx,
246 "openbsd" => OS::OpenBSD,
247 "psp" => OS::Psp,
248 "psx" => OS::Psx,
249 "redox" => OS::Redox,
250 "rtems" => OS::Rtems,
251 "solaris" => OS::Solaris,
252 "solid_asp3" => OS::SolidAsp3,
253 "teeos" => OS::TeeOS,
254 "trusty" => OS::Trusty,
255 "tvos" => OS::TvOS,
256 "uefi" => OS::Uefi,
257 "unknown" => OS::Unknown,
258 "vexos" => OS::VexOS,
259 "visionos" => OS::VisionOS,
260 "vita" => OS::Vita,
261 "vxworks" => OS::VxWorks,
262 "wasi" => OS::Wasi,
263 "watchos" => OS::WatchOS,
264 "windows" => OS::Windows,
265 "xous" => OS::Xous,
266 "zkvm" => OS::Zkvm,
267 _ => return Err(Error),
268 };
269
270 Ok(result)
271 }
272 }
273
274 impl fmt::Display for OS {
275 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
276 f.write_str(self.as_str())
277 }
278 }
279
280 #[cfg(feature = "serde")]
281 impl Serialize for OS {
282 fn serialize<S: ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
283 serializer.serialize_str(self.as_str())
284 }
285 }
286
287 #[cfg(all(feature = "serde", feature = "std"))]
288 impl<'de> Deserialize<'de> for OS {
289 fn deserialize<D: de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
290 let string = std::string::String::deserialize(deserializer)?;
291 string.parse().map_err(|_| {
292 D::Error::custom(std::format!(
293 "Unrecognized value '{}' for target_os",
294 string
295 ))
296 })
297 }
298 }