current_platform/lib.rs
1//! **Find out what platform your code is running on:**
2//!
3//! ```no_run
4//! use current_platform::CURRENT_PLATFORM;
5//!
6//! fn main() {
7//! println!("Running on {}", CURRENT_PLATFORM);
8//! }
9//! ```
10//! will print `Running on x86_64-unknown-linux-gnu` on desktop Linux.
11//!
12//! Platform information is resolved **at compile time,**
13//! based on the platform for which your code is compiled.
14//! It incurs **zero runtime cost.**
15//!
16//! The target triple for the platform where the code was compiled is also included,
17//! see [`COMPILED_ON`](COMPILED_ON).
18//!
19//! This crate is intentionally minimal and only provides the target triple.
20//! You can find out other properties of the platform using crates such as
21//! [`platforms`](https://docs.rs/platforms/latest/platforms/)
22//! (auto-generated, always up to date) or
23//! [`target-lexicon`](https://docs.rs/target-lexicon/latest/target_lexicon/)
24//! (more detailed but may be missing newly added or obscure platforms).
25
26/// The platform on which your code is running.
27///
28/// Also known as "target platform".
29pub const CURRENT_PLATFORM: &str = env!("TARGET_PLATFORM");
30
31/// The platform on which your code was compiled.
32///
33/// Also known as "host platform".
34/// It will only be different from [`CURRENT_PLATFORM`](CURRENT_PLATFORM)
35/// if the code was [cross-compiled.](https://en.wikipedia.org/wiki/Cross_compiler)
36///
37/// This is rarely needed; if in doubt, use [`CURRENT_PLATFORM`](CURRENT_PLATFORM).
38pub const COMPILED_ON: &str = env!("HOST_PLATFORM");