From e3c4f7d41384d0565a0f79b06413a1d6f6f067a3 Mon Sep 17 00:00:00 2001 From: Justin W Smith <103147162+justsmth@users.noreply.github.com> Date: Mon, 13 May 2024 15:36:53 -0400 Subject: [PATCH] Windows build with clang-cl; CI for Windows/ARM64 build (#1538) ## Issues Needed for: https://github.com/aws/aws-lc-rs/issues/376 ## Description * Updated `CMakeLists.txt` to support a Windows build using `clang-cl`. * Adds CI build/test of Windows/x64 using clang-cl. * Adds CI build of Windows/ARM64 using clang-cl. (Currently there are no runners available for testing Windows/ARM64 executables.) ## Callout * This change removes debug information by default from the "Release" build type. Alternatively, one may retain debug information in the artifacts by adding the `-ggdb` build flag via **CMAKE_C_FLAGS** or by using the "Relwithdebinfo" or "Debug" build types. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license. --- .github/workflows/windows-alt.yml | 55 +++++++++++++++++++++++++++++-- CMakeLists.txt | 36 +++++++++++--------- 2 files changed, 74 insertions(+), 17 deletions(-) diff --git a/.github/workflows/windows-alt.yml b/.github/workflows/windows-alt.yml index 5d808ad198..e25ef83505 100644 --- a/.github/workflows/windows-alt.yml +++ b/.github/workflows/windows-alt.yml @@ -63,12 +63,64 @@ jobs: options: | CMAKE_SYSTEM_NAME=Windows \ CMAKE_SYSTEM_PROCESSOR=x86_64 \ - CMAKE_BUILD_TOOL=ninja.exe \ + CMAKE_MAKE_PROGRAM=ninja.exe \ CMAKE_BUILD_TYPE=Release \ - name: Build Project run: cmake --build ./build --target all - name: Run tests run: cmake --build ./build --target run_tests + clang-cl: + if: github.repository_owner == 'aws' + strategy: + fail-fast: false + matrix: + target: + - x64 + - x64_arm64 + runs-on: windows-latest + steps: + - if: ${{ matrix.target == 'x64' }} + name: Install NASM + uses: ilammy/setup-nasm@v1.5.1 + - name: Remove wrong clang-cl.exe + run: rm "C:/Program Files/LLVM/bin/clang-cl.exe" + - name: Checkout + uses: actions/checkout@v4 + - uses: TheMrMilchmann/setup-msvc-dev@v3 + with: + arch: ${{ matrix.target }} + - if: ${{ matrix.target == 'x64' }} + name: Setup CMake + uses: threeal/cmake-action@v1.3.0 + with: + generator: Ninja + c-compiler: clang-cl + cxx-compiler: clang-cl + options: | + CMAKE_CROSSCOMPILING=${{ ((matrix.target == 'x64') && '0') || '1' }} \ + CMAKE_SYSTEM_NAME=Windows \ + CMAKE_SYSTEM_PROCESSOR=x86_64 \ + CMAKE_BUILD_TYPE=Release \ + - if: ${{ matrix.target == 'x64_arm64' }} + name: Setup CMake + uses: threeal/cmake-action@v1.3.0 + with: + generator: Ninja + c-compiler: clang-cl + cxx-compiler: clang-cl + options: | + CMAKE_CROSSCOMPILING=1 \ + CMAKE_SYSTEM_NAME=Windows \ + CMAKE_SYSTEM_PROCESSOR=ARM64 \ + CMAKE_C_COMPILER_TARGET=arm64-pc-windows-msvc \ + CMAKE_ASM_COMPILER_TARGET=arm64-pc-windows-msvc \ + CMAKE_CXX_COMPILER_TARGET=arm64-pc-windows-msvc \ + CMAKE_BUILD_TYPE=Release \ + - name: Build Project + run: cmake --build ./build --target all + - if: ${{ matrix.target == 'x64' }} + name: Run tests + run: cmake --build ./build --target run_tests cross-mingw: if: github.repository_owner == 'aws' runs-on: ubuntu-22.04 @@ -95,4 +147,3 @@ jobs: - name: x86_64-w64-mingw32 Build/Test run: ./tests/ci/run_cross_mingw_tests.sh x86_64 w64-mingw32 "-DCMAKE_BUILD_TYPE=Release" - diff --git a/CMakeLists.txt b/CMakeLists.txt index 3089697c79..b640b3ffcf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -347,32 +347,38 @@ if(GCC OR CLANG) # TODO(CryptoAlg-759): enable '-Wpedantic' if awslc has to follow c99 spec. if(CLANG OR (GCC AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.1.3")) # GCC 4.1.3 and below do not support all of these flags or they raise false positives. - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -Wall -Wextra -Wno-unused-parameter -Werror") + if (MSVC) + # clang-cl sets different default warnings than clang. It also treats -Wall + # as -Weverything, to match MSVC. Instead -W3 is the alias for -Wall. + # See http://llvm.org/viewvc/llvm-project?view=revision&revision=319116 + set(C_CXX_FLAGS "${C_CXX_FLAGS} -W3 -fmsc-version=1900") + set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-deprecated-declarations") + else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra") + set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wall -fvisibility=hidden -fno-common") + endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused -Wcomment -Wchar-subscripts -Wuninitialized -Wshadow") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wwrite-strings -Wformat-security -Wunused-result") - set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wvla -Wtype-limits") + set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wvla -Wtype-limits -Wno-unused-parameter") endif() + set(C_CXX_FLAGS "${C_CXX_FLAGS} -Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -Wwrite-strings") if(GCC AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "8") # GCC 8.x added a warning called -Wcast-function-type to the -Wextra umbrella. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-cast-function-type") endif() - set(C_CXX_FLAGS "${C_CXX_FLAGS} -Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -Wwrite-strings") - if(MSVC) - # clang-cl sets different default warnings than clang. It also treats -Wall - # as -Weverything, to match MSVC. Instead -W3 is the alias for -Wall. - # See http://llvm.org/viewvc/llvm-project?view=revision&revision=319116 - set(C_CXX_FLAGS "${C_CXX_FLAGS} -W3 -Wno-unused-parameter -fmsc-version=1900") - else() - if(EMSCRIPTEN) - # emscripten's emcc/clang does not accept the "-ggdb" flag. - set(C_CXX_FLAGS "${C_CXX_FLAGS} -g") + if(CMAKE_BUILD_TYPE_LOWER STREQUAL "debug" OR CMAKE_BUILD_TYPE_LOWER STREQUAL "relwithdebinfo") + if (MSVC) + set(C_CXX_FLAGS "${C_CXX_FLAGS} /Zi") else() - set(C_CXX_FLAGS "${C_CXX_FLAGS} -ggdb") + if(EMSCRIPTEN) + # emscripten's emcc/clang does not accept the "-ggdb" flag. + set(C_CXX_FLAGS "${C_CXX_FLAGS} -g") + else() + set(C_CXX_FLAGS "${C_CXX_FLAGS} -ggdb") + endif() endif() - - set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wall -fvisibility=hidden -fno-common") endif() if(MINGW)