Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build static librdkafka_windows.a with travis #3130

Merged
merged 25 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7fc6e2b
Build static librdkafka_windows.a with travis
Nov 2, 2020
6aedc13
Update paths to match Travis MinGW build script
Nov 2, 2020
914740e
Update DLL paths
Nov 2, 2020
fa37b37
Replace tabs with spaces
Nov 2, 2020
3202c00
Don't use msys2 rm, just use regular travis one
Nov 2, 2020
b6923bd
Add Win32 DLLs to MinGW C++ pkg-config
Nov 2, 2020
2fa3a83
Relocate MinGW target_link_libraries to allow building executables
Nov 2, 2020
3d714b7
Update CMakeLists.txt to include pkg-config for Windows DLLs for stat…
Nov 2, 2020
1a589f6
Write to librdkafka.a instead of librdkafka_windows.a
Nov 3, 2020
7bfe9b6
Update packing script for different .a file name
Nov 3, 2020
8b1233c
Separate MinGW static build and dynamic build
Nov 10, 2020
fff9182
Restore previous whitespace style in CMakeLists.txt
Nov 10, 2020
37794d5
CMakeLists.txt formatting
Nov 10, 2020
b3d1dc6
Undo CMakeLists.txt whitespace-only changes
Nov 11, 2020
e266bbd
Fix accidental tab characters in packaging/mingw-w64/travis-before-in…
Nov 11, 2020
fb17f94
Default WITH_PLUGINS to ON on Windows CMake builds
Nov 11, 2020
a2939dd
Modify CMAKE_FIND_LIBRARY_SUFFIXES instead of deleting .dll.a files
Nov 12, 2020
81428d0
Make use of Libs.private
Nov 12, 2020
d79ba78
Merge branch 'master' of https://github.com/edenhill/librdkafka into …
Jan 28, 2021
601c17e
Merge branch 'master' of https://github.com/edenhill/librdkafka into …
Apr 6, 2021
5108c01
Merge branch 'master' of https://github.com/edenhill/librdkafka into …
Apr 6, 2021
3ff3cb8
Fix a CMake check using WITH_PLUGINS when it should have been using W…
Apr 6, 2021
d393223
Add strip calls for MinGW static libraries
Apr 6, 2021
cbf9b16
Slight CMakeLists.txt refactor per SpaceIm comment
Apr 6, 2021
cc19265
Move CMAKE_FIND_LIBRARY_SUFFIXES from CMakeLists.txt to the Travis bu…
Apr 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,22 @@ matrix:
env: LINKAGE=static HOMEBREW_NO_AUTO_UPDATE=1
before_script:
- ./configure --install-deps --disable-lz4-ext --prefix="$PWD/dest" --enable-static --disable-syslog
- name: "Windows MinGW-w64"
- name: "Windows MinGW-w64 Dynamic"
os: windows
env:
- SKIP_MAKE=y
before_install:
- source ./packaging/mingw-w64/travis-before-install.sh
before_script:
- ./packaging/mingw-w64/configure-build-msys2-mingw.sh
- name: "Windows MinGW-w64 Static"
os: windows
env:
- SKIP_MAKE=y
before_install:
- source ./packaging/mingw-w64/travis-before-install.sh
before_script:
- ./packaging/mingw-w64/configure-build-msys2-mingw-static.sh
- name: "Linux GCC: +integration-tests +copyright-check +doc-check"
os: linux
dist: xenial
Expand Down
4 changes: 1 addition & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ endif()
# }

