Skip to content

Commit 5c87deb

Browse files
committed
Release Windows packages (#5)
* Support linking static dependencies when building with MSVC See apache#73 * Add Windows packaging
1 parent 2248adc commit 5c87deb

File tree

6 files changed

+170
-98
lines changed

6 files changed

+170
-98
lines changed

.github/workflows/ci-build-binary-artifacts.yaml

Lines changed: 8 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -28,82 +28,27 @@ concurrency:
2828
cancel-in-progress: true
2929

3030
jobs:
31-
32-
package-linux:
33-
name: Build ${{matrix.pkg.name}} ${{matrix.cpu.platform}}
34-
runs-on: ubuntu-22.04
35-
timeout-minutes: 500
36-
37-
strategy:
38-
fail-fast: false
39-
matrix:
40-
pkg:
41-
- { name: 'RPM', type: 'rpm', path: 'pkg/rpm/RPMS' }
42-
- { name: 'Deb', type: 'deb', path: 'pkg/deb/BUILD/DEB' }
43-
- { name: 'Alpine', type: 'apk', path: 'pkg/apk/build' }
44-
cpu:
45-
- { arch: 'x86_64', platform: 'x86_64' }
46-
- { arch: 'aarch64', platform: 'arm64' }
47-
48-
steps:
49-
- name: checkout
50-
uses: actions/checkout@v3
51-
52-
- name: Set up QEMU
53-
uses: docker/setup-qemu-action@v2
54-
55-
- name: Package Pulsar source
56-
run: build-support/generate-source-archive.sh
57-
58-
- uses: docker/setup-buildx-action@v2
59-
- run: build-support/copy-deps-versionfile.sh
60-
61-
- name: Build dependencies Docker image
62-
uses: docker/build-push-action@v3
63-
with:
64-
context: ./pkg/${{matrix.pkg.type}}
65-
load: true
66-
tags: build:latest
67-
platforms: linux/${{matrix.cpu.platform}}
68-
build-args: PLATFORM=${{matrix.cpu.arch}}
69-
cache-from: type=gha
70-
cache-to: type=gha,mode=max
71-
72-
- name: Build packages
73-
run: pkg/${{matrix.pkg.type}}/docker-build-${{matrix.pkg.type}}-${{matrix.cpu.platform}}.sh build:latest
74-
75-
- name: Zip artifact
76-
run: zip -r ${{matrix.pkg.type}}-${{matrix.cpu.platform}}.zip ${{matrix.pkg.path}}
77-
78-
- name: Upload binaries to release
79-
uses: svenstaro/upload-release-action@v2
80-
with:
81-
repo_token: ${{ secrets.GITHUB_TOKEN }}
82-
file: ${{matrix.pkg.type}}-${{matrix.cpu.platform}}.zip
83-
asset_name: ${{matrix.pkg.type}}-${{matrix.cpu.platform}}.zip
84-
tag: ${{ github.ref }}
85-
overwrite: true
86-
8731
package-windows:
8832
timeout-minutes: 120
8933
name: Build CPP Client on ${{ matrix.name }}
9034
runs-on: ${{ matrix.os }}
9135
env:
9236
VCPKG_ROOT: '${{ github.workspace }}/vcpkg'
37+
INSTALL_DIR: 'C:\pulsar-cpp'
9338
strategy:
9439
fail-fast: false
9540
matrix:
9641
include:
9742
- name: 'Windows x64'
9843
os: windows-2022
99-
triplet: x64-windows
44+
triplet: x64-windows-static
10045
vcpkg_dir: 'C:\vcpkg'
10146
suffix: 'windows-win64'
10247
generator: 'Visual Studio 17 2022'
10348
arch: '-A x64'
10449
- name: 'Windows x86'
10550
os: windows-2022
106-
triplet: x86-windows
51+
triplet: x86-windows-static
10752
vcpkg_dir: 'C:\vcpkg'
10853
suffix: 'windows-win32'
10954
generator: 'Visual Studio 17 2022'
@@ -145,7 +90,7 @@ jobs:
14590
run: |
14691
${{ env.VCPKG_ROOT }}\vcpkg.exe install --triplet ${{ matrix.triplet }} > dependencies.txt
14792
148-
- name: Configure and build
93+
- name: Build and package
14994
shell: bash
15095
run: |
15196
BUILD_DIR=./build
@@ -154,30 +99,15 @@ jobs:
15499
-G "${{ matrix.generator }}" ${{ matrix.arch }} \
155100
-DBUILD_TESTS=OFF \
156101
-DVCPKG_TRIPLET=${{ matrix.triplet }} \
102+
-DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} \
157103
-S .
158104
cmake --build $BUILD_DIR --parallel --config Release
159-
160-
- name: Package
161-
shell: bash
162-
run: |
163-
BUILD_DIR=./build
164-
PACKAGE_DIR=./package
165-
LIB_DIR=$PACKAGE_DIR/lib/Release
166-
VCPKG_INSTALLED_DIR=$PACKAGE_DIR/vcpkg_installed
167-
mkdir -p $PACKAGE_DIR
168-
mkdir -p $LIB_DIR
169-
mkdir -p $VCPKG_INSTALLED_DIR/${{ matrix.triplet }}
170-
171-
cp dependencies.txt $PACKAGE_DIR
172-
cp -r ./include $PACKAGE_DIR
173-
cp -r $BUILD_DIR/include/ $PACKAGE_DIR
174-
cp -r $BUILD_DIR/lib/Release/*.lib $LIB_DIR
175-
cp -r $BUILD_DIR/lib/Release/*.dll $LIB_DIR
176-
cp -r ./vcpkg_installed/${{ matrix.triplet }}/* $VCPKG_INSTALLED_DIR/${{ matrix.triplet }}
105+
cmake --install $BUILD_DIR
106+
cp dependencies.txt ${{ env.INSTALL_DIR }}
177107
178108
- name: Zip artifact
179109
shell: bash
180-
run: 7z a -tzip Windows-${{ matrix.triplet }}.zip ./package
110+
run: 7z a -tzip Windows-${{ matrix.triplet }}.zip ${{ env.INSTALL_DIR }}/*
181111

182112
- name: Upload binaries to release
183113
uses: svenstaro/upload-release-action@v2

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ jobs:
8181
runs-on: ${{ matrix.os }}
8282
env:
8383
VCPKG_ROOT: '${{ github.workspace }}/vcpkg'
84+
INSTALL_DIR: 'C:\pulsar-cpp'
8485
strategy:
8586
fail-fast: false
8687
matrix:
@@ -156,24 +157,49 @@ jobs:
156157
cmake --build ./build-0 --parallel --config Release
157158
fi
158159
159-
- name: Configure (dynamic library only)
160+
- name: Install static vcpkg packages
161+
run: |
162+
${{ env.VCPKG_ROOT }}\vcpkg.exe install --triplet "${{ matrix.triplet }}-static"
163+
164+
- name: Configure (LINK_STATIC=ON)
160165
shell: bash
161166
run: |
162167
if [ "$RUNNER_OS" == "Windows" ]; then
163168
cmake \
164169
-B ./build-1 \
165170
-G "${{ matrix.generator }}" ${{ matrix.arch }} \
166171
-DBUILD_TESTS=OFF \
167-
-DVCPKG_TRIPLET=${{ matrix.triplet }} \
168-
-DBUILD_STATIC_LIB=OFF \
172+
-DVCPKG_TRIPLET="${{ matrix.triplet }}-static" \
173+
-DCMAKE_INSTALL_PREFIX="${{ env.INSTALL_DIR }}" \
169174
-S .
170175
fi
171176
172-
- name: Compile
177+
- name: Install
173178
shell: bash
174179
run: |
175180
if [ "$RUNNER_OS" == "Windows" ]; then
176181
cmake --build ./build-1 --parallel --config Release
182+
cmake --install ./build-1
183+
fi
184+
185+
- name: Test examples
186+
shell: bash
187+
run: |
188+
if [ "$RUNNER_OS" == "Windows" ]; then
189+
cd win-examples
190+
cmake \
191+
-G "${{ matrix.generator }}" ${{ matrix.arch }} \
192+
-DLINK_STATIC=OFF \
193+
-DCMAKE_PREFIX_PATH=${{ env.INSTALL_DIR }} \
194+
-B build-dynamic
195+
cmake --build build-dynamic --config Release
196+
cmake \
197+
-G "${{ matrix.generator }}" ${{ matrix.arch }} \
198+
-DLINK_STATIC=ON \
199+
-DCMAKE_PREFIX_PATH=${{ env.INSTALL_DIR }} \
200+
-B build-static
201+
cmake --build build-static --config Release
202+
./build-static/Release/win-example.exe
177203
fi
178204
179205
package:

CMakeLists.txt

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ message(STATUS "Pulsar Client version macro: ${PULSAR_CLIENT_VERSION_MACRO}")
3333
set(PVM_COMMENT "This is generated from Version.h.in by CMAKE. DO NOT EDIT DIRECTLY")
3434
configure_file(templates/Version.h.in include/pulsar/Version.h @ONLY)
3535

36+
option(LINK_STATIC "Link against static libraries" OFF)
3637
if (VCPKG_TRIPLET)
3738
message(STATUS "Use vcpkg, triplet is ${VCPKG_TRIPLET}")
3839
set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/vcpkg_installed/${VCPKG_TRIPLET}")
@@ -44,7 +45,13 @@ if (VCPKG_TRIPLET)
4445
set(ZLIB_ROOT ${VCPKG_DEBUG_ROOT})
4546
set(OPENSSL_ROOT_DIR ${VCPKG_DEBUG_ROOT})
4647
endif ()
48+
if (VCPKG_TRIPLET MATCHES ".*-static")
49+
set(LINK_STATIC ON)
50+
else ()
51+
set(LINK_STATIC OFF)
52+
endif ()
4753
endif()
54+
MESSAGE(STATUS "LINK_STATIC: " ${LINK_STATIC})
4855

4956
find_program(CCACHE_PROGRAM ccache)
5057
if(CCACHE_PROGRAM)
@@ -69,9 +76,6 @@ MESSAGE(STATUS "BUILD_WIRESHARK: " ${BUILD_WIRESHARK})
6976
option(BUILD_PERF_TOOLS "Build Pulsar CLI perf producer/consumer" OFF)
7077
MESSAGE(STATUS "BUILD_PERF_TOOLS: " ${BUILD_PERF_TOOLS})
7178

72-
option(LINK_STATIC "Link against static libraries" OFF)
73-
MESSAGE(STATUS "LINK_STATIC: " ${LINK_STATIC})
74-
7579
option(USE_LOG4CXX "Build with Log4cxx support" OFF)
7680
MESSAGE(STATUS "USE_LOG4CXX: " ${USE_LOG4CXX})
7781

@@ -93,7 +97,7 @@ set(CMAKE_C_STANDARD 11)
9397
# https://stackoverflow.com/questions/10046114/in-cmake-how-can-i-test-if-the-compiler-is-clang
9498
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
9599
add_definitions(-DWIN32_LEAN_AND_MEAN -DNOGDI -D_WIN32_WINNT=0x0501 -D_CRT_SECURE_NO_WARNINGS)
96-
add_compile_options(/wd4244 /wd4267 /wd4018 /wd4715 /wd4251 /wd4275)
100+
add_compile_options(/wd4244 /wd4267 /wd4018 /wd4715 /wd4251 /wd4275 /wd4819)
97101
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
98102
# ?? Don't have this to test with
99103
else() # GCC or Clang are mostly compatible:
@@ -168,7 +172,7 @@ if (NOT ZLIB_INCLUDE_DIRS OR NOT ZLIB_LIBRARIES)
168172
message(FATAL_ERROR "Could not find zlib")
169173
endif ()
170174

171-
if (LINK_STATIC)
175+
if (LINK_STATIC AND NOT VCPKG_TRIPLET)
172176
find_library(LIB_ZSTD NAMES libzstd.a)
173177
message(STATUS "ZStd: ${LIB_ZSTD}")
174178
find_library(LIB_SNAPPY NAMES libsnappy.a)
@@ -195,6 +199,29 @@ if (LINK_STATIC)
195199
if (MSVC)
196200
add_definitions(-DCURL_STATICLIB)
197201
endif()
202+
elseif (LINK_STATIC AND VCPKG_TRIPLET)
203+
find_package(protobuf REQUIRED)
204+
message(STATUS "Found protobuf static library: " ${Protobuf_LIBRARIES})
205+
find_library(ZLIB_LIBRARIES NAMES zlib z)
206+
if (ZLIB_LIBRARIES)
207+
message(STATUS "Found zlib static library: " ${ZLIB_LIBRARIES})
208+
else ()
209+
message(FATAL_ERROR "Failed to find zlib static library")
210+
endif ()
211+
find_library(CURL_LIBRARIES NAMES libcurl)
212+
if (CURL_LIBRARIES)
213+
message(STATUS "Found libcurl: ${CURL_LIBRARIES}")
214+
else ()
215+
message(FATAL_ERROR "Cannot find libcurl")
216+
endif ()
217+
find_library(LIB_ZSTD zstd)
218+
if (LIB_ZSTD)
219+
message(STATUS "Found ZSTD library: ${LIB_ZSTD}")
220+
endif ()
221+
find_library(LIB_SNAPPY NAMES snappy)
222+
if (LIB_SNAPPY)
223+
message(STATUS "Found Snappy library: ${LIB_SNAPPY}")
224+
endif ()
198225
else()
199226
if (MSVC AND (${CMAKE_BUILD_TYPE} STREQUAL Debug))
200227
find_library(LIB_ZSTD zstdd HINTS "${VCPKG_DEBUG_ROOT}/lib")
@@ -211,7 +238,7 @@ else()
211238
find_library(LOG4CXX_LIBRARY_PATH log4cxx)
212239
find_path(LOG4CXX_INCLUDE_PATH log4cxx/logger.h)
213240
endif (USE_LOG4CXX)
214-
endif (LINK_STATIC)
241+
endif ()
215242

216243
if (Boost_MAJOR_VERSION EQUAL 1 AND Boost_MINOR_VERSION LESS 69)
217244
# Boost System does not require linking since 1.69
@@ -220,15 +247,15 @@ if (Boost_MAJOR_VERSION EQUAL 1 AND Boost_MINOR_VERSION LESS 69)
220247
endif()
221248

222249
if (MSVC)
223-
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} date_time)
250+
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} date_time)
224251
endif()
225252

226253
if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
227254
# GCC 4.8.2 implementation of std::regex is buggy
228255
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} regex)
229256
set(CMAKE_CXX_FLAGS " -DPULSAR_USE_BOOST_REGEX")
230257
MESSAGE(STATUS "Using Boost::Regex")
231-
else()
258+
elseif (CMAKE_COMPILER_IS_GNUCC)
232259
MESSAGE(STATUS "Using std::regex")
233260
# Turn on color error messages and show additional help with errors (only available in GCC v4.9+):
234261
add_compile_options(-fdiagnostics-show-option -fdiagnostics-color)
@@ -295,7 +322,7 @@ include_directories(
295322

296323
set(COMMON_LIBS
297324
${COMMON_LIBS}
298-
Threads::Threads
325+
${CMAKE_THREAD_LIBS_INIT}
299326
${Boost_REGEX_LIBRARY}
300327
${Boost_SYSTEM_LIBRARY}
301328
${Boost_DATE_TIME_LIBRARY}
@@ -307,13 +334,25 @@ set(COMMON_LIBS
307334
${CMAKE_DL_LIBS}
308335
)
309336

310-
if (NOT MSVC)
311-
set(COMMON_LIBS ${COMMON_LIBS} m)
312-
else()
337+
if (MSVC)
313338
set(COMMON_LIBS
314-
${COMMON_LIBS}
315-
wldap32.lib
316-
Normaliz.lib)
339+
${COMMON_LIBS}
340+
${Boost_DATE_TIME_LIBRARY}
341+
wldap32.lib
342+
Normaliz.lib)
343+
if (LINK_STATIC)
344+
# add external dependencies of libcurl
345+
set(COMMON_LIBS ${COMMON_LIBS} ws2_32.lib crypt32.lib)
346+
# the default compile options have /MD, which cannot be used to build DLLs that link static libraries
347+
string(REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
348+
string(REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
349+
string(REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
350+
message(STATUS "CMAKE_CXX_FLAGS_DEBUG: " ${CMAKE_CXX_FLAGS_DEBUG})
351+
message(STATUS "CMAKE_CXX_FLAGS_RELEASE: " ${CMAKE_CXX_FLAGS_RELEASE})
352+
message(STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO: " ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
353+
endif ()
354+
else()
355+
set(COMMON_LIBS ${COMMON_LIBS} m)
317356
endif()
318357

319358
if (USE_LOG4CXX)

lib/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ endif(NOT LIBRARY_VERSION)
4646
if (MSVC)
4747
find_package(dlfcn-win32 REQUIRED)
4848
set(CMAKE_DL_LIBS dlfcn-win32::dl psapi.lib)
49+
get_target_property(dlfcn-win32_LIBRARY dlfcn-win32::dl IMPORTED_LOCATION_RELEASE)
50+
message(STATUS "dlfcn-win32_LIBRARY: " ${dlfcn-win32_LIBRARY})
4951
endif(MSVC)
5052

5153

@@ -88,7 +90,7 @@ endif()
8890
# required dependencies except ssl
8991
if (LINK_STATIC AND BUILD_STATIC_LIB)
9092
if (MSVC)
91-
93+
set(COMMON_LIBS ${COMMON_LIBS} ${dlfcn-win32_LIBRARY})
9294
# This function is to remove either "debug" or "optimized" library names
9395
# out of the COMMON_LIBS list and return the sanitized list of libraries
9496
function(remove_libtype LIBLIST LIBTYPE OUTLIST)

0 commit comments

Comments
 (0)