Skip to content

Commit ebcbfc6

Browse files
etcwildeSteelskin
andauthored
build: Make swift-crypto build on Windows (#385)
Make swift-crypto build on Windows - [X] I've run tests to see all new and existing tests pass - [X] I've followed the code style of the rest of the project - [X] I've read the [Contribution Guidelines](CONTRIBUTING.md) - [X] I've updated the documentation if necessary - [N/A] I've run `.script/generate_boilerplate_files_with_gyb` and included updated generated files in a commit of this pull request Currently, swift-crypto on the main branch does not build on Windows. * Add the Windows Arm64 assembly files to the CMake build. * Add appropriate CMake options for swift-crypto to build on Windows. swift-crypto can be built on Windows from main Fixes #369 --------- Co-authored-by: Cory Benfield <[email protected]> (cherry picked from commit 9934678) (#370) Co-authored-by: Fabrice de Gans <[email protected]>
1 parent 785709b commit ebcbfc6

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
cmake_minimum_required(VERSION 3.15.1)
1616

17+
if(POLICY CMP0157)
18+
cmake_policy(SET CMP0157 NEW)
19+
endif()
20+
1721
project(SwiftCrypto
1822
LANGUAGES ASM C CXX Swift)
1923

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

54+
set(CMAKE_CXX_STANDARD 17)
55+
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
56+
# We need to ensure that we don't include the min/max macros from the Windows SDK.
57+
add_compile_definitions(NOMINMAX)
58+
# We can only link against the DLL version of the MSVC runtime library for now.
59+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
60+
if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2)
61+
# We need to set the static library prefix to "lib" so that we can link against the static libraries.
62+
set(CMAKE_STATIC_LIBRARY_PREFIX_Swift "lib")
63+
endif()
64+
endif()
65+
5066
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
5167
find_package(dispatch CONFIG)
5268
find_package(Foundation CONFIG)

Sources/CCryptoBoringSSL/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,27 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD" AND CMAKE_SYSTEM_PROCES
334334
gen/bcm/vpaes-armv8-linux.S
335335
gen/crypto/chacha-armv8-linux.S
336336
gen/crypto/chacha20_poly1305_armv8-linux.S)
337+
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|amd64|x86_64")
338+
target_sources(CCryptoBoringSSL PRIVATE
339+
)
340+
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64|arm64|aarch64")
341+
target_sources(CCryptoBoringSSL PRIVATE
342+
gen/bcm/aesv8-armv8-win.S
343+
gen/bcm/aesv8-gcm-armv8-win.S
344+
gen/bcm/armv8-mont-win.S
345+
gen/bcm/bn-armv8-win.S
346+
gen/bcm/ghash-neon-armv8-win.S
347+
gen/bcm/ghashv8-armv8-win.S
348+
gen/bcm/p256-armv8-asm-win.S
349+
gen/bcm/p256_beeu-armv8-asm-win.S
350+
gen/bcm/sha1-armv8-win.S
351+
gen/bcm/sha256-armv8-win.S
352+
gen/bcm/sha512-armv8-win.S
353+
gen/bcm/vpaes-armv8-win.S
354+
gen/crypto/chacha-armv8-win.S
355+
gen/crypto/chacha20_poly1305_armv8-win.S)
356+
else()
357+
message(FATAL_ERROR "platform sources are not defined here for ${CMAKE_SYSTEM_NAME} on ${CMAKE_SYSTEM_PROCESSOR}")
337358
endif()
338359

339360
target_include_directories(CCryptoBoringSSL PUBLIC

0 commit comments

Comments
 (0)