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 10 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
68 changes: 30 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ parseversion("src/rdkafka.h")

project(RdKafka VERSION ${RDKAFKA_VERSION})

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/packaging/cmake/Modules/")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
neptoess marked this conversation as resolved.
Show resolved Hide resolved
"${CMAKE_CURRENT_SOURCE_DIR}/packaging/cmake/Modules/")

# Options. No 'RDKAFKA_' prefix to match old C++ code. {

# This option doesn't affect build in fact, only C code
# (see 'rd_kafka_version_str'). In CMake the build type feature usually used
# (like Debug, Release, etc.).
# This option doesn't affect build in fact, only C code (see
# 'rd_kafka_version_str').
# In CMake the build type feature usually used (like Debug, Release, etc.).
option(WITHOUT_OPTIMIZATION "Disable optimization" OFF)

option(ENABLE_DEVEL "Enable development asserts, checks, etc" OFF)
Expand All @@ -36,7 +37,7 @@ endif()
include(CheckLibraryExists)
check_library_exists(m pow "" WITH_HDRHISTOGRAM)
if(WITH_HDRHISTOGRAM)
list(APPEND BUILT_WITH "HDRHISTOGRAM")
neptoess marked this conversation as resolved.
Show resolved Hide resolved
list(APPEND BUILT_WITH "HDRHISTOGRAM")
endif()
# }

Expand Down Expand Up @@ -68,11 +69,10 @@ endif()

# LibDL {
try_compile(
WITH_LIBDL
"${CMAKE_CURRENT_BINARY_DIR}/try_compile"
"${TRYCOMPILE_SRC_DIR}/dlopen_test.c"
LINK_LIBRARIES "${CMAKE_DL_LIBS}"
)
WITH_LIBDL
"${CMAKE_CURRENT_BINARY_DIR}/try_compile"
"${TRYCOMPILE_SRC_DIR}/dlopen_test.c"
LINK_LIBRARIES "${CMAKE_DL_LIBS}")
if(WITH_LIBDL)
list(APPEND BUILT_WITH "LIBDL")
endif()
Expand Down Expand Up @@ -117,11 +117,10 @@ else()
set(with_sasl_default ON)
else()
try_compile(
WITH_SASL_CYRUS_BOOL
"${CMAKE_CURRENT_BINARY_DIR}/try_compile"
"${TRYCOMPILE_SRC_DIR}/libsasl2_test.c"
LINK_LIBRARIES "-lsasl2"
)
WITH_SASL_CYRUS_BOOL
"${CMAKE_CURRENT_BINARY_DIR}/try_compile"
"${TRYCOMPILE_SRC_DIR}/libsasl2_test.c"
LINK_LIBRARIES "-lsasl2")
if(WITH_SASL_CYRUS_BOOL)
set(with_sasl_default ON)
set(SASL_LIBRARIES "-lsasl2")
Expand Down Expand Up @@ -163,7 +162,8 @@ option(RDKAFKA_BUILD_STATIC "Build static rdkafka library" OFF)
option(RDKAFKA_BUILD_EXAMPLES "Build examples" ON)
option(RDKAFKA_BUILD_TESTS "Build tests" ON)
if(WIN32)
option(WITHOUT_WIN32_CONFIG "Avoid including win32_config.h on cmake builds" ON)
option(WITHOUT_WIN32_CONFIG "Avoid including win32_config.h on cmake builds"
ON)
endif(WIN32)

# In:
Expand Down Expand Up @@ -226,35 +226,27 @@ set(namespace "${PROJECT_NAME}::")
include(CMakePackageConfigHelpers)

# In:
# * targets_export_name
# * PROJECT_NAME
# * targets_export_name
# * PROJECT_NAME
configure_package_config_file(
"packaging/cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
"packaging/cmake/Config.cmake.in" "${project_config}"
INSTALL_DESTINATION "${config_install_dir}")

write_basic_package_version_file(
"${project_version}"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
"${project_version}"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)

install(
FILES "${project_config}" "${project_version}" "packaging/cmake/Modules/FindLZ4.cmake"
DESTINATION "${config_install_dir}"
)
install(FILES "${project_config}" "${project_version}"
"packaging/cmake/Modules/FindLZ4.cmake"
DESTINATION "${config_install_dir}")

install(
EXPORT "${targets_export_name}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)
EXPORT "${targets_export_name}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}")

install(
FILES LICENSES.txt
DESTINATION "share/licenses/librdkafka"
)
install(FILES LICENSES.txt DESTINATION "share/licenses/librdkafka")

# }

Expand Down
18 changes: 10 additions & 8 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if(WIN32)
set(win32_sources ../win32/wingetopt.c ../win32/wingetopt.h)
set(win32_sources ../win32/wingetopt.c ../win32/wingetopt.h)
endif(WIN32)

