18 releases

0.1.17 May 3, 2024
0.1.15 Jan 20, 2024
0.1.14 Nov 18, 2023
0.1.8 Jun 26, 2023
0.1.3 Nov 22, 2022

#195 in Cargo plugins

Download history 1117/week @ 2024-03-14 1490/week @ 2024-03-21 1354/week @ 2024-03-28 1264/week @ 2024-04-04 2001/week @ 2024-04-11 1622/week @ 2024-04-18 2050/week @ 2024-04-25 2486/week @ 2024-05-02 2203/week @ 2024-05-09 2187/week @ 2024-05-16 1787/week @ 2024-05-23 1914/week @ 2024-05-30 2164/week @ 2024-06-06 2086/week @ 2024-06-13 1839/week @ 2024-06-20 1194/week @ 2024-06-27

7,762 downloads per month
Used in 6 crates (4 directly)

Apache-2.0 OR MIT

25KB
427 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–15MB
~134K SLoC