build_target/os.rs
1use std::fmt;
2
3use crate::utils::{build_env, define_target_enum};
4
5define_target_enum! {
6 // adapted from target/os.rs from platforms crate
7 /// Operating system of the target.
8 ///
9 /// # Note
10 /// This value is closely related to the second
11 /// and third element of the platform target triple, though it is not identical.
12 #[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
13 #[non_exhaustive]
14 pub enum Os {
15 /// IBM AIX operating system
16 Aix => "aix",
17 /// AMD HSA architecture
18 Amdhsa => "amdhsa",
19 /// Google’s Android mobile operating system
20 Android => "android",
21 /// CUDA parallel computing platform
22 Cuda => "cuda",
23 /// POSIX layer for Windows
24 Cygwin => "cygwin",
25 /// DragonflyBSD
26 Dragonfly => "dragonfly",
27 /// The emscripten JavaScript transpiler
28 Emscripten => "emscripten",
29 /// Espressif IoT framework
30 Espidf => "espidf",
31 /// The FreeBSD operating system
32 FreeBSD => "freebsd",
33 /// Google’s next-gen Rust OS
34 Fuchsia => "fuchsia",
35 /// Haiku, an open source BeOS clone
36 Haiku => "haiku",
37 /// Unikernel targeting HPC and cloud environments
38 Hermit => "hermit",
39 Horizon => "horizon",
40 Hurd => "hurd",
41 /// illumos is a partly free and open-source Unix OS based on OpenSolaris
42 IllumOS => "illumos",
43 /// Apple’s iOS mobile operating system
44 #[allow(non_camel_case_types)]
45 iOS => "ios",
46 /// Microkernel OS framework
47 L4re => "l4re",
48 /// Linux
49 Linux => "linux",
50 /// Real-time OS
51 Lynxos178 => "lynxos178",
52 /// Apple’s Mac OS X
53 MacOS => "macos",
54 /// The NetBSD operating system
55 NetBSD => "netbsd",
56 None => "none",
57 /// QNX Neutrino OS
58 Nto => "nto",
59 /// Embedded real-time OS
60 Nuttx => "nuttx",
61 /// The OpenBSD operating system
62 OpenBSD => "openbsd",
63 /// PlayStation Portable OS
64 Psp => "psp",
65 /// PlayStation OS
66 Psx => "psx",
67 /// Redox, a Unix-like OS written in Rust
68 Redox => "redox",
69 /// Real-time executive OS
70 Rtems => "rtems",
71 /// Oracle’s (formerly Sun) Solaris operating system
72 Solaris => "solaris",
73 SolidAsp3 => "solid_asp3",
74 /// Trusted Execution Environment OS
75 TeeOS => "teeos",
76 /// Android trusted environment
77 Trusty => "trusty",
78 /// Apple TV OS
79 TvOS => "tvos",
80 /// Firmware interface
81 Uefi => "uefi",
82 Unknown => "unknown",
83 /// Apple spatial OS
84 VisionOS => "visionos",
85 /// PlayStation Vita OS
86 Vita => "vita",
87 /// VVxWorks is a deterministic, priority-based preemptive RTOS with low latency and minimal jitter
88 VxWorks => "vxworks",
89 /// The WebAssembly System Interface
90 Wasi => "wasi",
91 /// Apple Watch OS
92 WatchOS => "watchos",
93 /// Microsoft’s Windows operating system
94 Windows => "windows",
95 /// Privacy-focused microkernel OS
96 Xous => "xous",
97 /// Zero-knowledge proof VM
98 Zkvm => "zkvm",
99 }
100
101 as_str_doc = "String representing this target OS which matches `#[cfg(target_os)]`",
102 from_str_doc = "Tries to parse the given string as an [`Os`] falling back to [`Os::Other`] for unknown values",
103}
104
105impl Os {
106 /// Gets the current target [`Os`].
107 #[must_use]
108 pub fn target() -> Self {
109 Self::from_str(build_env("CARGO_CFG_TARGET_OS"))
110 }
111}
112
113impl fmt::Display for Os {
114 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
115 f.write_str(self.as_str())
116 }
117}