Fix x86_64 fallback for aarch64 MacOS (#875)

This commit is contained in:
Jiahao XU 2023-03-10 22:09:16 +11:00 committed by GitHub
parent 9c617c2f8a
commit a22cb3a332
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View file

@ -61,7 +61,7 @@ pub async fn detect_targets() -> Vec<String> {
cfg_if! {
if #[cfg(target_os = "macos")] {
targets.extend(macos::detect_alternative_targets(&targets[0]));
targets.extend(macos::detect_alternative_targets(&targets[0]).await);
} else if #[cfg(target_os = "windows")] {
targets.extend(windows::detect_alternative_targets(&targets[0]));
}

View file

@ -1,10 +1,30 @@
use std::{io, process::Stdio};
use tokio::process::Command;
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<Item = String> {
async fn is_x86_64_supported() -> io::Result<bool> {
let exit_status = Command::new("arch")
.args(["-arch", "x86_64", "/usr/bin/true"])
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()?
.wait()
.await?;
Ok(exit_status.success())
}
pub(super) async fn detect_alternative_targets(target: &str) -> impl Iterator<Item = String> {
match target {
AARCH64 => [Some(X86), Some(UNIVERSAL)],
AARCH64 => [
is_x86_64_supported().await.unwrap_or(false).then_some(X86),
Some(UNIVERSAL),
],
X86 => [Some(UNIVERSAL), None],
_ => [None, None],
}