Skip to content

Commit

Permalink
Update Windows build configs
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Jul 11, 2024
1 parent b907119 commit 0ebbca3
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 41 deletions.
70 changes: 53 additions & 17 deletions .github/workflows/cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,43 +134,79 @@ jobs:
- 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
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: '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
if: ${{ matrix.target == 'aarch64-pc-windows-msvc' }}
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
54 changes: 32 additions & 22 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 Down Expand Up @@ -70,6 +70,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 +135,35 @@ impl CmakeBuilder {
return cmake_cfg;
}

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);
}
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.define("CMAKE_GENERATOR_PLATFORM", "ARM64");
cmake_cfg.define("CMAKE_SYSTEM_NAME", "Windows");
cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", "ARM64");
}
("msvc", "x86") => {
cmake_cfg.define("CMAKE_SYSTEM_NAME", "");
cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", "");
}
_ => {}
}
}

// If the build environment vendor is Apple
#[cfg(target_vendor = "apple")]
{
Expand All @@ -157,26 +187,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);
}
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 0ebbca3

Please sign in to comment.