add_executable(producer producer.c ${win32_sources})
Expand All @@ -17,17 +17,19 @@ target_link_libraries(rdkafka_performance PUBLIC rdkafka)
add_executable(rdkafka_example_cpp rdkafka_example.cpp ${win32_sources})
target_link_libraries(rdkafka_example_cpp PUBLIC rdkafka++)

add_executable(rdkafka_complex_consumer_example_cpp rdkafka_complex_consumer_example.cpp ${win32_sources})
add_executable(rdkafka_complex_consumer_example_cpp
rdkafka_complex_consumer_example.cpp ${win32_sources})
target_link_libraries(rdkafka_complex_consumer_example_cpp PUBLIC rdkafka++)

# The targets below has Unix include dirs and do not compile on Windows.
if(NOT WIN32)
add_executable(rdkafka_example rdkafka_example.c)
target_link_libraries(rdkafka_example PUBLIC rdkafka)
add_executable(rdkafka_example rdkafka_example.c)
target_link_libraries(rdkafka_example PUBLIC rdkafka)

add_executable(rdkafka_complex_consumer_example rdkafka_complex_consumer_example.c)
target_link_libraries(rdkafka_complex_consumer_example PUBLIC rdkafka)
add_executable(rdkafka_complex_consumer_example
rdkafka_complex_consumer_example.c)
target_link_libraries(rdkafka_complex_consumer_example PUBLIC rdkafka)

add_executable(kafkatest_verifiable_client kafkatest_verifiable_client.cpp)
target_link_libraries(kafkatest_verifiable_client PUBLIC rdkafka++)
add_executable(kafkatest_verifiable_client kafkatest_verifiable_client.cpp)
target_link_libraries(kafkatest_verifiable_client PUBLIC rdkafka++)
endif(NOT WIN32)
39 changes: 36 additions & 3 deletions packaging/mingw-w64/configure-build-msys2-mingw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,48 @@ cmake \
-D RDKAFKA_BUILD_TESTS=ON \
-D WITH_LIBDL=OFF \
-D WITH_PLUGINS=OFF \
-D WITH_SASL=ON \
neptoess marked this conversation as resolved.
Show resolved Hide resolved
-D WITH_SASL=OFF \
-D WITH_SSL=ON \
-D WITH_ZLIB=OFF \
-D RDKAFKA_BUILD_STATIC=OFF \
-D CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE .
-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 ../src/librdkafka.a ./
cp ../src-cpp/librdkafka++.a ./librdkafkapp.a
neptoess marked this conversation as resolved.
Show resolved Hide resolved
ar -M << EOF
create librdkafka_merge.a
neptoess marked this conversation as resolved.
Show resolved Hide resolved
addlib librdkafka.a
addlib libzstd.a
addlib libcrypto.a
addlib liblz4.a
addlib libssl.a
save
end
EOF

ar -M << EOF
create librdkafkapp_merge.a
addlib librdkafka_merge.a
addlib librdkafkapp.a
save
end
EOF

cp ./librdkafka_merge.a ../dest/lib/librdkafka.a
cp ./librdkafkapp_merge.a ../dest/lib/librdkafka++.a
popd
rm -rf ./mergescratch

export PATH="$PWD/dest/bin:/mingw64/bin/:${PATH}"
cd tests
./test-runner.exe -l -Q -p1
9 changes: 8 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,16 @@ 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-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-openssl mingw-w64-x86_64-lz4 mingw-w64-x86_64-zstd
neptoess marked this conversation as resolved.
Show resolved Hide resolved

# 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

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.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
103 changes: 41 additions & 62 deletions src-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
set(LIBVER 1)

set(
sources
set(sources
ConfImpl.cpp
ConsumerImpl.cpp
HandleImpl.cpp
Expand All @@ -13,8 +12,7 @@ set(
QueueImpl.cpp
RdKafka.cpp
TopicImpl.cpp
TopicPartitionImpl.cpp
)
TopicPartitionImpl.cpp)

if(RDKAFKA_BUILD_STATIC)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Expand All @@ -31,69 +29,50 @@ endif()
target_link_libraries(rdkafka++ PUBLIC rdkafka)

# Support '#include <rdkafcpp.h>'
target_include_directories(rdkafka++ PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>")
target_include_directories(
rdkafka++ PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>")
if(NOT RDKAFKA_BUILD_STATIC)
target_compile_definitions(rdkafka++ PRIVATE LIBRDKAFKACPP_EXPORTS)
target_compile_definitions(rdkafka++ PRIVATE LIBRDKAFKACPP_EXPORTS)
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(
"../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"
)
configure_file(
"../packaging/cmake/rdkafka.pc.in"
"${GENERATED_DIR}/rdkafka++-static.pc"
@ONLY
)
install(FILES ${GENERATED_DIR}/rdkafka.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)
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")
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++-static.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()

install(
TARGETS rdkafka++
EXPORT "${targets_export_name}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
TARGETS rdkafka++
EXPORT "${targets_export_name}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

install(
FILES "rdkafkacpp.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/librdkafka"
)
install(FILES "rdkafkacpp.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/librdkafka")
Loading