Rust has the ability to check configuration at build time with, e.g., #[cfg(target_os = "linux")] or if cfg!(target_os = "linux") {...}, where target_os is a feature.
#[cfg(target_os = "linux")]
if cfg!(target_os = "linux") {...}
target_os
Is there a list of all (or, at least, commonly used) features that can be checked in Rust?
See related question regarding attributes Is there an exhaustive list of standard attributes anywhere?.
The "Conditional compilation" section of the Reference has a list of configurations that must be defined (as of Rust 1.14):
target_arch
x86
x86_64
mips
powerpc
powerpc64
arm
aarch64
windows
macos
ios
linux
android
freebsd
dragonfly
bitrig
openbsd
netbsd
target_family
unix
target_env
gnu
msvc
musl
""
target_endian
little
big
target_pointer_width
32
64
target_has_atomic
8
16
ptr
target_vendor
apple
pc
unknown
test
debug_assertions
2.1m questions
2.1m answers
60 comments
57.0k users