Skip to content

build: Make swift-crypto build on Windows #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

cmake_minimum_required(VERSION 3.15.1)

if(POLICY CMP0157)
cmake_policy(SET CMP0157 NEW)
endif()

project(SwiftCrypto
LANGUAGES ASM C CXX Swift)

Expand Down Expand Up @@ -47,6 +51,18 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND NOT CMAKE_CROSSCOMPILING)
set(CMAKE_RANLIB "/usr/bin/ranlib")
endif()

set(CMAKE_CXX_STANDARD 17)
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
# We need to ensure that we don't include the min/max macros from the Windows SDK.
add_compile_definitions(NOMINMAX)
# We can only link against the DLL version of the MSVC runtime library for now.
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2)
# We need to set the static library prefix to "lib" so that we can link against the static libraries.
set(CMAKE_STATIC_LIBRARY_PREFIX_Swift "lib")
endif()
endif()

if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
find_package(dispatch CONFIG)
find_package(Foundation CONFIG)
Expand Down
20 changes: 19 additions & 1 deletion Sources/CCryptoBoringSSL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,26 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD|OpenBSD" AND CMAKE_SYSTE
gen/bcm/vpaes-armv8-linux.S
gen/crypto/chacha-armv8-linux.S
gen/crypto/chacha20_poly1305_armv8-linux.S)
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|amd64|x86_64")
# No assembly sources for x86_64 on Windows.
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64|arm64|aarch64")
target_sources(CCryptoBoringSSL PRIVATE
gen/bcm/aesv8-armv8-win.S
gen/bcm/aesv8-gcm-armv8-win.S
gen/bcm/armv8-mont-win.S
gen/bcm/bn-armv8-win.S
gen/bcm/ghash-neon-armv8-win.S
gen/bcm/ghashv8-armv8-win.S
gen/bcm/p256-armv8-asm-win.S
gen/bcm/p256_beeu-armv8-asm-win.S
gen/bcm/sha1-armv8-win.S
gen/bcm/sha256-armv8-win.S
gen/bcm/sha512-armv8-win.S
gen/bcm/vpaes-armv8-win.S
gen/crypto/chacha-armv8-win.S
gen/crypto/chacha20_poly1305_armv8-win.S)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These files are generated automatically by this script in swift-nio. I think this first needs a patch to swift-nio to ensure that this script can actually generate these two stanzas. Are you open to making that change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I edited the file here to be more friendly for the script. I opened apple/swift-nio#3275 but I could not figure out how to test it.

else()
message(FATAL_ERROR "platform sources are not defined here")
message(FATAL_ERROR "platform sources are not defined here for ${CMAKE_SYSTEM_NAME} on ${CMAKE_SYSTEM_PROCESSOR}")
endif()

target_include_directories(CCryptoBoringSSL PUBLIC
Expand Down