Merge pull request #84 from signalapp/macos-cross-compile

boring-sys: Handle cross-compiling macOS targets
This commit is contained in:
Ivan Nikulin 2023-07-28 13:21:04 +01:00 committed by GitHub
commit 4761cf7805
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 11 deletions

View File

@ -54,7 +54,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", "aarch64-apple-ios",
&[ &[
@ -76,26 +77,41 @@ const CMAKE_PARAMS_IOS: &[(&str, &[(&str, &str)])] = &[
("CMAKE_OSX_SYSROOT", "iphonesimulator"), ("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(); let target = env::var("TARGET").unwrap();
for (ios_target, params) in CMAKE_PARAMS_IOS { for (next_target, params) in CMAKE_PARAMS_APPLE {
if *ios_target == target { if *next_target == target {
return params; return params;
} }
} }
&[] &[]
} }
fn get_ios_sdk_name() -> &'static str { fn get_apple_sdk_name() -> &'static str {
for (name, value) in cmake_params_ios() { for (name, value) in cmake_params_apple() {
if *name == "CMAKE_OSX_SYSROOT" { if *name == "CMAKE_OSX_SYSROOT" {
return value; return value;
} }
} }
let target = env::var("TARGET").unwrap(); 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. /// Returns an absolute path to the BoringSSL source.
@ -181,8 +197,15 @@ fn get_boringssl_cmake_config() -> cmake::Config {
boringssl_cmake.define("ANDROID_STL", "c++_shared"); 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" => { "ios" => {
for (name, value) in cmake_params_ios() { for (name, value) in cmake_params_apple() {
eprintln!("ios arch={} add {}={}", arch, name, value); eprintln!("ios arch={} add {}={}", arch, name, value);
boringssl_cmake.define(name, value); boringssl_cmake.define(name, value);
} }
@ -329,10 +352,10 @@ fn get_extra_clang_args_for_bindgen() -> Vec<String> {
// Add platform-specific parameters. // Add platform-specific parameters.
#[allow(clippy::single_match)] #[allow(clippy::single_match)]
match os.as_ref() { match os.as_ref() {
"ios" => { "ios" | "macos" => {
// When cross-compiling for iOS, tell bindgen to use iOS sysroot, // When cross-compiling for Apple targets, tell bindgen to use SDK sysroot,
// and *don't* use system headers of the host macOS. // 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") let output = std::process::Command::new("xcrun")
.args(["--show-sdk-path", "--sdk", sdk]) .args(["--show-sdk-path", "--sdk", sdk])
.output() .output()