# WITH_PLUGINS {
if(WITH_LIBDL)
if(WITH_LIBDL OR WIN32)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to use libdl and not LoadLibrary on cygwin win32?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line just turns the WITH_PLUGINS CMake flag on. All this does is add rdkafka_plugin.c to the build (see https://github.com/neptoess/librdkafka/blob/add-mingw-to-packaging/src/CMakeLists.txt#L82-L84). rdkafka_plugin.c relies on rddl.c for its functionality, and it looks like rddl.c properly detects _WIN32 and handles plugin loading via LoadLibrary. If I'm misunderstanding this, let me know.

set(with_plugins_default ON)
else()
set(with_plugins_default OFF)
Expand Down Expand Up @@ -256,8 +256,6 @@ install(
DESTINATION "share/licenses/librdkafka"
)

# }

add_subdirectory(src)
add_subdirectory(src-cpp)

Expand Down
53 changes: 53 additions & 0 deletions packaging/mingw-w64/configure-build-msys2-mingw-static.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

set -e

cmake \
-G "MinGW Makefiles" \
-D CMAKE_INSTALL_PREFIX="$PWD/dest/" \
-D RDKAFKA_BUILD_STATIC=ON \
.

$mingw64 mingw32-make
$mingw64 mingw32-make install

# Bundle all the static dependencies with the static lib we just built
mkdir mergescratch
pushd mergescratch
cp /C/tools/msys64/mingw64/lib/libzstd.a ./
cp /C/tools/msys64/mingw64/lib/libcrypto.a ./
cp /C/tools/msys64/mingw64/lib/liblz4.a ./
cp /C/tools/msys64/mingw64/lib/libssl.a ./
cp /C/tools/msys64/mingw64/lib/libz.a ./
cp ../src/librdkafka.a ./

# Have to rename because ar won't work with + in the name
cp ../src-cpp/librdkafka++.a ./librdkafkacpp.a
ar -M << EOF
create librdkafka-static.a
addlib librdkafka.a
addlib libzstd.a
addlib libcrypto.a
addlib liblz4.a
addlib libssl.a
addlib libz.a
save
end
EOF

ar -M << EOF
create librdkafkacpp-static.a
addlib librdkafka-static.a
addlib librdkafkacpp.a
save
end
EOF

cp ./librdkafka-static.a ../dest/lib/
cp ./librdkafkacpp-static.a ../dest/lib/librdkafka++-static.a
popd
rm -rf ./mergescratch

export PATH="$PWD/dest/bin:/mingw64/bin/:${PATH}"
cd tests
./test-runner.exe -l -Q -p1
10 changes: 9 additions & 1 deletion packaging/mingw-w64/travis-before-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ case $TRAVIS_OS_NAME in
# to zstd instead of xz compression
$msys2 pacman -Sy --noconfirm pacman
choco upgrade --no-progress -y msys2
$msys2 pacman --sync --noconfirm --needed mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-openssl mingw-w64-x86_64-cyrus-sasl

## Install more MSYS2 packages from https://packages.msys2.org/base here
$msys2 pacman --sync --noconfirm --needed mingw-w64-x86_64-gcc mingw-w64-x86_64-make mingw-w64-x86_64-cmake mingw-w64-x86_64-openssl mingw-w64-x86_64-lz4 mingw-w64-x86_64-zstd

# Removing the DLLs so cmake links against the static libs
neptoess marked this conversation as resolved.
Show resolved Hide resolved
rm /C/tools/msys64/mingw64/lib/libzstd.dll.a
rm /C/tools/msys64/mingw64/lib/libcrypto.dll.a
rm /C/tools/msys64/mingw64/lib/liblz4.dll.a
rm /C/tools/msys64/mingw64/lib/libssl.dll.a
rm /C/tools/msys64/mingw64/lib/libz.dll.a

taskkill //IM gpg-agent.exe //F || true # https://travis-ci.community/t/4967
export PATH=/C/tools/msys64/mingw64/bin:$PATH
export MAKE=mingw32-make # so that Autotools can find it
Expand Down
8 changes: 7 additions & 1 deletion packaging/nuget/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ def build (self, buildtype):
# osx static lib and pkg-config file
[{'arch': 'x64', 'plat': 'osx', 'fname_glob': 'librdkafka-clang.tar.gz'}, './lib/librdkafka-static.a', 'librdkafka_darwin.a'],
[{'arch': 'x64', 'plat': 'osx', 'fname_glob': 'librdkafka-clang.tar.gz'}, './lib/pkgconfig/rdkafka-static.pc', 'librdkafka_darwin.pc'],

# win static lib and pkg-config file
[{'arch': 'x64', 'plat': 'win', 'fname_glob': 'librdkafka-mingw.tar.gz'}, './lib/librdkafka-static.a', 'librdkafka_windows.a'],
[{'arch': 'x64', 'plat': 'win', 'fname_glob': 'librdkafka-mingw.tar.gz'}, './lib/pkgconfig/rdkafka-static.pc', 'librdkafka_windows.pc'],
]

for m in mappings:
Expand Down Expand Up @@ -573,7 +577,9 @@ def verify (self, path):
"./librdkafka_musl_linux.a",
"./librdkafka_musl_linux.pc",
"./librdkafka_darwin.a",
"./librdkafka_darwin.pc"]
"./librdkafka_darwin.pc",
"./librdkafka_windows.a",
"./librdkafka_windows.pc"]

missing = list()
with zfile.ZFile(path, 'r') as zf:
Expand Down
57 changes: 24 additions & 33 deletions src-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,49 +37,40 @@ if(NOT RDKAFKA_BUILD_STATIC)
endif()

