From ecf6fdbab58cc1549a65cb4ddb4ec6cb9993882a Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Tue, 7 Jun 2022 12:20:46 +1000 Subject: [PATCH] Revert back to using `Vec>` for targets Signed-off-by: Jiahao XU --- src/target.rs | 74 +++++++++------------------------------------------ 1 file changed, 12 insertions(+), 62 deletions(-) diff --git a/src/target.rs b/src/target.rs index cb274ec3..7f5e4f7b 100644 --- a/src/target.rs +++ b/src/target.rs @@ -1,59 +1,10 @@ -use arrayvec::ArrayVec; use std::io::{BufRead, Cursor}; -use std::iter::IntoIterator; -use std::ops::Deref; use std::process::Output; -use std::slice; use tokio::process::Command; /// Compiled target triple, used as default for binary fetching pub const TARGET: &str = env!("TARGET"); -#[derive(Debug, Clone)] -pub struct Targets(ArrayVec, 2>); - -impl Targets { - fn from_array(arr: [Box; LEN]) -> Self { - let mut v = ArrayVec::new(); - - for elem in arr { - v.push(elem); - } - - Self(v) - } - - fn push(&mut self, s: Box) { - self.0.push(s) - } -} - -impl Deref for Targets { - type Target = [Box]; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl IntoIterator for Targets { - type Item = Box; - type IntoIter = arrayvec::IntoIter, 2>; - - fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() - } -} - -impl<'a> IntoIterator for &'a Targets { - type Item = &'a Box; - type IntoIter = slice::Iter<'a, Box>; - - fn into_iter(self) -> Self::IntoIter { - (&self.0).into_iter() - } -} - /// Detect the targets supported at runtime, /// which might be different from `TARGET` which is detected /// at compile-time. @@ -67,9 +18,9 @@ impl<'a> IntoIterator for &'a Targets { /// /// Check [this issue](https://github.com/ryankurte/cargo-binstall/issues/155) /// for more information. -pub async fn detect_targets() -> Targets { +pub async fn detect_targets() -> Vec> { if let Some(target) = get_target_from_rustc().await { - let mut v = Targets::from_array([target]); + let mut v = vec![target]; #[cfg(target_os = "linux")] if v[0].contains("gnu") { @@ -93,7 +44,7 @@ pub async fn detect_targets() -> Targets { } #[cfg(not(any(target_os = "linux", target_os = "macos")))] { - Targets::from_array([TARGET.into()]) + vec![TARGET.into()] } } } @@ -117,9 +68,9 @@ async fn get_target_from_rustc() -> Option> { #[cfg(target_os = "linux")] mod linux { - use super::{Command, Output, Targets, TARGET}; + use super::{Command, Output, TARGET}; - pub(super) async fn detect_targets_linux() -> Targets { + pub(super) async fn detect_targets_linux() -> Vec> { let abi = parse_abi(); if let Ok(Output { @@ -134,19 +85,19 @@ mod linux { } else if let Some(libc_version) = parse_libc_version_from_ldd_output(&stderr) { libc_version } else { - return Targets::from_array([create_target_str("musl", abi)]); + return vec![create_target_str("musl", abi)]; }; if libc_version == "gnu" { - return Targets::from_array([ + return vec![ create_target_str("gnu", abi), create_target_str("musl", abi), - ]); + ]; } } // Fallback to using musl - Targets::from_array([create_target_str("musl", abi)]) + vec![create_target_str("musl", abi)] } fn parse_libc_version_from_ldd_output(output: &[u8]) -> Option<&'static str> { @@ -187,17 +138,16 @@ mod linux { #[cfg(target_os = "macos")] mod macos { - use super::Targets; use guess_host_triple::guess_host_triple; pub(super) const AARCH64: &str = "aarch64-apple-darwin"; pub(super) const X86: &str = "x86_64-apple-darwin"; - pub(super) fn detect_targets_macos() -> Targets { + pub(super) fn detect_targets_macos() -> Vec> { if guess_host_triple() == Some(AARCH64) { - Targets::from_array([AARCH64.into(), X86.into()]) + vec![AARCH64.into(), X86.into()] } else { - Targets::from_array([X86.into()]) + vec![X86.into()] } } }