#run-time #detect #target #system #binary #environment #rustc

bin+lib detect-targets

在运行时检测环境的目标

20次发布

0.1.19 2024年8月10日
0.1.17 2024年5月3日
0.1.15 2024年1月20日
0.1.14 2023年11月18日
0.1.3 2022年11月22日

#148 in Cargo插件

Download history 1831/week @ 2024-04-20 2442/week @ 2024-04-27 2150/week @ 2024-05-04 1936/week @ 2024-05-11 2361/week @ 2024-05-18 1556/week @ 2024-05-25 2257/week @ 2024-06-01 2199/week @ 2024-06-08 1833/week @ 2024-06-15 1602/week @ 2024-06-22 1897/week @ 2024-06-29 1498/week @ 2024-07-06 1617/week @ 2024-07-13 1837/week @ 2024-07-20 1819/week @ 2024-07-27 2527/week @ 2024-08-03

8,061每月下载量
用于 6 个crate(4 个直接)

Apache-2.0 OR MIT

25KB
422

在运行时检测目标。

如果环境变量 CARGO 存在,它会运行 $CARGO -vV,否则它会尝试运行 rustc -vV

如果系统上没有安装 rustc,它将回退到使用系统调用加上Linux上的 ldd 来检测目标。

示例用法

  • 二进制文件使用musl libc构建,可在任何地方运行,但运行时支持glibc。
  • 二进制文件为x86_64-apple-darwin构建,但在aarch64-apple-darwin上运行。

此crate提供两个API

示例

检测目标:

use detect_targets::detect_targets;

let targets = detect_targets().await;
eprintln!("Your platform supports targets: {targets:#?}");

get_desired_targets 带用户覆盖

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 不带用户覆盖

use detect_targets::get_desired_targets;

eprintln!(
    "Your platform supports targets: {:#?}",
    get_desired_targets(None).get().await
);

依赖

~3–13MB
~127K SLoC