From c8196b9f99795260851bc39d889111aba40d2513 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Wed, 30 Sep 2026 16:36:21 +1000 Subject: [PATCH] [build] msquic: fix static MinGW linking --- cmake/MsQuic.cmake | 26 +++++++++++++++++++ cmake/toolchains/msquic-clangcl-mingw64.cmake | 1 + cmake/toolchains/msquic-mingw-compat.h | 6 ++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/cmake/MsQuic.cmake b/cmake/MsQuic.cmake index 2fa9fc45..ce6ac192 100644 --- a/cmake/MsQuic.cmake +++ b/cmake/MsQuic.cmake @@ -82,6 +82,9 @@ function(lg_add_static_msquic) find_program(LG_MSQUIC_WINDRES NAMES "${MINGW64_TRIPLE}-windres" x86_64-w64-mingw32-windres REQUIRED) + find_program(LG_MSQUIC_DLLTOOL + NAMES "${MINGW64_TRIPLE}-dlltool" x86_64-w64-mingw32-dlltool + REQUIRED) # MsQuic's Windows sources use the CL command-line ABI and its monolithic # archive rule uses lib.exe syntax. Compile those sources with clang-cl, @@ -90,6 +93,29 @@ function(lg_add_static_msquic) set(LG_MSQUIC_IMPORT_DIR "${LG_MSQUIC_BINARY_DIR}/mingw-imports") file(MAKE_DIRECTORY "${LG_MSQUIC_IMPORT_DIR}") + set(LG_MSQUIC_SECUR32EX_DEF + "${LG_MSQUIC_IMPORT_DIR}/secur32ex.def") + set(LG_MSQUIC_SECUR32EX_LIBRARY + "${LG_MSQUIC_IMPORT_DIR}/secur32ex.lib") + file(WRITE "${LG_MSQUIC_SECUR32EX_DEF}" + "LIBRARY secur32.dll\n" + "EXPORTS\n" + " QueryContextAttributesExW\n") + execute_process( + COMMAND "${LG_MSQUIC_DLLTOOL}" + --input-def "${LG_MSQUIC_SECUR32EX_DEF}" + --output-lib "${LG_MSQUIC_SECUR32EX_LIBRARY}" + RESULT_VARIABLE LG_MSQUIC_DLLTOOL_RESULT + ERROR_VARIABLE LG_MSQUIC_DLLTOOL_ERROR) + if(NOT LG_MSQUIC_DLLTOOL_RESULT EQUAL 0) + message(FATAL_ERROR + "Unable to create the extended Secur32 import library: " + "${LG_MSQUIC_DLLTOOL_ERROR}") + endif() + + list(APPEND LG_MSQUIC_SYSTEM_LIBRARIES + "${LG_MSQUIC_SECUR32EX_LIBRARY}") + foreach(LG_MSQUIC_SYSTEM_LIBRARY onecore secur32 diff --git a/cmake/toolchains/msquic-clangcl-mingw64.cmake b/cmake/toolchains/msquic-clangcl-mingw64.cmake index 864469f5..faa6a881 100644 --- a/cmake/toolchains/msquic-clangcl-mingw64.cmake +++ b/cmake/toolchains/msquic-clangcl-mingw64.cmake @@ -111,6 +111,7 @@ list(APPEND MSQUIC_CLANG_CL_OPTIONS "/clang:-Wno-int-conversion" "/clang:-Wno-unused-function" "/clang:-Wno-incompatible-pointer-types" + "/clang:-Wno-duplicate-decl-specifier" "/FI${MSQUIC_COMPAT_HEADER}") list(JOIN MSQUIC_CLANG_CL_OPTIONS " " MSQUIC_CLANG_CL_FLAGS) diff --git a/cmake/toolchains/msquic-mingw-compat.h b/cmake/toolchains/msquic-mingw-compat.h index 627dc611..9f5a8d19 100644 --- a/cmake/toolchains/msquic-mingw-compat.h +++ b/cmake/toolchains/msquic-mingw-compat.h @@ -22,7 +22,7 @@ #define _H_LG_MSQUIC_MINGW_COMPAT_ #ifndef FORCEINLINE -#define FORCEINLINE __inline__ __attribute__((__always_inline__)) +#define FORCEINLINE __forceinline #endif #ifndef EXTERN_C_START @@ -43,6 +43,10 @@ #include +#ifndef __cplusplus +#define inline static __inline__ +#endif + #undef UNREFERENCED_PARAMETER #define UNREFERENCED_PARAMETER(parameter) ((void)(parameter))