Skip to content

Add support for Mac Catalyst (on Intel and Apple Silicon chips) #2

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

Merged
merged 1 commit into from
May 31, 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
45 changes: 36 additions & 9 deletions boring-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ const CMAKE_PARAMS_IOS: &[(&str, &[(&str, &str)])] = &[
("CMAKE_OSX_SYSROOT", "iphonesimulator"),
],
),
(
"aarch64-apple-ios-macabi",
&[
("CMAKE_OSX_ARCHITECTURES", "arm64"),
("CMAKE_OSX_SYSROOT", "macosx"),
],
),
(
"x86_64-apple-ios-macabi",
&[
("CMAKE_OSX_ARCHITECTURES", "x86_64"),
("CMAKE_OSX_SYSROOT", "macosx"),
],
),
];

fn cmake_params_ios() -> &'static [(&'static str, &'static str)] {
Expand Down Expand Up @@ -141,6 +155,7 @@ const BORING_SSL_PATH: &str = "deps/boringssl";
fn get_boringssl_cmake_config() -> cmake::Config {
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let target = std::env::var("TARGET").unwrap();
let pwd = std::env::current_dir().unwrap();

let mut boringssl_cmake = cmake::Config::new(BORING_SSL_PATH);
Expand Down Expand Up @@ -178,17 +193,29 @@ fn get_boringssl_cmake_config() -> cmake::Config {
// Bitcode is always on.
let bitcode_cflag = "-fembed-bitcode";

// Hack for Xcode 10.1.
let target_cflag = if arch == "x86_64" {
"-target x86_64-apple-ios-simulator"
if target.ends_with("-macabi") {
// Mac Catalyst
let compiler_flags = format!("{} -target {}", bitcode_cflag, target);
boringssl_cmake.define("CMAKE_ASM_FLAGS", &compiler_flags);
// Work around hardcoded deployment target in cc crate by defining CMAKE_C_FLAGS
// instead of using the cflag builder.
boringssl_cmake.define("CMAKE_C_FLAGS", &compiler_flags);
boringssl_cmake.define("CMAKE_CXX_FLAGS", &compiler_flags);
} else {
""
};
// Normal iOS

let cflag = format!("{} {}", bitcode_cflag, target_cflag);
// Hack for Xcode 10.1.
let target_cflag = if arch == "x86_64" {
"-target x86_64-apple-ios-simulator"
} else {
""
};

let cflag = format!("{} {}", bitcode_cflag, target_cflag);

boringssl_cmake.define("CMAKE_ASM_FLAGS", &cflag);
boringssl_cmake.cflag(&cflag);
boringssl_cmake.define("CMAKE_ASM_FLAGS", &cflag);
boringssl_cmake.cflag(&cflag);
}

boringssl_cmake
}
Expand Down Expand Up @@ -394,7 +421,7 @@ fn main() {
// so let's disable all alignment tests and hope for the best.
//
// [1]: https://github.com/rust-lang/rust-bindgen/issues/1651
"aarch64-apple-ios" | "aarch64-apple-ios-sim" => {
"aarch64-apple-ios" | "aarch64-apple-ios-sim" | "aarch64-apple-ios-macabi" => {
builder = builder.layout_tests(false);
}
_ => {}
Expand Down