Skip to content

Commit 11e32c6

Browse files
Bump dependencies to latest versions for CVEs (#540)
1 parent 070132b commit 11e32c6

File tree

14 files changed

+205
-108
lines changed

14 files changed

+205
-108
lines changed

.github/workflows/ci-pr-validation.yaml

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ jobs:
9090
fetch-depth: 0
9191
submodules: recursive
9292

93+
- name: Restore vcpkg installed cache
94+
uses: actions/cache@v4
95+
with:
96+
path: build/vcpkg_installed
97+
key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json', 'CMakeLists.txt', 'vcpkg-triplets/**') }}
98+
restore-keys: vcpkg-${{ runner.os }}-
99+
93100
- name: Build the project
94101
run: |
95102
cmake -B build -DINTEGRATE_VCPKG=ON -DBUILD_TESTS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
@@ -117,6 +124,15 @@ jobs:
117124
fetch-depth: 0
118125
submodules: recursive
119126

127+
- name: Restore vcpkg installed cache
128+
uses: actions/cache@v4
129+
with:
130+
path: |
131+
build/vcpkg_installed
132+
build-boost-asio/vcpkg_installed
133+
key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json', 'CMakeLists.txt', 'vcpkg-triplets/**') }}
134+
restore-keys: vcpkg-${{ runner.os }}-
135+
120136
- name: Build core libraries
121137
run: |
122138
cmake -B build -DINTEGRATE_VCPKG=ON -DBUILD_TESTS=OFF
@@ -154,8 +170,8 @@ jobs:
154170
155171
- name: Verify custom vcpkg installation
156172
run: |
157-
mv vcpkg /tmp/
158-
cmake -B build-2 -DINTEGRATE_VCPKG=ON -DCMAKE_TOOLCHAIN_FILE="/tmp/vcpkg/scripts/buildsystems/vcpkg.cmake"
173+
mv vcpkg /tmp/vcpkg-custom
174+
cmake -B build-2 -DINTEGRATE_VCPKG=ON -DCMAKE_TOOLCHAIN_FILE="/tmp/vcpkg-custom/scripts/buildsystems/vcpkg.cmake"
159175
160176
cpp20-build:
161177
name: Build with the C++20 standard
@@ -206,31 +222,45 @@ jobs:
206222
arch: '-A Win32'
207223

208224
steps:
209-
- name: checkout
210-
uses: actions/checkout@v3
225+
- uses: actions/checkout@v4
226+
with:
227+
submodules: true
211228

212229
- name: Restore vcpkg and its artifacts.
213-
uses: actions/cache@v3
230+
uses: actions/cache@v4
214231
id: vcpkg-cache
232+
continue-on-error: true
215233
with:
216234
path: |
217-
${{ env.VCPKG_ROOT }}
218-
vcpkg_installed
219-
!${{ env.VCPKG_ROOT }}/.git
220-
!${{ env.VCPKG_ROOT }}/buildtrees
221-
!${{ env.VCPKG_ROOT }}/packages
222-
!${{ env.VCPKG_ROOT }}/downloads
223-
key: |
224-
${{ runner.os }}-${{ matrix.triplet}}-${{ hashFiles( 'vcpkg.json' ) }}
235+
${{ github.workspace }}/vcpkg_installed
236+
${{ env.VCPKG_ROOT }}/downloads
237+
${{ env.VCPKG_ROOT }}/vcpkg.exe
238+
key: ${{ runner.os }}-${{ matrix.triplet }}-vcpkg-${{ hashFiles('vcpkg.json') }}
239+
restore-keys: |
240+
${{ runner.os }}-${{ matrix.triplet }}-vcpkg-
241+
save-always: true
225242

226243
- name: Get vcpkg(windows)
227244
if: ${{ runner.os == 'Windows' && steps.vcpkg-cache.outputs.cache-hit != 'true' }}
245+
shell: pwsh
228246
run: |
229247
cd ${{ github.workspace }}
230-
mkdir build -force
231-
git clone https://github.com/Microsoft/vcpkg.git
232-
cd vcpkg
233-
.\bootstrap-vcpkg.bat
248+
mkdir build -Force
249+
# If vcpkg.exe already exists, skip bootstrapping to save time and avoid
250+
# modifying the checked-out vcpkg directory.
251+
if (Test-Path "${{ github.workspace }}\\vcpkg\\vcpkg.exe") {
252+
Write-Host "vcpkg.exe present — skipping bootstrap"
253+
} else {
254+
if (Test-Path vcpkg) {
255+
# If vcpkg was checked out as a submodule it may be shallow; fetch full history
256+
git -C vcpkg fetch --unshallow || true
257+
} else {
258+
git clone https://github.com/Microsoft/vcpkg.git
259+
}
260+
Push-Location vcpkg
261+
.\bootstrap-vcpkg.bat
262+
Pop-Location
263+
}
234264
235265
- name: remove system vcpkg(windows)
236266
if: runner.os == 'Windows'
@@ -355,6 +385,13 @@ jobs:
355385
fetch-depth: 0
356386
submodules: recursive
357387

388+
- name: Restore vcpkg installed cache
389+
uses: actions/cache@v4
390+
with:
391+
path: build-osx/vcpkg_installed
392+
key: vcpkg-${{ runner.os }}-arm64-${{ hashFiles('vcpkg.json', 'CMakeLists.txt', 'vcpkg-triplets/**') }}
393+
restore-keys: vcpkg-${{ runner.os }}-arm64-
394+
358395
- name: Build libraries
359396
run: ./pkg/mac/build-static-library.sh
360397

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,25 @@ if (INTEGRATE_VCPKG)
127127
find_package(ZLIB REQUIRED)
128128
find_package(OpenSSL REQUIRED)
129129
find_package(protobuf CONFIG REQUIRED)
130+
find_package(absl CONFIG REQUIRED)
130131
find_package(zstd CONFIG REQUIRED)
131132
find_package(Snappy CONFIG REQUIRED)
132133
set(COMMON_LIBS CURL::libcurl
133134
ZLIB::ZLIB
134135
OpenSSL::SSL
135136
OpenSSL::Crypto
136137
protobuf::libprotobuf
138+
absl::base
139+
absl::log
140+
absl::log_internal_message
141+
absl::log_internal_check_op
142+
absl::status
143+
absl::statusor
144+
absl::strings
145+
absl::str_format
146+
absl::time
147+
absl::synchronization
148+
absl::cord
137149
$<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>
138150
Snappy::snappy
139151
)

LegacyFindPackages.cmake

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ if (VCPKG_TRIPLET)
2323
set(CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR}/vcpkg_installed/${VCPKG_TRIPLET}")
2424
message(STATUS "Use CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
2525
set(PROTOC_PATH "${CMAKE_PREFIX_PATH}/tools/protobuf/protoc")
26+
if (MSVC)
27+
# vcpkg host tools (protoc, etc.) are always built for the host machine
28+
# architecture (x64 on GitHub Actions), regardless of the target triplet.
29+
# Use find_program to locate protoc.exe across known host tool paths.
30+
find_program(PROTOC_PATH NAMES protoc.exe
31+
PATHS
32+
"${PROJECT_SOURCE_DIR}/vcpkg_installed/x64-windows/tools/protobuf"
33+
"${PROJECT_SOURCE_DIR}/vcpkg_installed/arm64-windows/tools/protobuf"
34+
"${PROJECT_SOURCE_DIR}/vcpkg_installed/${VCPKG_TRIPLET}/tools/protobuf"
35+
NO_DEFAULT_PATH)
36+
if (NOT PROTOC_PATH)
37+
set(PROTOC_PATH "${CMAKE_PREFIX_PATH}/tools/protobuf/protoc.exe")
38+
endif ()
39+
# Set the cache variable so protobuf's CMake module compatibility shim finds it
40+
set(Protobuf_PROTOC_EXECUTABLE "${PROTOC_PATH}" CACHE FILEPATH "protoc executable" FORCE)
41+
endif ()
2642
message(STATUS "Use protoc: ${PROTOC_PATH}")
2743
set(VCPKG_ROOT "${PROJECT_SOURCE_DIR}/vcpkg_installed/${VCPKG_TRIPLET}")
2844
set(VCPKG_DEBUG_ROOT "${VCPKG_ROOT}/debug")
@@ -51,6 +67,10 @@ if (APPLE AND NOT LINK_STATIC)
5167
# The latest Protobuf dependency on macOS requires the C++17 support and
5268
# it could only be found by the CONFIG mode
5369
set(LATEST_PROTOBUF TRUE)
70+
elseif (MSVC AND VCPKG_TRIPLET)
71+
# protobuf >= 6.x on Windows with vcpkg requires CONFIG mode to resolve
72+
# the protobuf::libprotobuf CMake target and its abseil dependencies
73+
set(LATEST_PROTOBUF TRUE)
5474
else ()
5575
set(LATEST_PROTOBUF FALSE)
5676
endif ()
@@ -83,8 +103,13 @@ message("OPENSSL_INCLUDE_DIR: " ${OPENSSL_INCLUDE_DIR})
83103
message("OPENSSL_LIBRARIES: " ${OPENSSL_LIBRARIES})
84104

85105
if (LATEST_PROTOBUF)
86-
# See https://github.com/apache/arrow/issues/35987
87-
add_definitions(-DPROTOBUF_USE_DLLS)
106+
if (NOT LINK_STATIC)
107+
# Only needed when protobuf itself is a DLL; static builds must NOT define this
108+
# because it marks symbols as __declspec(dllimport), causing LNK2019 when
109+
# linking against a static libprotobuf.lib.
110+
# See https://github.com/apache/arrow/issues/35987
111+
add_definitions(-DPROTOBUF_USE_DLLS)
112+
endif ()
88113
# Use Config mode to avoid FindProtobuf.cmake does not find the Abseil library
89114
find_package(Protobuf REQUIRED CONFIG)
90115
else ()
@@ -127,8 +152,10 @@ if (LINK_STATIC AND NOT VCPKG_TRIPLET)
127152
add_definitions(-DCURL_STATICLIB)
128153
endif()
129154
elseif (LINK_STATIC AND VCPKG_TRIPLET)
130-
find_package(Protobuf REQUIRED)
131-
message(STATUS "Found protobuf static library: " ${Protobuf_LIBRARIES})
155+
if (NOT LATEST_PROTOBUF)
156+
find_package(Protobuf REQUIRED)
157+
message(STATUS "Found protobuf static library: " ${Protobuf_LIBRARIES})
158+
endif ()
132159
if (MSVC AND (${CMAKE_BUILD_TYPE} STREQUAL Debug))
133160
find_library(ZLIB_LIBRARIES NAMES zlibd)
134161
else ()
@@ -264,8 +291,8 @@ if (MSVC)
264291
wldap32.lib
265292
Normaliz.lib)
266293
if (LINK_STATIC)
267-
# add external dependencies of libcurl
268-
set(COMMON_LIBS ${COMMON_LIBS} ws2_32.lib crypt32.lib)
294+
# add external dependencies of libcurl (iphlpapi for if_nametoindex)
295+
set(COMMON_LIBS ${COMMON_LIBS} ws2_32.lib crypt32.lib iphlpapi.lib)
269296
# the default compile options have /MD, which cannot be used to build DLLs that link static libraries
270297
string(REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
271298
string(REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
@@ -279,6 +306,23 @@ if (MSVC)
279306
message(STATUS "CMAKE_CXX_FLAGS_RELEASE: " ${CMAKE_CXX_FLAGS_RELEASE})
280307
message(STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO: " ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
281308
endif ()
309+
if (VCPKG_TRIPLET)
310+
# protobuf >= 6.x requires abseil; link it explicitly since MSVC static
311+
# linking does not resolve transitive dependencies automatically
312+
find_package(absl CONFIG REQUIRED)
313+
set(COMMON_LIBS ${COMMON_LIBS}
314+
absl::base
315+
absl::log
316+
absl::log_internal_message
317+
absl::log_internal_check_op
318+
absl::status
319+
absl::statusor
320+
absl::strings
321+
absl::str_format
322+
absl::time
323+
absl::synchronization
324+
absl::cord)
325+
endif ()
282326
else()
283327
set(COMMON_LIBS ${COMMON_LIBS} m)
284328
endif()

build-support/merge_archives.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ for ITEM in $ITEMS; do
4545
cd ..
4646
done
4747

48+
rm -f $MERGED_LIBRARY
4849
ar -qc $MERGED_LIBRARY $LIBS
4950

5051

build-support/merge_archives_vcpkg.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,19 @@ if [[ $# -lt 1 ]]; then
2727
fi
2828

2929
CMAKE_BUILD_DIRECTORY=$1
30+
31+
# libprotoc.a is the protobuf compiler (protoc) tool library, not the runtime.
32+
# It pulls in google::protobuf::compiler::java::* and absl debugging/VDSO symbols
33+
# that are not needed by client code and cannot be satisfied without additional deps.
34+
# libprotobuf-lite.a is a subset of libprotobuf.a and causes duplicate symbols.
35+
EXCLUDE_PATTERN="libprotoc.a\|libprotobuf-lite.a"
36+
3037
if [[ $VCPKG_TRIPLET ]]; then
3138
./merge_archives.sh $CMAKE_BUILD_DIRECTORY/libpulsarwithdeps.a \
3239
$CMAKE_BUILD_DIRECTORY/lib/libpulsar.a \
33-
$(find "$CMAKE_BUILD_DIRECTORY/vcpkg_installed/$VCPKG_TRIPLET" -name "*.a" | grep -v debug)
40+
$(find "$CMAKE_BUILD_DIRECTORY/vcpkg_installed/$VCPKG_TRIPLET" -name "*.a" | grep -v '/debug/' | grep -v "$EXCLUDE_PATTERN")
3441
else
3542
./merge_archives.sh $CMAKE_BUILD_DIRECTORY/libpulsarwithdeps.a \
3643
$CMAKE_BUILD_DIRECTORY/lib/libpulsar.a \
37-
$(find "$CMAKE_BUILD_DIRECTORY/vcpkg_installed" -name "*.a" | grep -v debug)
44+
$(find "$CMAKE_BUILD_DIRECTORY/vcpkg_installed" -name "*.a" | grep -v '/debug/' | grep -v "$EXCLUDE_PATTERN")
3845
fi

lib/CMakeLists.txt

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,59 @@ if (LINK_STATIC AND BUILD_STATIC_LIB)
140140

141141
add_library(pulsarStaticWithDeps STATIC ${PULSAR_SOURCES})
142142
target_include_directories(pulsarStaticWithDeps PRIVATE ${dlfcn-win32_INCLUDE_DIRS})
143-
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
144-
remove_libtype("${COMMON_LIBS}" "optimized" STATIC_LIBS)
143+
if (VCPKG_TRIPLET)
144+
# Collect ALL vcpkg-installed static archives so every transitive dependency
145+
# (protobuf, abseil, curl, zlib, etc.) is merged into the fat lib without
146+
# requiring manual enumeration of individual targets.
147+
set(_vcpkg_dir "${PROJECT_SOURCE_DIR}/vcpkg_installed/${VCPKG_TRIPLET}")
148+
file(GLOB _release_libs "${_vcpkg_dir}/lib/*.lib")
149+
file(GLOB _debug_libs "${_vcpkg_dir}/debug/lib/*.lib")
150+
# Exclude the protobuf compiler tool and lite runtime (not needed at runtime)
151+
foreach (_excl "libprotoc" "libprotobuf-lite")
152+
list(FILTER _release_libs EXCLUDE REGEX "/${_excl}\\.lib$")
153+
list(FILTER _debug_libs EXCLUDE REGEX "/${_excl}\\.lib$")
154+
endforeach ()
155+
# Build per-lib generator expressions to select debug vs release archive
156+
# for multi-config generators (Visual Studio).
157+
set(_vcpkg_static_libs "")
158+
foreach (_rlib IN LISTS _release_libs)
159+
get_filename_component(_libname "${_rlib}" NAME)
160+
set(_dlib "${_vcpkg_dir}/debug/lib/${_libname}")
161+
if (EXISTS "${_dlib}")
162+
list(APPEND _vcpkg_static_libs "$<IF:$<CONFIG:Debug>,${_dlib},${_rlib}>")
163+
else ()
164+
list(APPEND _vcpkg_static_libs "${_rlib}")
165+
endif ()
166+
endforeach ()
167+
# Also merge Windows system DLL import libs so pulsarWithDeps.lib is fully
168+
# self-contained. lib.exe carries the import records into the archive; the
169+
# final linker then resolves DLL deps without the user listing them.
170+
# lib.exe finds these by name via the LIB env var set up by MSBuild/MSVC.
171+
list(APPEND _vcpkg_static_libs
172+
ws2_32.lib crypt32.lib wldap32.lib Normaliz.lib iphlpapi.lib)
173+
set_property(TARGET pulsarStaticWithDeps PROPERTY STATIC_LIBRARY_OPTIONS ${_vcpkg_static_libs})
145174
else ()
146-
remove_libtype("${COMMON_LIBS}" "debug" STATIC_LIBS)
175+
# Non-vcpkg MSVC static build: resolve COMMON_LIBS entries for lib.exe.
176+
# CMake imported target names cannot be passed to lib.exe directly; replace
177+
# them with $<TARGET_FILE:...> generator expressions.
178+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
179+
remove_libtype("${COMMON_LIBS}" "optimized" STATIC_LIBS)
180+
else ()
181+
remove_libtype("${COMMON_LIBS}" "debug" STATIC_LIBS)
182+
endif ()
183+
set(RESOLVED_STATIC_LIBS "")
184+
foreach (LIB IN LISTS STATIC_LIBS)
185+
if (TARGET ${LIB})
186+
get_target_property(_LIB_TYPE ${LIB} TYPE)
187+
if (_LIB_TYPE STREQUAL "STATIC_LIBRARY" OR _LIB_TYPE STREQUAL "UNKNOWN_LIBRARY")
188+
list(APPEND RESOLVED_STATIC_LIBS "$<TARGET_FILE:${LIB}>")
189+
endif ()
190+
elseif (IS_ABSOLUTE "${LIB}" AND LIB MATCHES "\\.(lib|a)$")
191+
list(APPEND RESOLVED_STATIC_LIBS "${LIB}")
192+
endif ()
193+
endforeach ()
194+
set_property(TARGET pulsarStaticWithDeps PROPERTY STATIC_LIBRARY_OPTIONS ${RESOLVED_STATIC_LIBS})
147195
endif ()
148-
set_property(TARGET pulsarStaticWithDeps PROPERTY STATIC_LIBRARY_OPTIONS ${STATIC_LIBS})
149196
set_property(TARGET pulsarStaticWithDeps PROPERTY OUTPUT_NAME ${LIB_NAME}WithDeps)
150197
set_property(TARGET pulsarStaticWithDeps PROPERTY VERSION ${LIBRARY_VERSION})
151198
install(TARGETS pulsarStaticWithDeps DESTINATION lib)

lib/CurlWrapper.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,11 @@
2121
#include <assert.h>
2222
#include <curl/curl.h>
2323

24+
#include <mutex>
2425
#include <string>
2526

2627
namespace pulsar {
2728

28-
struct CurlInitializer {
29-
CurlInitializer() { curl_global_init(CURL_GLOBAL_ALL); }
30-
~CurlInitializer() { curl_global_cleanup(); }
31-
};
32-
static CurlInitializer curlInitializer;
33-
3429
class CurlWrapper {
3530
public:
3631
CurlWrapper() noexcept {}
@@ -47,6 +42,8 @@ class CurlWrapper {
4742

4843
// It must be called before calling other methods
4944
bool init() {
45+
static std::once_flag initFlag;
46+
std::call_once(initFlag, [] { curl_global_init(CURL_GLOBAL_ALL); });
5047
handle_ = curl_easy_init();
5148
return handle_ != nullptr;
5249
}

lib/MessageBuilder.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ MessageBuilder& MessageBuilder::setReplicationClusters(const std::vector<std::st
149149

150150
MessageBuilder& MessageBuilder::disableReplication(bool flag) {
151151
checkMetadata();
152-
google::protobuf::RepeatedPtrField<std::string> r;
152+
google::protobuf::RepeatedPtrField<std::string>* replicateTo = impl_->metadata.mutable_replicate_to();
153+
replicateTo->Clear();
153154
if (flag) {
154-
r.AddAllocated(new std::string("__local__"));
155+
replicateTo->Add("__local__");
155156
}
156-
r.Swap(impl_->metadata.mutable_replicate_to());
157157
return *this;
158158
}
159159

lib/MessageImpl.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ void MessageImpl::setReplicationClusters(const std::vector<std::string>& cluster
6161
}
6262

6363
void MessageImpl::disableReplication(bool flag) {
64-
google::protobuf::RepeatedPtrField<std::string> r;
64+
google::protobuf::RepeatedPtrField<std::string>* replicateTo = metadata.mutable_replicate_to();
65+
replicateTo->Clear();
6566
if (flag) {
66-
r.AddAllocated(new std::string("__local__"));
67+
replicateTo->Add("__local__");
6768
}
68-
r.Swap(metadata.mutable_replicate_to());
6969
}
7070

7171
void MessageImpl::setProperty(const std::string& name, const std::string& value) {

0 commit comments

Comments
 (0)