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 <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-11-21 20:16:28 +11:00 committed by GitHub
parent 26b28dc63f
commit 62e350eba9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 8 deletions

View file

@ -42,9 +42,7 @@ pub async fn detect_targets() -> Vec<String> {
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]));
}

View file

@ -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<Item = String> {
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<String> {
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
}