Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add fallback x86_64h-apple-darwin and fallback for it #1228

Merged
merged 1 commit into from
Jul 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions crates/detect-targets/src/detect/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ use tokio::process::Command;

const AARCH64: &str = "aarch64-apple-darwin";
const X86: &str = "x86_64-apple-darwin";
/// https://doc.rust-lang.org/nightly/rustc/platform-support/x86_64h-apple-darwin.html
///
/// This target is an x86_64 target that only supports Apple's late-gen
/// (Haswell-compatible) Intel chips.
///
/// It enables a set of target features available on these chips (AVX2 and similar),
/// and MachO binaries built with this target may be used as the x86_64h entry in
/// universal binaries ("fat" MachO binaries), and will fail to load on machines
/// that do not support this.
///
/// It is similar to x86_64-apple-darwin in nearly all respects, although
/// the minimum supported OS version is slightly higher (it requires 10.8
/// rather than x86_64-apple-darwin's 10.7).
const X86H: &str = "x86_64h-apple-darwin";
const UNIVERSAL: &str = "universal-apple-darwin";
const UNIVERSAL2: &str = "universal2-apple-darwin";

Expand All @@ -13,22 +27,28 @@ async fn is_x86_64_supported() -> io::Result<bool> {
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()?
.wait()
.status()
.await?;

Ok(exit_status.success())
}

pub(super) async fn detect_alternative_targets(target: &str) -> impl Iterator<Item = String> {
match target {
AARCH64 => [
is_x86_64_supported().await.unwrap_or(false).then_some(X86),
Some(UNIVERSAL),
Some(UNIVERSAL2),
],
X86 => [Some(UNIVERSAL), Some(UNIVERSAL2), None],
_ => [None, None, None],
AARCH64 => {
let is_x86_64_supported = is_x86_64_supported().await.unwrap_or(false);
[
// Prefer universal as it provides native arm executable
Some(UNIVERSAL),
Some(UNIVERSAL2),
// Prefer x86h since it is more optimized
is_x86_64_supported.then_some(X86H),
is_x86_64_supported.then_some(X86),
]
}
X86 => [Some(UNIVERSAL), Some(UNIVERSAL2), None, None],
X86H => [Some(X86), Some(UNIVERSAL), Some(UNIVERSAL2), None],
_ => [None, None, None, None],
}
.into_iter()
.flatten()
Expand Down