34 releases

new 0.1.33 Dec 14, 2024
0.1.31 Nov 29, 2024
0.1.17 May 3, 2024
0.1.15 Jan 20, 2024
0.1.3 Nov 22, 2022

#69 in Build Utils

Download history 2985/week @ 2024-08-24 2728/week @ 2024-08-31 7162/week @ 2024-09-07 3556/week @ 2024-09-14 3143/week @ 2024-09-21 3028/week @ 2024-09-28 3071/week @ 2024-10-05 3141/week @ 2024-10-12 3054/week @ 2024-10-19 3205/week @ 2024-10-26 2981/week @ 2024-11-02 2237/week @ 2024-11-09 2578/week @ 2024-11-16 6748/week @ 2024-11-23 6118/week @ 2024-11-30 5089/week @ 2024-12-07

20,811 downloads per month
Used in 7 crates (5 directly)

Apache-2.0 OR MIT

25KB
422 lines

Detect the target at the runtime.

It runs $CARGO -vV if environment variable CARGO is present for cargo subcommands, otherwise it would try running rustc -vV.

If both rustc isn't present on the system, it will fallback to using syscalls plus ldd on Linux to detect targets.

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:

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
);

Dependencies

~3–12MB
~121K SLoC