From af0c36a22f5af067af5161c841cb68f81f4adda3 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Fri, 10 Nov 2023 16:34:06 -0800 Subject: [PATCH] boring-sys: Don't use CMake cross-compilation for macOS->iOS (or macOS->macOS) --- boring-sys/build/main.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/boring-sys/build/main.rs b/boring-sys/build/main.rs index b02f76a9..e9749ff9 100644 --- a/boring-sys/build/main.rs +++ b/boring-sys/build/main.rs @@ -11,6 +11,20 @@ use crate::config::Config; mod config; +fn should_use_cmake_cross_compilation(config: &Config) -> bool { + if config.host == config.target { + return false; + } + match config.target_os.as_str() { + "macos" | "ios" => { + // Cross-compiling for Apple platforms on macOS is supported using the normal Xcode + // tools, along with the settings from `cmake_params_apple`. + !config.host.ends_with("-darwin") + } + _ => true, + } +} + // Android NDK >= 19. const CMAKE_PARAMS_ANDROID_NDK: &[(&str, &[(&str, &str)])] = &[ ("aarch64", &[("ANDROID_ABI", "arm64-v8a")]), @@ -193,11 +207,13 @@ fn get_boringssl_cmake_config(config: &Config) -> cmake::Config { return boringssl_cmake; } - boringssl_cmake - .define("CMAKE_CROSSCOMPILING", "true") - .define("CMAKE_C_COMPILER_TARGET", &config.target) - .define("CMAKE_CXX_COMPILER_TARGET", &config.target) - .define("CMAKE_ASM_COMPILER_TARGET", &config.target); + if should_use_cmake_cross_compilation(config) { + boringssl_cmake + .define("CMAKE_CROSSCOMPILING", "true") + .define("CMAKE_C_COMPILER_TARGET", &config.target) + .define("CMAKE_CXX_COMPILER_TARGET", &config.target) + .define("CMAKE_ASM_COMPILER_TARGET", &config.target); + } if let Some(sysroot) = &config.env.sysroot { boringssl_cmake.define("CMAKE_SYSROOT", sysroot);