Skip to content

Commit b21f2ef

Browse files
author
toasteater
committed
Add workaround for iOS build
There is an issue in bindgen that prevents building for the aarch64-apple-ios target. This works arounds the issue by replacing aarch64 with arm64 which clang can understand. Also fixes conditional includes for macOS, which was using the target of the *build script* instead of the target we're building for. Close #285
1 parent be71230 commit b21f2ef

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

gdnative-sys/build.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@ fn main() {
1212
mod header_binding {
1313
use std::path::PathBuf;
1414

15-
#[cfg(any(target_os = "macos", target_os = "ios"))]
1615
fn osx_include_path() -> Result<String, std::io::Error> {
1716
use std::process::Command;
1817

1918
let output = Command::new("xcode-select").arg("-p").output()?.stdout;
2019
let prefix_str = std::str::from_utf8(&output).expect("invalid output from `xcode-select`");
21-
let prefix = prefix_str.trim_right();
20+
let prefix = prefix_str.trim_end();
2221

23-
let platform = if cfg!(target_os = "macos") {
22+
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
23+
24+
let platform = if target_os == "macos" {
2425
"MacOSX"
25-
} else if cfg!(target_os = "ios") {
26+
} else if target_os == "ios" {
2627
"iPhoneOS"
2728
} else {
28-
unreachable!();
29+
panic!("not building for macOS or iOS");
2930
};
3031

3132
let infix = if prefix == "/Library/Developer/CommandLineTools" {
@@ -58,12 +59,24 @@ mod header_binding {
5859
.ctypes_prefix("libc")
5960
.clang_arg(format!("-I{}/godot_headers", manifest_dir));
6061

61-
#[cfg(any(target_os = "macos", target_os = "ios"))]
62-
match osx_include_path() {
63-
Ok(osx_include_path) => {
64-
builder = builder.clang_arg("-I").clang_arg(osx_include_path);
62+
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
63+
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
64+
65+
// Workaround: x86_64 architecture is unsupported by the iPhone SDK, but cargo-lipo will
66+
// try to build it anyway. This leads to a clang error, so we'll skip the SDK.
67+
if target_os == "macos" || (target_os == "ios" && target_arch != "x86_64") {
68+
match osx_include_path() {
69+
Ok(osx_include_path) => {
70+
builder = builder.clang_arg("-I").clang_arg(osx_include_path);
71+
}
72+
_ => {}
6573
}
66-
_ => {}
74+
}
75+
76+
// Workaround for https://github.com/rust-lang/rust-bindgen/issues/1211: manually set
77+
// target triple to `arm64-apple-ios` in place of `aarch64-apple-ios`.
78+
if target_arch == "aarch64" && target_os == "ios" {
79+
builder = builder.clang_arg("--target=arm64-apple-ios");
6780
}
6881

6982
let bindings = builder.generate().expect("Unable to generate bindings");

0 commit comments

Comments
 (0)