From 62e350eba916f610a2f5e265e18b9fc78a3b47e6 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Mon, 21 Nov 2022 20:16:28 +1100 Subject: [PATCH] detect-targets: Add support of MacOS universal binary (#552) * Add support for MacOS universal bin * Refactor: Extract new fn `macos::detect_alternative_targets` Signed-off-by: Jiahao XU --- crates/detect-targets/src/detect.rs | 4 +--- crates/detect-targets/src/detect/macos.rs | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/crates/detect-targets/src/detect.rs b/crates/detect-targets/src/detect.rs index 6200e425a..71940e715 100644 --- a/crates/detect-targets/src/detect.rs +++ b/crates/detect-targets/src/detect.rs @@ -42,9 +42,7 @@ pub async fn detect_targets() -> Vec { v.push(v[0].replace("gnu", "musl")); } } else if #[cfg(target_os = "macos")] { - if &*v[0] == macos::AARCH64 { - v.push(macos::X86.into()); - } + v.extend(macos::detect_alternative_targets(&v[0])); } else if #[cfg(target_os = "windows")] { v.extend(windows::detect_alternative_targets(&v[0])); } diff --git a/crates/detect-targets/src/detect/macos.rs b/crates/detect-targets/src/detect/macos.rs index 67e31ccf9..ad5b1f0e1 100644 --- a/crates/detect-targets/src/detect/macos.rs +++ b/crates/detect-targets/src/detect/macos.rs @@ -1,15 +1,25 @@ use crate::TARGET; use guess_host_triple::guess_host_triple; -pub(super) const AARCH64: &str = "aarch64-apple-darwin"; -pub(super) const X86: &str = "x86_64-apple-darwin"; +const AARCH64: &str = "aarch64-apple-darwin"; +const X86: &str = "x86_64-apple-darwin"; +const UNIVERSAL: &str = "universal-apple-darwin"; + +pub(super) fn detect_alternative_targets(target: &str) -> impl Iterator { + match target { + AARCH64 => [Some(X86), Some(UNIVERSAL)], + X86 => [Some(UNIVERSAL), None], + _ => [None, None], + } + .into_iter() + .flatten() + .map(ToString::to_string) +} pub(super) fn detect_targets_macos() -> Vec { let mut targets = vec![guess_host_triple().unwrap_or(TARGET).to_string()]; - if targets[0] == AARCH64 { - targets.push(X86.into()); - } + targets.extend(detect_alternative_targets(&targets[0])); targets }