Skip to content

Commit

Permalink
detect-targets: Add support of MacOS universal binary (rust-lang#552)
Browse files Browse the repository at this point in the history
* Add support for MacOS universal bin
* Refactor: Extract new fn `macos::detect_alternative_targets`

Signed-off-by: Jiahao XU <[email protected]>
  • Loading branch information
NobodyXu authored Nov 21, 2022
1 parent 26b28dc commit 62e350e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 1 addition & 3 deletions crates/detect-targets/src/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
Expand Down
20 changes: 15 additions & 5 deletions crates/detect-targets/src/detect/macos.rs
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 62e350e

Please sign in to comment.