pub enum Os {
Linux,
MacOs,
IOs,
Windows,
FreeBsd,
NetBsd,
OpenBsd,
Illumos,
Wasi,
None,
}Expand description
An operating system, in the sense of the thing that defines the syscall interface, the object format, the start files and the availability of a declaration.
Android is not here. It is a Linux kernel with a different libc, so it is Os::Linux with
Env::Android, which is also how GCC and LLVM spell it. The rule is that the OS field
answers “whose kernel” and the environment field answers “whose libc”, and Android is the
case that shows they are separate questions.
Variants§
Linux
Linux. Every libc in the environment field is reachable from here.
MacOs
macOS.
IOs
iOS. A different OS from macOS and not a variant of it: a different platform value in
LC_BUILD_VERSION, a different set of availability macros, and a different SDK.
Windows
Windows, either environment.
FreeBsd
FreeBSD 14 and later.
NetBsd
NetBSD 10.1 and later.
OpenBsd
OpenBSD. Dynamically linked libc only, because OpenBSD does not ship a static one and breaks its libc ABI on purpose at every release.
Illumos
illumos. In scope because it is open, which is the whole of the argument.
Wasi
WASI. The preview number lives in the OS version, because wasip1 and wasip3 are
different ABIs rather than different releases of one.
None
No operating system. Freestanding, which is the kernel target and the embedded target and the only row in the matrix that has to reach tier 1 without a libc.
Implementations§
Source§impl Os
impl Os
Sourcepub const fn object_format(self) -> Option<ObjectFormat>
pub const fn object_format(self) -> Option<ObjectFormat>
The object format this OS uses. There is exactly one per OS, which is why this is a function of the OS and not a field anybody sets.
The freestanding case is the exception and it is handled in crate::TargetTuple,
because a freestanding target’s format follows its architecture: a wasm freestanding
target emits wasm and an aarch64 one emits ELF.
Sourcepub const fn is_darwin(self) -> bool
pub const fn is_darwin(self) -> bool
Whether this is one of the Darwin systems, which share a kernel, a linker, a set of ABI divergences from AAPCS64 and a licence that stops us shipping their headers.
Sourcepub const fn has_selectable_libc(self) -> bool
pub const fn has_selectable_libc(self) -> bool
Whether a program on this OS is linked against a libc that the tuple names.
False for Darwin and Windows-MSVC in the sense that matters here: the system C library is not a choice the user makes, so the environment field is carrying something else.
Sourcepub const fn default_env(self) -> Env
pub const fn default_env(self) -> Env
The environment used when the tuple does not name one.
Windows defaults to gnu rather than msvc, and that is a decision rather than an
oversight. spec/cross-compile/04-target-matrix.md puts x86_64-windows-gnu at tier 1 and
x86_64-windows-msvc at tier 2 because mingw-w64 is the one we are allowed to ship, and
a default that requires the user to fetch a Microsoft SDK is a default that fails on a
fresh machine.
Sourcepub const fn takes_version(self) -> bool
pub const fn takes_version(self) -> bool
Whether an OS version in the tuple means something here.
Darwin has a deployment target that decides which declarations exist, and WASI has a preview number that decides the ABI. Everywhere else the version that matters belongs to the libc and lives in the environment version instead.