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插件
8,061每月下载量
用于 6 个crate(4 个直接)
25KB
422 行
在运行时检测目标。
如果环境变量 CARGO
存在,它会运行 $CARGO -vV
,否则它会尝试运行 rustc -vV
。
如果系统上没有安装 rustc
,它将回退到使用系统调用加上Linux上的 ldd
来检测目标。
示例用法
- 二进制文件使用musl libc构建,可在任何地方运行,但运行时支持glibc。
- 二进制文件为x86_64-apple-darwin构建,但在aarch64-apple-darwin上运行。
此crate提供两个API
detect_targets
提供在运行时获取目标的API,但代码在当前线程上运行。get_desired_targets
提供API,可以使用用户提供的覆盖,或者使用tokio::spawn
在后台运行detect_targets
。
示例
检测目标
:
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