| 1 |
# platform-info |
| 2 |
|
| 3 |
<!-- spell-checker:ignore (API) nodename osname sysname (rust) println --> |
| 4 |
<!-- spell-checker:ignore (wasm) wasip wasmtime --> |
| 5 |
|
| 6 |
[](https://crates.io/crates/platform-info) |
| 7 |
[](LICENSE) |
| 8 |
[](https://codecov.io/gh/uutils/platform-info/tree/main) |
| 9 |
|
| 10 |
A simple cross-platform way to get information about the currently running system. |
| 11 |
|
| 12 |
## Examples |
| 13 |
|
| 14 |
This simple example: |
| 15 |
|
| 16 |
```rust,ignore |
| 17 |
// examples/ex.rs |
| 18 |
// * use `cargo run --example ex` to execute this example |
| 19 |
|
| 20 |
// spell-checker:ignore (API) nodename osname sysname |
| 21 |
|
| 22 |
use platform_info::*; |
| 23 |
|
| 24 |
fn main() { |
| 25 |
let info = PlatformInfo::new().expect("Unable to determine platform info"); |
| 26 |
// println!("info={:#?}", info); |
| 27 |
|
| 28 |
println!("{}", info.sysname().to_string_lossy()); |
| 29 |
println!("{}", info.nodename().to_string_lossy()); |
| 30 |
println!("{}", info.release().to_string_lossy()); |
| 31 |
println!("{}", info.version().to_string_lossy()); |
| 32 |
println!("{}", info.machine().to_string_lossy()); |
| 33 |
println!("{}", info.processor().to_string_lossy()); |
| 34 |
println!("{}", info.osname().to_string_lossy()); |
| 35 |
} |
| 36 |
``` |
| 37 |
|
| 38 |
should display something like: |
| 39 |
|
| 40 |
```text |
| 41 |
Linux |
| 42 |
hostname |
| 43 |
5.10.0-8-amd64 |
| 44 |
#1 SMP Debian 5.10.46-4 (2021-08-03) |
| 45 |
x86_64 |
| 46 |
x86_64 |
| 47 |
GNU/Linux |
| 48 |
``` |
| 49 |
|
| 50 |
> Using `cargo run --example ex` will build and execute this [example code](examples/ex.rs). |
| 51 |
|
| 52 |
### WASI |
| 53 |
|
| 54 |
To cross-compile and run the example under [WASI](https://wasi.dev/), first install |
| 55 |
[wasmtime](https://wasmtime.dev/): |
| 56 |
|
| 57 |
```shell |
| 58 |
curl https://wasmtime.dev/install.sh -sSf | bash |
| 59 |
``` |
| 60 |
|
| 61 |
Then build and run: |
| 62 |
|
| 63 |
```shell |
| 64 |
cargo build --target wasm32-wasip1 --example ex |
| 65 |
wasmtime target/wasm32-wasip1/debug/examples/ex.wasm |
| 66 |
``` |
| 67 |
|
| 68 |
This should display: |
| 69 |
|
| 70 |
```text |
| 71 |
wasi |
| 72 |
localhost |
| 73 |
0.0.0 |
| 74 |
0.0.0 |
| 75 |
wasm32 |
| 76 |
wasm32 |
| 77 |
WASI |
| 78 |
``` |
| 79 |
|
| 80 |
Other examples can be found in the [examples](examples) directory. |
| 81 |
|
| 82 |
## License |
| 83 |
|
| 84 |
`platform-info` is licensed under the [MIT License](LICENSE). |