Add minimal cross-compilation support for Windows and AArch64 Linux

Cross-compiling to AArch64 Linux can be done with a CMake toolchain
file, along with setting the correct compiler and include paths in the
environment.

Cross-compiling from X64 Windows to ARM64 Windows doesn't look at the
toolchain at all, because CMake + Visual Studio can already
cross-compile. Unfortunately, the Visual Studio CMake generator
doesn't set CMAKE_SYSTEM_PROCESSOR, which is what the BoringSSL
CMakeLists.txt is looking at to choose the architecture. For now,
disable the use of assembly when cross-compiling on Windows (assuming
that the Visual Studio generator will be used there).
This commit is contained in:
Jordan Rose 2022-06-22 13:27:13 -07:00
parent ccc0128cba
commit 3bbb1b94b6
2 changed files with 75 additions and 53 deletions

View File

@ -141,11 +141,13 @@ const BORING_SSL_PATH: &str = "deps/boringssl";
fn get_boringssl_cmake_config() -> cmake::Config { fn get_boringssl_cmake_config() -> cmake::Config {
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap(); let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let os = std::env::var("CARGO_CFG_TARGET_OS").unwrap(); let os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let host = std::env::var("HOST").unwrap();
let target = std::env::var("TARGET").unwrap();
let pwd = std::env::current_dir().unwrap(); let pwd = std::env::current_dir().unwrap();
let mut boringssl_cmake = cmake::Config::new(BORING_SSL_PATH); let mut boringssl_cmake = cmake::Config::new(BORING_SSL_PATH);
if host != target {
// Add platform-specific parameters. // Add platform-specific parameters for cross-compilation.
match os.as_ref() { match os.as_ref() {
"android" => { "android" => {
// We need ANDROID_NDK_HOME to be set properly. // We need ANDROID_NDK_HOME to be set properly.
@ -165,8 +167,6 @@ fn get_boringssl_cmake_config() -> cmake::Config {
// 21 is the minimum level tested. You can give higher value. // 21 is the minimum level tested. You can give higher value.
boringssl_cmake.define("ANDROID_NATIVE_API_LEVEL", "21"); boringssl_cmake.define("ANDROID_NATIVE_API_LEVEL", "21");
boringssl_cmake.define("ANDROID_STL", "c++_shared"); boringssl_cmake.define("ANDROID_STL", "c++_shared");
boringssl_cmake
} }
"ios" => { "ios" => {
@ -186,16 +186,20 @@ fn get_boringssl_cmake_config() -> cmake::Config {
}; };
let cflag = format!("{} {}", bitcode_cflag, target_cflag); let cflag = format!("{} {}", bitcode_cflag, target_cflag);
boringssl_cmake.define("CMAKE_ASM_FLAGS", &cflag); boringssl_cmake.define("CMAKE_ASM_FLAGS", &cflag);
boringssl_cmake.cflag(&cflag); boringssl_cmake.cflag(&cflag);
boringssl_cmake
} }
_ => { "windows" => {
// Configure BoringSSL for building on 32-bit non-windows platforms. if host.contains("windows") {
if arch == "x86" && os != "windows" { // BoringSSL's CMakeLists.txt isn't set up for cross-compiling using Visual Studio.
// Disable assembly support so that it at least builds.
boringssl_cmake.define("OPENSSL_NO_ASM", "YES");
}
}
"linux" => match arch.as_str() {
"x86" => {
boringssl_cmake.define( boringssl_cmake.define(
"CMAKE_TOOLCHAIN_FILE", "CMAKE_TOOLCHAIN_FILE",
pwd.join(BORING_SSL_PATH) pwd.join(BORING_SSL_PATH)
@ -203,11 +207,26 @@ fn get_boringssl_cmake_config() -> cmake::Config {
.as_os_str(), .as_os_str(),
); );
} }
"aarch64" => {
boringssl_cmake.define(
"CMAKE_TOOLCHAIN_FILE",
pwd.join("cmake/aarch64-linux.cmake").as_os_str(),
);
}
_ => {
eprintln!(
"warning: no toolchain file configured by boring-sys for {}",
target
);
}
},
_ => {}
}
}
boringssl_cmake boringssl_cmake
} }
}
}
/// Verify that the toolchains match https://csrc.nist.gov/CSRC/media/projects/cryptographic-module-validation-program/documents/security-policies/140sp3678.pdf /// Verify that the toolchains match https://csrc.nist.gov/CSRC/media/projects/cryptographic-module-validation-program/documents/security-policies/140sp3678.pdf
/// See "Installation Instructions" under section 12.1. /// See "Installation Instructions" under section 12.1.

View File

@ -0,0 +1,3 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
# Rely on environment variables to set the compiler and include paths.