From 0503e1737559a61509e84927d95bb14fff8ba5f6 Mon Sep 17 00:00:00 2001 From: erw7 Date: Sun, 31 Oct 2021 18:03:30 +0900 Subject: [PATCH] fix(build): fix build failure in MinGW The new MinGW fails to build libuv due to a typedef conflict between mstcpip.h and src/win/winapi.h. This change avoids conflicts by disabling typedef in the MinGW header. --- third-party/cmake/BuildLibuv.cmake | 8 +++++++- .../patches/libuv-disable-typedef-MinGW.patch | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 third-party/patches/libuv-disable-typedef-MinGW.patch diff --git a/third-party/cmake/BuildLibuv.cmake b/third-party/cmake/BuildLibuv.cmake index 32fe2659a4..dce64c777b 100644 --- a/third-party/cmake/BuildLibuv.cmake +++ b/third-party/cmake/BuildLibuv.cmake @@ -5,7 +5,7 @@ function(BuildLibuv) cmake_parse_arguments(_libuv "BUILD_IN_SOURCE" "TARGET" - "CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND" + "PATCH_COMMAND;CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND" ${ARGN}) if(NOT _libuv_CONFIGURE_COMMAND AND NOT _libuv_BUILD_COMMAND @@ -28,6 +28,7 @@ function(BuildLibuv) -DTARGET=${_libuv_TARGET} -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake + PATCH_COMMAND "${_libuv_PATCH_COMMAND}" BUILD_IN_SOURCE ${_libuv_BUILD_IN_SOURCE} CONFIGURE_COMMAND "${_libuv_CONFIGURE_COMMAND}" BUILD_COMMAND "${_libuv_BUILD_COMMAND}" @@ -62,6 +63,10 @@ elseif(WIN32) set(BUILD_SHARED ON) elseif(MINGW) set(BUILD_SHARED OFF) + set(LIBUV_PATCH_COMMAND + ${GIT_EXECUTABLE} -C ${DEPS_BUILD_DIR}/src/libuv init + COMMAND ${GIT_EXECUTABLE} -C ${DEPS_BUILD_DIR}/src/libuv apply --ignore-whitespace + ${CMAKE_CURRENT_SOURCE_DIR}/patches/libuv-disable-typedef-MinGW.patch) else() message(FATAL_ERROR "Trying to build libuv in an unsupported system ${CMAKE_SYSTEM_NAME}/${CMAKE_C_COMPILER_ID}") endif() @@ -75,6 +80,7 @@ elseif(WIN32) -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DBUILD_SHARED_LIBS=${BUILD_SHARED} -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR} + PATCH_COMMAND ${LIBUV_PATCH_COMMAND} BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}) diff --git a/third-party/patches/libuv-disable-typedef-MinGW.patch b/third-party/patches/libuv-disable-typedef-MinGW.patch new file mode 100644 index 0000000000..a47893cede --- /dev/null +++ b/third-party/patches/libuv-disable-typedef-MinGW.patch @@ -0,0 +1,19 @@ +diff --git a/include/uv/win.h b/include/uv/win.h +index f5f1d3a3..64a0dfd9 100644 +--- a/include/uv/win.h ++++ b/include/uv/win.h +@@ -45,7 +45,14 @@ typedef struct pollfd { + #endif + + #include ++// Disable the typedef in mstcpip.h of MinGW. ++#define _TCP_INITIAL_RTO_PARAMETERS _TCP_INITIAL_RTO_PARAMETERS__ ++#define TCP_INITIAL_RTO_PARAMETERS TCP_INITIAL_RTO_PARAMETERS__ ++#define PTCP_INITIAL_RTO_PARAMETERS PTCP_INITIAL_RTO_PARAMETERS__ + #include ++#undef _TCP_INITIAL_RTO_PARAMETERS ++#undef TCP_INITIAL_RTO_PARAMETERS ++#undef PTCP_INITIAL_RTO_PARAMETERS + #include + + #include