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
use std::fmt;
use crate::utils::{build_env, define_target_enum};
define_target_enum! {
// adapted from target/os.rs from platforms crate
/// Operating system of the target.
///
/// # Note
/// This value is closely related to the second
/// and third element of the platform target triple, though it is not identical.
#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[non_exhaustive]
pub enum Os {
/// IBM AIX operating system
Aix => "aix",
/// AMD HSA architecture
Amdhsa => "amdhsa",
/// Google’s Android mobile operating system
Android => "android",
/// CUDA parallel computing platform
Cuda => "cuda",
/// POSIX layer for Windows
Cygwin => "cygwin",
/// DragonflyBSD
Dragonfly => "dragonfly",
/// The emscripten JavaScript transpiler
Emscripten => "emscripten",
/// Espressif IoT framework
Espidf => "espidf",
/// The FreeBSD operating system
FreeBSD => "freebsd",
/// Google’s next-gen Rust OS
Fuchsia => "fuchsia",
/// Haiku, an open source BeOS clone
Haiku => "haiku",
/// Unikernel targeting HPC and cloud environments
Hermit => "hermit",
Horizon => "horizon",
Hurd => "hurd",
/// illumos is a partly free and open-source Unix OS based on OpenSolaris
IllumOS => "illumos",
/// Apple’s iOS mobile operating system
#[allow(non_camel_case_types)]
iOS => "ios",
/// Microkernel OS framework
L4re => "l4re",
/// Linux
Linux => "linux",
/// Real-time OS
Lynxos178 => "lynxos178",
/// Apple’s Mac OS X
MacOS => "macos",
/// The NetBSD operating system
NetBSD => "netbsd",
None => "none",
/// QNX Neutrino OS
Nto => "nto",
/// Embedded real-time OS
Nuttx => "nuttx",
/// The OpenBSD operating system
OpenBSD => "openbsd",
/// PlayStation Portable OS
Psp => "psp",
/// PlayStation OS
Psx => "psx",
/// Redox, a Unix-like OS written in Rust
Redox => "redox",
/// Real-time executive OS
Rtems => "rtems",
/// Oracle’s (formerly Sun) Solaris operating system
Solaris => "solaris",
SolidAsp3 => "solid_asp3",
/// Trusted Execution Environment OS
TeeOS => "teeos",
/// Android trusted environment
Trusty => "trusty",
/// Apple TV OS
TvOS => "tvos",
/// Firmware interface
Uefi => "uefi",
Unknown => "unknown",
/// Apple spatial OS
VisionOS => "visionos",
/// PlayStation Vita OS
Vita => "vita",
/// VVxWorks is a deterministic, priority-based preemptive RTOS with low latency and minimal jitter
VxWorks => "vxworks",
/// The WebAssembly System Interface
Wasi => "wasi",
/// Apple Watch OS
WatchOS => "watchos",
/// Microsoft’s Windows operating system
Windows => "windows",
/// Privacy-focused microkernel OS
Xous => "xous",
/// Zero-knowledge proof VM
Zkvm => "zkvm",
}
as_str_doc = "String representing this target OS which matches `#[cfg(target_os)]`",
from_str_doc = "Tries to parse the given string as an [`Os`] falling back to [`Os::Other`] for unknown values",
}
impl Os {
/// Gets the current target [`Os`].
#[must_use]
pub fn target() -> Self {
Self::from_str(build_env("CARGO_CFG_TARGET_OS"))
}
}
impl fmt::Display for Os {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}