diff --git a/.github/workflows/cross.yml b/.github/workflows/cross.yml index 1607210f1d2..bd799f9d136 100644 --- a/.github/workflows/cross.yml +++ b/.github/workflows/cross.yml @@ -140,7 +140,7 @@ jobs: aws-lc-rs-windows-gnu: if: github.repository_owner == 'aws' - name: ${{ matrix.target }} + name: ${{ matrix.target }} ${{ (matrix.ninja == '1' && 'w/ Ninja') || 'w/o Ninja'}} runs-on: windows-latest strategy: fail-fast: false @@ -148,11 +148,17 @@ jobs: target: - 'x86_64-pc-windows-gnu' # TODO: 'i686-pc-windows-gnu' + ninja: + - '0' + - '1' steps: - uses: ilammy/setup-nasm@v1 - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' + - name: Install ninja-build tool + if: ${{ matrix.ninja == '1' }} + uses: seanmiddleditch/gha-setup-ninja@v4 - uses: dtolnay/rust-toolchain@master id: toolchain with: @@ -164,8 +170,8 @@ jobs: run: cargo test -p aws-lc-rs --release --target ${{ matrix.target }} --features bindgen aws-lc-rs-windows-msvc: - if: github.repository_owner == 'aws' - name: ${{ matrix.target }} + if: ${{ github.repository_owner == 'aws' }} + name: ${{ matrix.target }} ${{ (matrix.ninja == '1' && 'w/ Ninja') || 'w/o Ninja'}} - ${{ (matrix.crt_static == '1' && '/WX and crt-static') || '/WX' }} runs-on: windows-latest strategy: fail-fast: false @@ -174,8 +180,12 @@ jobs: - 'x86_64-pc-windows-msvc' - 'i686-pc-windows-msvc' - 'aarch64-pc-windows-msvc' - env: - RUSTFLAGS: '-Clink-arg=/WX' + ninja: + - '0' + - '1' + crt_static: + - '0' + - '1' steps: - name: Install NASM if: ${{ matrix.target == 'x86_64-pc-windows-msvc' || matrix.target == 'i686-pc-windows-msvc' }} @@ -184,6 +194,7 @@ jobs: with: submodules: 'recursive' - name: Install ninja-build tool + if: ${{ matrix.ninja == '1' }} uses: seanmiddleditch/gha-setup-ninja@v4 - uses: dtolnay/rust-toolchain@master id: toolchain @@ -197,9 +208,16 @@ jobs: } else { echo "ACTION_CARGO=test" | Out-File -FilePath $env:GITHUB_ENV -Append } - - name: Degbug build for ${{ matrix.target }} + - 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 + if: ${{ matrix.target != 'aarch64-pc-windows-msvc' || matrix.ninja == '1' }} run: cargo ${{ env.ACTION_CARGO }} -p aws-lc-rs --all-targets --target ${{ matrix.target }} --features bindgen - - name: No-default-features Debug Build for ${{ matrix.target }} - run: cargo ${{ env.ACTION_CARGO }} -p aws-lc-rs --all-targets --target ${{ matrix.target }} --no-default-features --features aws-lc-sys - name: Release Build for ${{ matrix.target }} + if: ${{ matrix.target != 'aarch64-pc-windows-msvc' || matrix.ninja == '1' }} run: cargo ${{ env.ACTION_CARGO }} --release -p aws-lc-rs --all-targets --target ${{ matrix.target }} diff --git a/aws-lc-sys/builder/cmake_builder.rs b/aws-lc-sys/builder/cmake_builder.rs index fc867a35c1f..894919139a2 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; @@ -67,12 +67,7 @@ impl CmakeBuilder { } fn get_cmake_config(&self) -> cmake::Config { - let mut cmake_cfg = cmake::Config::new(&self.manifest_dir); - if cargo_env("CARGO_ENCODED_RUSTFLAGS").contains("-Ctarget-feature=+crt-static") { - // See issue: https://github.com/aws/aws-lc-rs/issues/453 - cmake_cfg.static_crt(true); - } - cmake_cfg + cmake::Config::new(&self.manifest_dir) } #[allow(clippy::too_many_lines)] @@ -91,9 +86,6 @@ impl CmakeBuilder { } else { cmake_cfg.define("CMAKE_BUILD_TYPE", "release"); } - } else if target_os() == "windows" { - // See issue: https://github.com/aws/aws-lc-rs/issues/453 - cmake_cfg.define("CMAKE_BUILD_TYPE", "relwithdebinfo"); } else { cmake_cfg.define("CMAKE_BUILD_TYPE", "debug"); } @@ -142,14 +134,17 @@ impl CmakeBuilder { return cmake_cfg; } - if test_ninja_command() { - // Use Ninja if available - cmake_cfg.generator("Ninja"); - } - - if target_os() == "windows" && target_arch() == "x86" && target_env() == "msvc" { - cmake_cfg.define("CMAKE_SYSTEM_NAME", ""); - cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", ""); + if target_os() == "windows" { + // See issue: https://github.com/aws/aws-lc-rs/issues/453 + if is_crt_static() { + cmake_cfg.static_crt(true); + } else { + cmake_cfg.static_crt(false); + } + if target_arch() == "x86" && target_env() == "msvc" { + cmake_cfg.define("CMAKE_SYSTEM_NAME", ""); + cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", ""); + } } if target_vendor() == "apple" { @@ -173,7 +168,7 @@ impl CmakeBuilder { } if target_underscored() == "aarch64_pc_windows_msvc" { - cmake_cfg.generator("Ninja"); + //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"); @@ -181,9 +176,15 @@ impl CmakeBuilder { #[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"); + cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", "ARM64"); + cmake_cfg.define("CMAKE_C_FLAGS_INIT", "--target=arm64-pc-windows-msvc"); + cmake_cfg.define("CMAKE_CXX_FLAGS_INIT", "--target=arm64-pc-windows-msvc"); + cmake_cfg.define("CMAKE_ASM_FLAGS_INIT", "--target=arm64-pc-windows-msvc"); + + cmake_cfg.define("CMAKE_FIND_ROOT_PATH_MODE_PROGRAM", "NEVER"); + cmake_cfg.define("CMAKE_FIND_ROOT_PATH_MODE_LIBRARY", "ONLY"); + cmake_cfg.define("CMAKE_FIND_ROOT_PATH_MODE_INCLUDE", "ONLY"); + cmake_cfg.define("CMAKE_FIND_ROOT_PATH_MODE_INCLUDE", "ONLY"); } } diff --git a/aws-lc-sys/builder/main.rs b/aws-lc-sys/builder/main.rs index 866d2055b89..bf3e9fffee0 100644 --- a/aws-lc-sys/builder/main.rs +++ b/aws-lc-sys/builder/main.rs @@ -369,6 +369,11 @@ fn is_no_asm() -> bool { unsafe { AWS_LC_SYS_NO_ASM } } +fn is_crt_static() -> bool { + let features = cargo_env("CARGO_CFG_TARGET_FEATURE"); + features.contains("crt-static") +} + fn has_bindgen_feature() -> bool { cfg!(feature = "bindgen") }