From 1554025781f7431d3f56998887be2c1f9a088739 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Tue, 20 Oct 2020 12:44:26 +0000 Subject: [PATCH 1/2] build: don't build shared libraries for zlib and zlib-ng. Signed-off-by: Piotr Sikora --- bazel/foreign_cc/BUILD | 1 + bazel/foreign_cc/zlib.patch | 49 +++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/bazel/foreign_cc/BUILD b/bazel/foreign_cc/BUILD index c2a214747107..33138016d661 100644 --- a/bazel/foreign_cc/BUILD +++ b/bazel/foreign_cc/BUILD @@ -346,6 +346,7 @@ envoy_cmake_external( "CMAKE_CXX_COMPILER_FORCED": "on", "CMAKE_C_COMPILER_FORCED": "on", "SKIP_BUILD_EXAMPLES": "on", + "BUILD_SHARED_LIBS": "off", # The following entries are for zlib-ng. Since zlib and zlib-ng are compatible source # codes and CMake ignores unknown cache entries, it is fine to combine it into one diff --git a/bazel/foreign_cc/zlib.patch b/bazel/foreign_cc/zlib.patch index d8a7354dc6da..ef54ec60c0f5 100644 --- a/bazel/foreign_cc/zlib.patch +++ b/bazel/foreign_cc/zlib.patch @@ -1,8 +1,53 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index 0fe939d..2f0475a 100644 +index e108c16..5ab1a49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -229,21 +229,22 @@ endif() +@@ -183,10 +183,18 @@ if(MINGW) + set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj) + endif(MINGW) + +-add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) +-add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) +-set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) +-set_target_properties(zlib PROPERTIES SOVERSION 1) ++if(NOT DEFINED BUILD_SHARED_LIBS) ++ add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) ++ add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) ++ set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) ++ set_target_properties(zlib PROPERTIES SOVERSION 1) ++ ++ set(ZLIB_INSTALL_LIBRARIES zlib zlibstatic) ++else() ++ add_library(zlib ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) ++ ++ set(ZLIB_INSTALL_LIBRARIES zlib) ++endif() + + if(NOT CYGWIN) + # This property causes shared libraries on Linux to have the full version +@@ -201,7 +209,7 @@ endif() + + if(UNIX) + # On unix-like platforms the library is almost always called libz +- set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z) ++ set_target_properties(${ZLIB_INSTALL_LIBRARIES} PROPERTIES OUTPUT_NAME z) + if(NOT APPLE) + set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") + endif() +@@ -211,7 +219,7 @@ elseif(BUILD_SHARED_LIBS AND WIN32) + endif() + + if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) +- install(TARGETS zlib zlibstatic ++ install(TARGETS ${ZLIB_INSTALL_LIBRARIES} + RUNTIME DESTINATION "${INSTALL_BIN_DIR}" + ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" + LIBRARY DESTINATION "${INSTALL_LIB_DIR}" ) +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 5ab1a49..cc43333 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -237,21 +237,22 @@ endif() #============================================================================ # Example binaries #============================================================================ From 83c9590574049f143cc7d28108c5d2af7c5182e6 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Tue, 20 Oct 2020 23:09:50 +0000 Subject: [PATCH 2/2] review: fix build on Windows. Signed-off-by: Piotr Sikora --- bazel/foreign_cc/BUILD | 2 +- bazel/foreign_cc/zlib.patch | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/bazel/foreign_cc/BUILD b/bazel/foreign_cc/BUILD index 33138016d661..8e0bf0b32f13 100644 --- a/bazel/foreign_cc/BUILD +++ b/bazel/foreign_cc/BUILD @@ -374,7 +374,7 @@ envoy_cmake_external( "//conditions:default": "@net_zlib//:all", }), static_libraries = select({ - "//bazel:windows_x86_64": ["zlibstatic.lib"], + "//bazel:windows_x86_64": ["zlib.lib"], "//conditions:default": ["libz.a"], }), ) diff --git a/bazel/foreign_cc/zlib.patch b/bazel/foreign_cc/zlib.patch index ef54ec60c0f5..aeeeed3147fd 100644 --- a/bazel/foreign_cc/zlib.patch +++ b/bazel/foreign_cc/zlib.patch @@ -1,5 +1,5 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index e108c16..5ab1a49 100644 +index e108c16..2cd82ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,10 +183,18 @@ if(MINGW) @@ -25,16 +25,26 @@ index e108c16..5ab1a49 100644 if(NOT CYGWIN) # This property causes shared libraries on Linux to have the full version -@@ -201,7 +209,7 @@ endif() +@@ -196,22 +204,22 @@ if(NOT CYGWIN) + # + # This has no effect with MSVC, on that platform the version info for + # the DLL comes from the resource file win32/zlib1.rc +- set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION}) ++ set_target_properties(${ZLIB_INSTALL_LIBRARIES} PROPERTIES VERSION ${ZLIB_FULL_VERSION}) + endif() if(UNIX) # On unix-like platforms the library is almost always called libz - set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z) + set_target_properties(${ZLIB_INSTALL_LIBRARIES} PROPERTIES OUTPUT_NAME z) if(NOT APPLE) - set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") +- set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") ++ set_target_properties(${ZLIB_INSTALL_LIBRARIES} PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") endif() -@@ -211,7 +219,7 @@ elseif(BUILD_SHARED_LIBS AND WIN32) + elseif(BUILD_SHARED_LIBS AND WIN32) + # Creates zlib1.dll when building shared library version +- set_target_properties(zlib PROPERTIES SUFFIX "1.dll") ++ set_target_properties(${ZLIB_INSTALL_LIBRARIES} PROPERTIES SUFFIX "1.dll") endif() if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) @@ -43,11 +53,7 @@ index e108c16..5ab1a49 100644 RUNTIME DESTINATION "${INSTALL_BIN_DIR}" ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" LIBRARY DESTINATION "${INSTALL_LIB_DIR}" ) -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 5ab1a49..cc43333 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -237,21 +237,22 @@ endif() +@@ -229,21 +237,22 @@ endif() #============================================================================ # Example binaries #============================================================================