From cd34120d90edbcee9bf6e2e55e49345fd29b4c03 Mon Sep 17 00:00:00 2001 From: Justin W Smith <103147162+justsmth@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:18:40 -0400 Subject: [PATCH] Allow cmake toolchain env (#431) --- .github/workflows/cross.yml | 25 ++++++++++++++++++++ aws-lc-fips-sys/builder/cmake_builder.rs | 27 ++++++++++++--------- aws-lc-sys/builder/cmake_builder.rs | 30 ++++++++++++++++-------- 3 files changed, 61 insertions(+), 21 deletions(-) diff --git a/.github/workflows/cross.yml b/.github/workflows/cross.yml index 4ab4dcdb617..2ded0b3d20f 100644 --- a/.github/workflows/cross.yml +++ b/.github/workflows/cross.yml @@ -113,6 +113,31 @@ jobs: run: cargo build -p aws-lc-rs --release --target x86_64-apple-ios --features bindgen + cargo-xwin: + if: github.repository_owner == 'aws' + runs-on: ubuntu-latest + steps: + - name: Install build dependencies + run: | + sudo apt-get update && sudo apt-get install --assume-yes nasm clang ninja-build llvm + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + target: x86_64-pc-windows-msvc + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + target: aarch64-pc-windows-msvc + - name: Install cargo-xwin and bindgen-cli + run: cargo install cargo-xwin bindgen-cli + - name: cargo xwin build for `x86_64-pc-windows-msvc` + run: cargo xwin build -p aws-lc-rs --release --target x86_64-pc-windows-msvc + - name: cargo xwin build for `aarch64-pc-windows-msvc` + run: cargo xwin build -p aws-lc-rs --release --target aarch64-pc-windows-msvc + aws-lc-rs-windows-mingw: if: github.repository_owner == 'aws' name: x86_64-pc-windows-gnu diff --git a/aws-lc-fips-sys/builder/cmake_builder.rs b/aws-lc-fips-sys/builder/cmake_builder.rs index b2dab2500cd..a98d81e953b 100644 --- a/aws-lc-fips-sys/builder/cmake_builder.rs +++ b/aws-lc-fips-sys/builder/cmake_builder.rs @@ -3,8 +3,8 @@ use crate::OutputLib::{Crypto, RustWrapper, Ssl}; use crate::{ - cargo_env, execute_command, is_no_asm, target, target_arch, target_os, target_vendor, - OutputLibType, + cargo_env, execute_command, is_no_asm, option_env, target, target_arch, target_os, + target_vendor, OutputLibType, }; use std::collections::HashMap; use std::env; @@ -138,6 +138,20 @@ impl CmakeBuilder { } else { cmake_cfg.define("BUILD_LIBSSL", "OFF"); } + cmake_cfg.define("FIPS", "1"); + + if cfg!(feature = "asan") { + env::set_var("CC", "clang"); + env::set_var("CXX", "clang++"); + env::set_var("ASM", "clang"); + + cmake_cfg.define("ASAN", "1"); + } + + // Allow environment to specify CMake toolchain. + if option_env("CMAKE_TOOLCHAIN_FILE").is_some() { + return cmake_cfg; + } if target_vendor() == "apple" { if target_os().trim() == "ios" { @@ -150,15 +164,6 @@ impl CmakeBuilder { cmake_cfg.define("CMAKE_OSX_ARCHITECTURES", "arm64"); } } - cmake_cfg.define("FIPS", "1"); - - if cfg!(feature = "asan") { - env::set_var("CC", "clang"); - env::set_var("CXX", "clang++"); - env::set_var("ASM", "clang"); - - cmake_cfg.define("ASAN", "1"); - } cmake_cfg } diff --git a/aws-lc-sys/builder/cmake_builder.rs b/aws-lc-sys/builder/cmake_builder.rs index 04ff709213a..910b8afc91f 100644 --- a/aws-lc-sys/builder/cmake_builder.rs +++ b/aws-lc-sys/builder/cmake_builder.rs @@ -3,7 +3,7 @@ use crate::OutputLib::{Crypto, RustWrapper, Ssl}; use crate::{ - cargo_env, execute_command, is_no_asm, target, target_arch, target_env, target_os, + cargo_env, execute_command, is_no_asm, option_env, target, target_arch, target_env, target_os, target_vendor, OutputLibType, }; use std::env; @@ -119,6 +119,19 @@ impl CmakeBuilder { } } + if cfg!(feature = "asan") { + env::set_var("CC", "clang"); + env::set_var("CXX", "clang++"); + env::set_var("ASM", "clang"); + + cmake_cfg.define("ASAN", "1"); + } + + // Allow environment to specify CMake toolchain. + if option_env("CMAKE_TOOLCHAIN_FILE").is_some() { + return cmake_cfg; + } + if target_vendor() == "apple" { if target_os().to_lowercase() == "ios" { cmake_cfg.define("CMAKE_SYSTEM_NAME", "iOS"); @@ -143,11 +156,16 @@ impl CmakeBuilder { cmake_cfg.generator("Ninja"); } - if target_os() == "windows" && target_arch() == "aarch64" && target_env() == "msvc" { + if target_os() == "windows" + && target_arch() == "aarch64" + && target_env() == "msvc" + && option_env("CMAKE_TOOLCHAIN_FILE_aarch64_pc_windows_msvc").is_none() + { cmake_cfg.generator("Ninja"); cmake_cfg.define("CMAKE_C_COMPILER", "clang-cl"); cmake_cfg.define("CMAKE_CXX_COMPILER", "clang-cl"); cmake_cfg.define("CMAKE_ASM_COMPILER", "clang-cl"); + // If the build host is not aarch64 #[cfg(not(target_arch = "aarch64"))] { // Only needed when cross-compiling @@ -157,14 +175,6 @@ impl CmakeBuilder { } } - if cfg!(feature = "asan") { - env::set_var("CC", "clang"); - env::set_var("CXX", "clang++"); - env::set_var("ASM", "clang"); - - cmake_cfg.define("ASAN", "1"); - } - cmake_cfg }