#project #run-time

bin+lib detect-targets

Detect the target of the env at runtime

48 releases

new 0.1.47 Apr 5, 2025
0.1.46 Mar 19, 2025
0.1.43 Feb 28, 2025
0.1.34 Dec 28, 2024
0.1.3 Nov 22, 2022

#63 in Configuration

Download history 4986/week @ 2024-12-14 3522/week @ 2024-12-21 3815/week @ 2024-12-28 4561/week @ 2025-01-04 4323/week @ 2025-01-11 4683/week @ 2025-01-18 3844/week @ 2025-01-25 5129/week @ 2025-02-01 4911/week @ 2025-02-08 2951/week @ 2025-02-15 2809/week @ 2025-02-22 2933/week @ 2025-03-01 3154/week @ 2025-03-08 3436/week @ 2025-03-15 2618/week @ 2025-03-22 1817/week @ 2025-03-29

11,576 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

~4–13MB
~129K SLoC