Skip to content

Commit

Permalink
Allow cmake toolchain env (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth authored Jun 5, 2024
1 parent 7607cd1 commit cd34120
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 21 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 16 additions & 11 deletions aws-lc-fips-sys/builder/cmake_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" {
Expand All @@ -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
}
Expand Down
30 changes: 20 additions & 10 deletions aws-lc-sys/builder/cmake_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit cd34120

Please sign in to comment.