# Generate pkg-config file
set(PKG_CONFIG_NAME
"librdkafka++"
)
set(PKG_CONFIG_DESCRIPTION
"The Apache Kafka C/C++ library"
)
set(PKG_CONFIG_VERSION
"${PROJECT_VERSION}"
)
set(PKG_CONFIG_REQUIRES "rdkafka")
set(PKG_CONFIG_CFLAGS
"-I\${includedir}"
)
set(PKG_CONFIG_LIBS
"-L\${libdir} -lrdkafka++"
)
set(PKG_CONFIG_LIBS_PRIVATE
"-lrdkafka"
)
configure_file(
set(PKG_CONFIG_VERSION "${PROJECT_VERSION}")
if(NOT RDKAFKA_BUILD_STATIC)
set(PKG_CONFIG_NAME "librdkafka++")
set(PKG_CONFIG_DESCRIPTION "The Apache Kafka C/C++ library")
set(PKG_CONFIG_REQUIRES "rdkafka")
set(PKG_CONFIG_CFLAGS "-I\${includedir}")
set(PKG_CONFIG_LIBS "-L\${libdir} -lrdkafka++")
set(PKG_CONFIG_LIBS_PRIVATE "-lrdkafka")
configure_file(
"../packaging/cmake/rdkafka.pc.in"
"${GENERATED_DIR}/rdkafka++.pc"
@ONLY
)
install(FILES ${GENERATED_DIR}/rdkafka++.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)
if(RDKAFKA_BUILD_STATIC)
set(PKG_CONFIG_NAME
"librdkafka++-static"
)
set(PKG_CONFIG_DESCRIPTION
"The Apache Kafka C/C++ library (static)"
)
set(PKG_CONFIG_LIBS
"-L\${libdir} \${libdir}/librdkafka++.a"
install(
FILES ${GENERATED_DIR}/rdkafka++.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)
else()
set(PKG_CONFIG_NAME "librdkafka++-static")
set(PKG_CONFIG_DESCRIPTION "The Apache Kafka C/C++ library (static)")
set(PKG_CONFIG_REQUIRES "")
set(PKG_CONFIG_CFLAGS "-I\${includedir} -DLIBRDKAFKA_STATICLIB")
if(WIN32)
neptoess marked this conversation as resolved.
Show resolved Hide resolved
set(PKG_CONFIG_LIBS "-L\${libdir} \${libdir}/librdkafka++.a -lws2_32 -lsecur32 -lcrypt32")
else()
set(PKG_CONFIG_LIBS "-L\${libdir} \${libdir}/librdkafka++.a")
endif()
configure_file(
"../packaging/cmake/rdkafka.pc.in"
"${GENERATED_DIR}/rdkafka++-static.pc"
@ONLY
)
install(FILES ${GENERATED_DIR}/rdkafka.pc
install(
FILES ${GENERATED_DIR}/rdkafka++-static.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)
endif()
Expand Down
140 changes: 69 additions & 71 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ if(WITHOUT_WIN32_CONFIG)
list(APPEND rdkafka_compile_definitions ENABLE_DEVEL=0)
endif(ENABLE_DEVEL)
if(WITH_PLUGINS)
list(APPEND rdkafka_compile_definitions WITH_PLUGIN=1)
list(APPEND rdkafka_compile_definitions WITH_PLUGINS=1)
neptoess marked this conversation as resolved.
Show resolved Hide resolved
else()
list(APPEND rdkafka_compile_definitions WITH_PLUGIN=0)
list(APPEND rdkafka_compile_definitions WITH_PLUGINS=0)
endif(WITH_PLUGINS)
endif()

Expand Down Expand Up @@ -182,13 +182,7 @@ if(RDKAFKA_BUILD_STATIC)
target_compile_definitions(rdkafka PUBLIC LIBRDKAFKA_STATICLIB)
endif()

if(MINGW)
message(STATUS "Detected MinGW build")
# MinGW ignores `#pragma comment(lib, ...)` so we need to specify link libs
target_link_libraries(rdkafka PUBLIC crypt32 ws2_32 secur32)
endif(MINGW)

if(WIN32)
if(WIN32)
if(RDKAFKA_BUILD_STATIC)
target_link_libraries(rdkafka PUBLIC crypt32)
else()
Expand Down Expand Up @@ -253,80 +247,84 @@ if(WITH_LZ4_EXT)
target_link_libraries(rdkafka PUBLIC LZ4::LZ4)
endif()

# Set up path to these sources for other sub-projects (tests, examples)
# to be able to reach them.
#set(rdkafka_SRC_DIR ${PROJECT_SOURCE_DIR}
# CACHE INTERNAL "${PROJECT_NAME} source dir" FORCE)
if(MINGW)
message(STATUS "Detected MinGW build")
# MinGW ignores `#pragma comment(lib, ...)` so we need to specify link libs
target_link_libraries(rdkafka PUBLIC crypt32 ws2_32 secur32)
endif(MINGW)
neptoess marked this conversation as resolved.
Show resolved Hide resolved

# Generate pkg-config file
set(PKG_CONFIG_NAME
"librdkafka"
)
set(PKG_CONFIG_DESCRIPTION
"The Apache Kafka C/C++ library"
)
set(PKG_CONFIG_VERSION
"${PROJECT_VERSION}"
)
set(PKG_CONFIG_REQUIRES "")
if(WITH_ZLIB)
string(APPEND PKG_CONFIG_REQUIRES "zlib ")
endif()
if(WITH_SSL)
set(PKG_CONFIG_VERSION "${PROJECT_VERSION}")
if(NOT RDKAFKA_BUILD_STATIC)
set(PKG_CONFIG_NAME "librdkafka")
set(PKG_CONFIG_DESCRIPTION "The Apache Kafka C/C++ library")
set(PKG_CONFIG_REQUIRES "")
if(WITH_ZLIB)
string(APPEND PKG_CONFIG_REQUIRES "zlib ")
endif()

if(WITH_SSL)
string(APPEND PKG_CONFIG_REQUIRES "libssl ")
endif()
if(WITH_SASL_CYRUS)
string(APPEND PKG_CONFIG_REQUIRES "libsasl2 ")
endif()
if(WITH_ZSTD)
endif()

if(WITH_SASL_CYRUS)
string(APPEND PKG_CONFIG_REQUIRES "libsasl2 ")
endif()

if(WITH_ZSTD)
string(APPEND PKG_CONFIG_REQUIRES "libzstd ")
endif()
if(WITH_LZ4_EXT)
endif()

if(WITH_LZ4_EXT)
string(APPEND PKG_CONFIG_REQUIRES "liblz4 ")
endif()
set(PKG_CONFIG_CFLAGS
"-I\${includedir}"
)
set(PKG_CONFIG_LIBS
"-L\${libdir} -lrdkafka"
)
set(PKG_CONFIG_LIBS_PRIVATE
"-lpthread"
)
find_library(RT_LIBRARY rt)
if(RT_LIBRARY)
string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lrt")
endif()
if(WITH_PLUGINS)
string(APPEND PKG_CONFIG_LIBS_PRIVATE " -ldl")
endif()
if(WITH_HDRHISTOGRAM)
string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lm")
endif()
configure_file(
"../packaging/cmake/rdkafka.pc.in"
"${GENERATED_DIR}/rdkafka.pc"
@ONLY
)
install(FILES ${GENERATED_DIR}/rdkafka.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)
if(RDKAFKA_BUILD_STATIC)
set(PKG_CONFIG_NAME
"librdkafka-static"
)
set(PKG_CONFIG_DESCRIPTION
"The Apache Kafka C/C++ library (static)"
endif()

set(PKG_CONFIG_CFLAGS "-I\${includedir}")
set(PKG_CONFIG_LIBS "-L\${libdir} -lrdkafka")
set(PKG_CONFIG_LIBS_PRIVATE "-lpthread")
find_library(RT_LIBRARY rt)
if(RT_LIBRARY)
string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lrt")
endif()

if(WITH_PLUGINS)
string(APPEND PKG_CONFIG_LIBS_PRIVATE " -ldl")
endif()

if(WITH_HDRHISTOGRAM)
string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lm")
endif()

configure_file(
"../packaging/cmake/rdkafka.pc.in"
"${GENERATED_DIR}/rdkafka.pc"
@ONLY
)
set(PKG_CONFIG_LIBS
"-L\${libdir} \${libdir}/librdkafka.a"
install(
FILES ${GENERATED_DIR}/rdkafka.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)
else()
set(PKG_CONFIG_REQUIRES "")
set(PKG_CONFIG_NAME "librdkafka-static")
set(PKG_CONFIG_DESCRIPTION "The Apache Kafka C/C++ library (static)")
set(PKG_CONFIG_CFLAGS "-I\${includedir} -DLIBRDKAFKA_STATICLIB")
if(WIN32)
set(
PKG_CONFIG_LIBS
"-L\${libdir} \${libdir}/librdkafka.a -lws2_32 -lsecur32 -lcrypt32"
)
else()
set(PKG_CONFIG_LIBS "-L\${libdir} \${libdir}/librdkafka.a")
endif()

configure_file(
"../packaging/cmake/rdkafka.pc.in"
"${GENERATED_DIR}/rdkafka-static.pc"
@ONLY
)
install(FILES ${GENERATED_DIR}/rdkafka.pc
install(
FILES ${GENERATED_DIR}/rdkafka-static.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)
endif()
Expand Down