Skip to content

Commit

Permalink
Test more windows targets (#452)
Browse files Browse the repository at this point in the history
* Update Windows build configs

* Remove ninja
  • Loading branch information
justsmth authored Jul 16, 2024
1 parent 4b9bd34 commit eeac93b
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 58 deletions.
75 changes: 55 additions & 20 deletions .github/workflows/cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,45 +132,80 @@ jobs:
toolchain: stable
target: aarch64-pc-windows-msvc
- name: Install cargo-xwin and bindgen-cli
run: cargo install cargo-xwin bindgen-cli
run: cargo install --locked 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
run: cargo xwin build -p aws-lc-rs --release --all-targets --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
run: cargo xwin build -p aws-lc-rs --release --all-targets --target aarch64-pc-windows-msvc

aws-lc-rs-windows-mingw:
aws-lc-rs-windows-gnu:
if: github.repository_owner == 'aws'
name: x86_64-pc-windows-gnu
name: ${{ matrix.target }}
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
target:
- 'x86_64-pc-windows-gnu'
# TODO: Fails in GitHub CI. Appears to be related to bindgen.
# .../base.h:61:10: fatal error: 'stdlib.h' file not found
# - 'i686-pc-windows-gnu'
steps:
- uses: ilammy/setup-nasm@v1
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- uses: dtolnay/rust-toolchain@master
id: toolchain
with:
toolchain: stable
target: x86_64-pc-windows-gnu
- name: Debug Test on `x86_64-pc-windows-gnu`
run: cargo test -p aws-lc-rs --target x86_64-pc-windows-gnu --features bindgen
- name: Release test on `x86_64-pc-windows-gnu`
run: cargo test -p aws-lc-rs --release --target x86_64-pc-windows-gnu --features bindgen
target: ${{ matrix.target }}
- name: Debug Test on `${{ matrix.target }}`
run: cargo test -p aws-lc-rs --target ${{ matrix.target }} --features bindgen
- name: Release test on `${{ matrix.target }}`
run: cargo test -p aws-lc-rs --release --target ${{ matrix.target }} --features bindgen

aws-lc-rs-windows-arm64:
if: github.repository_owner == 'aws'
name: aarch64-pc-windows-msvc
aws-lc-rs-windows-msvc:
if: ${{ github.repository_owner == 'aws' }}
name: ${{ matrix.target }} - ${{ (matrix.crt_static == '1' && 'crt-static and /WX') || '/WX' }}
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
target:
- 'x86_64-pc-windows-msvc'
- 'i686-pc-windows-msvc'
- 'aarch64-pc-windows-msvc'
crt_static:
- '0'
- '1'
steps:
- uses: actions/checkout@v3
- name: Install NASM
if: ${{ matrix.target == 'x86_64-pc-windows-msvc' || matrix.target == 'i686-pc-windows-msvc' }}
uses: ilammy/setup-nasm@v1
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Install ninja-build tool
uses: seanmiddleditch/gha-setup-ninja@v4
- uses: dtolnay/rust-toolchain@master
id: toolchain
with:
toolchain: stable
target: aarch64-pc-windows-msvc
- name: Build for `aarch64-pc-windows-msvc`
run: cargo build -p aws-lc-rs --target aarch64-pc-windows-msvc --features bindgen
target: ${{ matrix.target }}
- name: Set ACTION_CARGO
run: |
if ('${{ matrix.target }}' -like '*aarch64*') {
echo "ACTION_CARGO=build" | Out-File -FilePath $env:GITHUB_ENV -Append
} else {
echo "ACTION_CARGO=test" | Out-File -FilePath $env:GITHUB_ENV -Append
}
- name: Set RUSTFLAGS
run: |
if ('${{ matrix.crt_static }}' -eq '1') {
echo "RUSTFLAGS=-Clink-arg=/WX -Ctarget-feature=+crt-static" | Out-File -FilePath $env:GITHUB_ENV -Append
} else {
echo "RUSTFLAGS=-Clink-arg=/WX" | Out-File -FilePath $env:GITHUB_ENV -Append
}
- name: Debug build
run: cargo ${{ env.ACTION_CARGO }} -p aws-lc-rs --all-targets --target ${{ matrix.target }} --features bindgen
- name: Release Build for ${{ matrix.target }}
run: cargo ${{ env.ACTION_CARGO }} --release -p aws-lc-rs --all-targets --target ${{ matrix.target }}
2 changes: 1 addition & 1 deletion aws-lc-fips-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub(crate) struct TestCommandResult {
status: bool,
}

const MAX_CMD_OUTPUT_SIZE: usize = 1 << 14;
const MAX_CMD_OUTPUT_SIZE: usize = 1 << 15;
fn execute_command(executable: &OsStr, args: &[&OsStr]) -> TestCommandResult {
if let Ok(mut result) = Command::new(executable).args(args).output() {
result.stderr.truncate(MAX_CMD_OUTPUT_SIZE);
Expand Down
79 changes: 43 additions & 36 deletions aws-lc-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, emit_warning, execute_command, is_no_asm, option_env, target, target_arch,
target_env, target_os, target_underscored, target_vendor, OutputLibType,
cargo_env, emit_warning, execute_command, is_crt_static, is_no_asm, option_env, target,
target_arch, target_env, target_os, target_underscored, target_vendor, OutputLibType,
};
use std::env;
use std::ffi::OsStr;
Expand All @@ -21,11 +21,6 @@ fn test_clang_cl_command() -> bool {
execute_command("clang-cl".as_ref(), &["--version".as_ref()]).status
}

fn test_ninja_command() -> bool {
execute_command("ninja".as_ref(), &["--version".as_ref()]).status
|| execute_command("ninja-build".as_ref(), &["--version".as_ref()]).status
}

fn test_nasm_command() -> bool {
execute_command("nasm".as_ref(), &["-version".as_ref()]).status
}
Expand Down Expand Up @@ -70,6 +65,7 @@ impl CmakeBuilder {
cmake::Config::new(&self.manifest_dir)
}

#[allow(clippy::too_many_lines)]
fn prepare_cmake_build(&self) -> cmake::Config {
let mut cmake_cfg = self.get_cmake_config();

Expand Down Expand Up @@ -134,6 +130,11 @@ impl CmakeBuilder {
return cmake_cfg;
}

// See issue: https:/aws/aws-lc-rs/issues/453
if target_os() == "windows" {
Self::configure_windows(&mut cmake_cfg);
}

// If the build environment vendor is Apple
#[cfg(target_vendor = "apple")]
{
Expand All @@ -157,33 +158,45 @@ impl CmakeBuilder {
cmake_cfg.define("CMAKE_THREAD_LIBS_INIT", "-lpthread");
}

if (target_env() != "msvc") && test_ninja_command() {
// Use Ninja if available
cmake_cfg.generator("Ninja");
}

if target_underscored() == "aarch64_pc_windows_msvc" {
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
cmake_cfg.define("CMAKE_C_COMPILER_TARGET", "arm64-pc-windows-msvc");
cmake_cfg.define("CMAKE_CXX_COMPILER_TARGET", "arm64-pc-windows-msvc");
cmake_cfg.define("CMAKE_ASM_COMPILER_TARGET", "arm64-pc-windows-msvc");
}
}

if target_env() == "ohos" {
Self::configure_open_harmony(&mut cmake_cfg);
}

cmake_cfg
}

fn configure_windows(cmake_cfg: &mut cmake::Config) {
match (target_env().as_str(), target_arch().as_str()) {
("msvc", "aarch64") => {
cmake_cfg.generator_toolset(format!(
"ClangCL{}",
if cfg!(target_arch = "x86_64") {
",host=x64"
} else {
""
}
));
cmake_cfg.static_crt(is_crt_static());
cmake_cfg.define("CMAKE_GENERATOR_PLATFORM", "ARM64");
cmake_cfg.define("CMAKE_SYSTEM_NAME", "Windows");
cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", "ARM64");
}
("msvc", "x86") => {
cmake_cfg.static_crt(is_crt_static());
cmake_cfg.define("CMAKE_SYSTEM_NAME", "");
cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", "");
}
("msvc", _) => {
cmake_cfg.static_crt(is_crt_static());
}
("gnu", "x86") => {
cmake_cfg.define("CMAKE_SYSTEM_NAME", "Windows");
cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", "x86");
}
_ => {}
}
}

fn configure_open_harmony(cmake_cfg: &mut cmake::Config) {
const OHOS_NDK_HOME: &str = "OHOS_NDK_HOME";
if let Ok(ndk) = env::var(OHOS_NDK_HOME) {
Expand Down Expand Up @@ -245,15 +258,9 @@ impl crate::Builder for CmakeBuilder {
eprintln!("Missing dependency: nasm");
missing_dependency = true;
}
if target_arch() == "aarch64" && target_env() == "msvc" {
if !test_ninja_command() {
eprintln!("Missing dependency: ninja");
missing_dependency = true;
}
if !test_clang_cl_command() {
eprintln!("Missing dependency: clang-cl");
missing_dependency = true;
}
if target_arch() == "aarch64" && target_env() == "msvc" && !test_clang_cl_command() {
eprintln!("Missing dependency: clang-cl");
missing_dependency = true;
}
}
if let Some(cmake_cmd) = find_cmake_command() {
Expand Down
7 changes: 6 additions & 1 deletion aws-lc-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub(crate) struct TestCommandResult {
status: bool,
}

const MAX_CMD_OUTPUT_SIZE: usize = 1 << 12;
const MAX_CMD_OUTPUT_SIZE: usize = 1 << 15;
fn execute_command(executable: &OsStr, args: &[&OsStr]) -> TestCommandResult {
if let Ok(mut result) = Command::new(executable).args(args).output() {
result.stderr.truncate(MAX_CMD_OUTPUT_SIZE);
Expand Down Expand Up @@ -392,6 +392,11 @@ fn prepare_cargo_cfg() {
*/
}

fn is_crt_static() -> bool {
let features = cargo_env("CARGO_CFG_TARGET_FEATURE");
features.contains("crt-static")
}

fn main() {
initialize();
prepare_cargo_cfg();
Expand Down

0 comments on commit eeac93b

Please sign in to comment.