Crate detect_targets
source · [−]Expand description
Detect the target at the runtime.
Example use cases:
- The binary is built with musl libc to run on anywhere, but the runtime supports glibc.
- The binary is built for x86_64-apple-darwin, but run on aarch64-apple-darwin.
This crate provides two API:
detect_targetsprovides the API to get the target at runtime, but the code is run on the current thread.get_desired_targetsprovides the API to either use override provided by the users, or rundetect_targetsin the background usingtokio::spawn.
Example
detect_targets:
use detect_targets::detect_targets;
let targets = detect_targets().await;
eprintln!("Your platform supports targets: {targets:#?}");get_desired_targets with user override:
use detect_targets::get_desired_targets;
assert_eq!(
get_desired_targets(Some(vec![
"x86_64-apple-darwin".to_string(),
"aarch64-apple-darwin".to_string(),
])).get().await,
&["x86_64-apple-darwin", "aarch64-apple-darwin"],
);get_desired_targets without user override:
use detect_targets::get_desired_targets;
eprintln!(
"Your platform supports targets: {:#?}",
get_desired_targets(None).get().await
);Structs
Constants
Compiled target triple, used as default for binary fetching
Functions
Detect the targets supported at runtime,
which might be different from TARGET which is detected
at compile-time.
If opts_targets is Some, then it will be used.
Otherwise, call detect_targets using tokio::spawn to detect targets.