Skip to content
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: 34 additions & 11 deletions boring-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ fn cmake_params_android() -> &'static [(&'static str, &'static str)] {
&[]
}

const CMAKE_PARAMS_IOS: &[(&str, &[(&str, &str)])] = &[
const CMAKE_PARAMS_APPLE: &[(&str, &[(&str, &str)])] = &[
// iOS
(
"aarch64-apple-ios",
&[
Expand All @@ -75,26 +76,41 @@ const CMAKE_PARAMS_IOS: &[(&str, &[(&str, &str)])] = &[
("CMAKE_OSX_SYSROOT", "iphonesimulator"),
],
),
// macOS
(
"aarch64-apple-darwin",
&[
("CMAKE_OSX_ARCHITECTURES", "arm64"),
("CMAKE_OSX_SYSROOT", "macosx"),
],
),
(
"x86_64-apple-darwin",
&[
("CMAKE_OSX_ARCHITECTURES", "x86_64"),
("CMAKE_OSX_SYSROOT", "macosx"),
],
),
];

fn cmake_params_ios() -> &'static [(&'static str, &'static str)] {
fn cmake_params_apple() -> &'static [(&'static str, &'static str)] {
let target = env::var("TARGET").unwrap();
for (ios_target, params) in CMAKE_PARAMS_IOS {
if *ios_target == target {
for (next_target, params) in CMAKE_PARAMS_APPLE {
if *next_target == target {
return params;
}
}
&[]
}

fn get_ios_sdk_name() -> &'static str {
for (name, value) in cmake_params_ios() {
fn get_apple_sdk_name() -> &'static str {
for (name, value) in cmake_params_apple() {
if *name == "CMAKE_OSX_SYSROOT" {
return value;
}
}
let target = env::var("TARGET").unwrap();
panic!("cannot find iOS SDK for {} in CMAKE_PARAMS_IOS", target);
panic!("cannot find SDK for {} in CMAKE_PARAMS_APPLE", target);
}

/// Returns an absolute path to the BoringSSL source.
Expand Down Expand Up @@ -180,8 +196,15 @@ fn get_boringssl_cmake_config() -> cmake::Config {
boringssl_cmake.define("ANDROID_STL", "c++_shared");
}

"macos" => {
for (name, value) in cmake_params_apple() {
eprintln!("macos arch={} add {}={}", arch, name, value);
boringssl_cmake.define(name, value);
}
}

"ios" => {
for (name, value) in cmake_params_ios() {
for (name, value) in cmake_params_apple() {
eprintln!("ios arch={} add {}={}", arch, name, value);
boringssl_cmake.define(name, value);
}
Expand Down Expand Up @@ -295,10 +318,10 @@ fn get_extra_clang_args_for_bindgen() -> Vec<String> {
// Add platform-specific parameters.
#[allow(clippy::single_match)]
match os.as_ref() {
"ios" => {
// When cross-compiling for iOS, tell bindgen to use iOS sysroot,
"ios" | "macos" => {
// When cross-compiling for Apple targets, tell bindgen to use SDK sysroot,
// and *don't* use system headers of the host macOS.
let sdk = get_ios_sdk_name();
let sdk = get_apple_sdk_name();
let output = std::process::Command::new("xcrun")
.args(["--show-sdk-path", "--sdk", sdk])
.output()
Expand Down