diff --git a/.github/workflows/cross.yml b/.github/workflows/cross.yml index e740d49540c..ac8facc3dcf 100644 --- a/.github/workflows/cross.yml +++ b/.github/workflows/cross.yml @@ -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 }} diff --git a/aws-lc-fips-sys/builder/main.rs b/aws-lc-fips-sys/builder/main.rs index da6de18856a..ac5d5ed5c93 100644 --- a/aws-lc-fips-sys/builder/main.rs +++ b/aws-lc-fips-sys/builder/main.rs @@ -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); diff --git a/aws-lc-sys/builder/cmake_builder.rs b/aws-lc-sys/builder/cmake_builder.rs index 23ef84f6765..7f6c1b84957 100644 --- a/aws-lc-sys/builder/cmake_builder.rs +++ b/aws-lc-sys/builder/cmake_builder.rs @@ -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; @@ -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 } @@ -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(); @@ -134,6 +130,11 @@ impl CmakeBuilder { return cmake_cfg; } + // See issue: https://github.com/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")] { @@ -157,26 +158,6 @@ 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); } @@ -184,6 +165,38 @@ impl CmakeBuilder { 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) { @@ -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() { diff --git a/aws-lc-sys/builder/main.rs b/aws-lc-sys/builder/main.rs index 866d2055b89..4bf220138b0 100644 --- a/aws-lc-sys/builder/main.rs +++ b/aws-lc-sys/builder/main.rs @@ -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); @@ -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();