Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shnatsel/current_platform
Find out what platform your code is running on from Rust
https://github.com/shnatsel/current_platform
compile-time platform rust
Last synced: 24 days ago
JSON representation
Find out what platform your code is running on from Rust
- Host: GitHub
- URL: https://github.com/shnatsel/current_platform
- Owner: Shnatsel
- License: apache-2.0
- Created: 2022-03-30T16:44:39.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-04-13T23:42:49.000Z (over 2 years ago)
- Last Synced: 2024-10-16T05:54:24.583Z (about 1 month ago)
- Topics: compile-time, platform, rust
- Language: Rust
- Homepage:
- Size: 19.5 KB
- Stars: 32
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE.md
Awesome Lists containing this project
README
## `current_platform`
**Find out what platform your code is running on, in Rust:**
```rust
use current_platform::CURRENT_PLATFORM;fn main() {
println!("Running on {}", CURRENT_PLATFORM);
}
```will print `Running on x86_64-unknown-linux-gnu` on desktop Linux.
Platform information is resolved **at compile time,**
based on the platform for which your code is compiled.
It incurs **zero runtime cost.**The target triple for the platform where the code was compiled is also included
as `COMPILED_ON`. It is only different from the `CURRENT_PLATFORM` if the code
was [cross-compiled.](https://en.wikipedia.org/wiki/Cross_compiler)
This is rarely useful; if in doubt, use `CURRENT_PLATFORM`.This crate is intentionally minimal and only provides the target triples.
You can find out other properties of the platform using crates such as
[`platforms`](https://docs.rs/platforms/latest/platforms/)
(auto-generated, always up to date) or
[`target-lexicon`](https://docs.rs/target-lexicon/latest/target_lexicon/)
(more detailed but may be missing newly added or obscure platforms).