From 4a1501912f84af33d9f4f21b853ace3b3b113e9d Mon Sep 17 00:00:00 2001 From: Morten Bek Ditlevsen Date: Tue, 24 Nov 2026 15:07:15 +0100 Subject: [PATCH] Build with SwiftPM on Windows - Defines _WINSOCKAPI_, NOMINMAX and NOCRYPT on Windows, as swift-nio-ssl's copy of BoringSSL does (2.37.3): otherwise windows.h's winsock.h clashes with winsock2.h. - Renames the thread-exit callback on Windows with a define (thread_win.cc allows it to be a macro). Unprefixed, it clashes with the one in swift-crypto's BoringSSL when both are linked into one binary. - Compiles the error tables from gen/crypto/err_data.cc instead of err_data.c. crypto/err/err.cc (C++) declares them without extern "C"; elsewhere a global variable's C++ name is its C name, but on Windows it isn't, so the C definitions didn't link. --- Package.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index bce195cd..e1e82153 100644 --- a/Package.swift +++ b/Package.swift @@ -268,7 +268,11 @@ let package = Package( "crypto/x509/x_val.cc", "crypto/x509/x_x509.cc", "crypto/x509/x_x509a.cc", - "err_data.c", + // Not err_data.c: crypto/err/err.cc (C++) declares these tables + // without extern "C", which on Windows gives their C++ names a + // different mangling from their C ones. gen/crypto/err_data.cc is + // the same tables in C++. + "gen/crypto/err_data.cc", "ssl/bio_ssl.cc", "ssl/d1_both.cc", "ssl/d1_lib.cc", @@ -315,6 +319,16 @@ let package = Package( cSettings: [ .define("OPENSSL_NO_ASM", to: "1"), + // As swift-nio-ssl's copy of BoringSSL: windows.h includes + // winsock.h, which clashes with winsock2.h, unless _WINSOCKAPI_ is + // defined. + .define("_WINSOCKAPI_", .when(platforms: [.windows])), + .define("NOMINMAX", .when(platforms: [.windows])), + .define("NOCRYPT", .when(platforms: [.windows])), + // Windows only: the thread-exit callback isn't prefixed, so it would + // clash with the one in other copies of BoringSSL (swift-crypto's) + // in the same binary. thread_win.cc allows it to be a macro. + .define("p_thread_callback_boringssl", to: "p_thread_callback_boringssl_grpc", .when(platforms: [.windows])), .headerSearchPath("./"), .headerSearchPath("include/"), ]