I found I can use if cfg!(target_os = "android") { ... }
and similar lines to get boolean information about the compile target.
I would like to instead get it directly as Strings, without having to build an exhaustive list of possible values.
I found https://crates.io/crates/cargo-rustc-cfg which looks like it would provide those Strings, but it doesn't seem to play well together with a project setup as recommended by flutter_rust_bridge | Dart Package (which I'm using because I want to do my UI with Flutter):
error: could not find
Cargo.toml
in/home/thomas/Development/git/flutter_rust_bridge_template
or any parent directory
The terminal process "cargo 'test', '--doc', '--', 'Cfg::rustc_target', '--nocapture'" failed to launch (exit code: 101).
And even if it worked - Since it seems to run a separate cargo process to get the info it probably wouldn't be able to pick up on the cross-compiling settings used by the flutter_rust_bridge - Which would make the whole thing kind of pointless.
Is there any more elegant way than an exhaustive list of all possible targets in which I define a String manually, like this:
let mut val = String::new();
if cfg!(windows) {
val.push_str("Windows");
} else if cfg!(target_os = "android") {
val.push_str("Android");
} else if cfg!(target_os = "ios") {
val.push_str("iOS");
} else if cfg!(target_arch = "aarch64-apple-darwin") {
val.push_str("MacOS Darwin");
} else if cfg!(target_os = "macos") {
val.push_str("MacOS Intel");
} else if cfg!(target_family = "wasm") {
val.push_str("WebAsembly");
} else if cfg!(target_os = "linux") {
val.push_str("Linux")
} else if cfg!(unix) {
val.push_str("other Unix");
} else {
val.push_str("unknown OS");
}