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

Fix Apple Silicon builds #88

Merged
merged 1 commit into from
Aug 9, 2022
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
29 changes: 29 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ fn main() {
let target = env::var("TARGET").expect("Could not read `TARGET`!");
println!("target:{}", target);

let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
println!("target_arch:{}", target_arch);

let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap();
println!("target_vendor:{}", target_vendor);

let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
println!("target_os:{}", target_os);

let out_dir = env::var("OUT_DIR").expect("Could not read `OUT_DIR`!");
println!("out_dir:{}", out_dir);

Expand Down Expand Up @@ -57,6 +66,26 @@ fn main() {
cm.define("SDL_SHARED", "ON");
cm.define("SDL_STATIC", "ON");
cm.define("HIDAPI", "ON");

// We need to set extra CMake options when building for Apple platforms.
if target_vendor == "apple" {
// CMake can handle the x86_64/aarch64 duality of Apple platforms, but
// needs to be told which architecture(s) we want. Since rust doesn't
// support fat binaries, we'll only set the one architecture
// requested. See: https://github.com/rust-lang/cargo/issues/8875
match target_arch.as_str() {
"aarch64" => {
cm.define("CMAKE_OSX_ARCHITECTURES", "arm64");
}
"x86_64" => {
cm.define("CMAKE_OSX_ARCHITECTURES", "x86_64");
}
arch => {
println!("Unrecognized architecture for Apple platform \"{}\", not setting CMAKE_OSX_ARCHITECTURES", arch);
}
}
}

cm.profile("Release");
let build_output_path = cm.build();
println!("build_output_path: {}", build_output_path.display());
Expand Down