Skip to content

Commit

Permalink
Fix building and linking OpenSSL on Windows ARM (#122)
Browse files Browse the repository at this point in the history
* Fix building for Windows on ARM by including msvc libraries

* Fix linking OpenSSL on Windows ARM64
  • Loading branch information
mnightingale authored Jun 26, 2024
1 parent 6112115 commit 5c73f78
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def build_extension(self, ext: Extension):
"src/unlocked_ssl.cc",
],
"gcc_flags": ["-Wno-unused-parameter", "-Wno-missing-field-initializers"],
"msvc_x86_libraries": ["ws2_32"],
"msvc_libraries": ["ws2_32"],
},
{
"sources": [
Expand Down Expand Up @@ -345,8 +345,8 @@ def build_extension(self, ext: Extension):
if self.compiler.compiler_type == "msvc":
if IS_X86 and "msvc_x86_flags" in source_files:
args["extra_postargs"] += source_files["msvc_x86_flags"]
if IS_X86 and "msvc_x86_libraries" in source_files:
ext.libraries += source_files["msvc_x86_libraries"]
if "msvc_libraries" in source_files:
ext.libraries += source_files["msvc_libraries"]
else:
if "gcc_flags" in source_files:
args["extra_postargs"] += source_files["gcc_flags"]
Expand Down
10 changes: 6 additions & 4 deletions src/unlocked_ssl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ void openssl_init() {
if(!SSLWantReadError) goto cleanup;

#if defined(_WIN32) || defined(__CYGWIN__)
#ifdef _M_ARM64
HMODULE windows_openssl_handle = GetModuleHandle(TEXT("libssl-3-arm64.dll"));
#else
HMODULE windows_openssl_handle = GetModuleHandle(TEXT("libssl-3.dll"));
if(!windows_openssl_handle) {
windows_openssl_handle = GetModuleHandle(TEXT("libssl-1_1.dll"));
if(!windows_openssl_handle) goto cleanup;
}
if(!windows_openssl_handle) windows_openssl_handle = GetModuleHandle(TEXT("libssl-1_1.dll"));
#endif
if(!windows_openssl_handle) goto cleanup;

*(void**)&SSL_read_ex = GetProcAddress(windows_openssl_handle, "SSL_read_ex");
*(void**)&SSL_get_error = GetProcAddress(windows_openssl_handle, "SSL_get_error");
Expand Down

0 comments on commit 5c73f78

Please sign in to comment.