use std::process::Stdio;
use tokio::process::Command;
const AARCH64: &str = "aarch64-apple-darwin";
const X86: &str = "x86_64-apple-darwin";
const X86H: &str = "x86_64h-apple-darwin";
const UNIVERSAL: &str = "universal-apple-darwin";
const UNIVERSAL2: &str = "universal2-apple-darwin";
async fn is_arch_supported(arch_name: &str) -> bool {
Command::new("arch")
.args(["-arch", arch_name, "/usr/bin/true"])
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
.await
.map(|exit_status| exit_status.success())
.unwrap_or(false)
}
pub(super) async fn detect_alternative_targets(target: &str) -> impl Iterator<Item = String> {
match target {
AARCH64 => {
let x86_64h_task = tokio::spawn(is_arch_supported("x86_64h"));
let x86_64_task = tokio::spawn(is_arch_supported("x86_64"));
[
Some(UNIVERSAL),
Some(UNIVERSAL2),
x86_64h_task.await.unwrap().then_some(X86H),
x86_64_task.await.unwrap().then_some(X86),
]
}
X86 => [
is_arch_supported("x86_64h").await.then_some(X86H),
Some(UNIVERSAL),
Some(UNIVERSAL2),
None,
],
X86H => [Some(X86), Some(UNIVERSAL), Some(UNIVERSAL2), None],
_ => [None, None, None, None],
}
.into_iter()
.flatten()
.map(ToString::to_string)
}