mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 12:38:43 +00:00
Add get_targets_from_rustc
to detect_targets
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
8bf4d187ee
commit
cce378e2c5
1 changed files with 22 additions and 3 deletions
|
@ -1,4 +1,7 @@
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
|
use std::io::{BufRead, Cursor};
|
||||||
|
use std::process::Output;
|
||||||
|
use tokio::process::Command;
|
||||||
|
|
||||||
/// Compiled target triple, used as default for binary fetching
|
/// Compiled target triple, used as default for binary fetching
|
||||||
pub const TARGET: &str = env!("TARGET");
|
pub const TARGET: &str = env!("TARGET");
|
||||||
|
@ -17,6 +20,10 @@ pub const TARGET: &str = env!("TARGET");
|
||||||
/// Check [this issue](https://github.com/ryankurte/cargo-binstall/issues/155)
|
/// Check [this issue](https://github.com/ryankurte/cargo-binstall/issues/155)
|
||||||
/// for more information.
|
/// for more information.
|
||||||
pub async fn detect_targets() -> ArrayVec<Box<str>, 2> {
|
pub async fn detect_targets() -> ArrayVec<Box<str>, 2> {
|
||||||
|
if let Some(target) = get_targets_from_rustc().await {
|
||||||
|
return from_array([target]);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
linux::detect_targets_linux().await
|
linux::detect_targets_linux().await
|
||||||
|
@ -31,6 +38,20 @@ pub async fn detect_targets() -> ArrayVec<Box<str>, 2> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Figure out what the host target is, from rustc or from this program's own build target
|
||||||
|
async fn get_targets_from_rustc() -> Option<Box<str>> {
|
||||||
|
match Command::new("rustc").arg("-vV").output().await {
|
||||||
|
Ok(Output { status, stdout, .. }) if status.success() => Cursor::new(stdout)
|
||||||
|
.lines()
|
||||||
|
.filter_map(|line| line.ok())
|
||||||
|
.find_map(|line| {
|
||||||
|
line.strip_prefix("host: ")
|
||||||
|
.map(|host| host.to_owned().into_boxed_str())
|
||||||
|
}),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn from_array<T, const LEN: usize, const CAP: usize>(arr: [T; LEN]) -> ArrayVec<T, CAP> {
|
fn from_array<T, const LEN: usize, const CAP: usize>(arr: [T; LEN]) -> ArrayVec<T, CAP> {
|
||||||
let mut v = ArrayVec::new();
|
let mut v = ArrayVec::new();
|
||||||
|
|
||||||
|
@ -43,9 +64,7 @@ fn from_array<T, const LEN: usize, const CAP: usize>(arr: [T; LEN]) -> ArrayVec<
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
mod linux {
|
mod linux {
|
||||||
use super::{from_array, ArrayVec, TARGET};
|
use super::{from_array, ArrayVec, Command, Output, TARGET};
|
||||||
use std::process::Output;
|
|
||||||
use tokio::process::Command;
|
|
||||||
|
|
||||||
pub(super) async fn detect_targets_linux() -> ArrayVec<Box<str>, 2> {
|
pub(super) async fn detect_targets_linux() -> ArrayVec<Box<str>, 2> {
|
||||||
let abi = parse_abi();
|
let abi = parse_abi();
|
||||||
|
|
Loading…
Add table
Reference in a new issue