45 releases

new 0.1.44 Mar 7, 2025
0.1.38 Jan 19, 2025
0.1.34 Dec 28, 2024
0.1.31 Nov 29, 2024
0.1.3 Nov 22, 2022

#71 in Build Utils

Download history 4135/week @ 2024-11-18 6485/week @ 2024-11-25 6182/week @ 2024-12-02 5984/week @ 2024-12-09 4189/week @ 2024-12-16 3786/week @ 2024-12-23 3833/week @ 2024-12-30 4272/week @ 2025-01-06 4641/week @ 2025-01-13 4101/week @ 2025-01-20 4204/week @ 2025-01-27 5396/week @ 2025-02-03 4359/week @ 2025-02-10 3053/week @ 2025-02-17 2539/week @ 2025-02-24 2995/week @ 2025-03-03

13,549 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
~118K SLoC