rdkafka: switch to cmake, split outputs, remove static library from non-static targets, fix static build (#349725)

This commit is contained in:
Yueh-Shun Li
2025-03-14 18:04:14 +08:00
committed by GitHub
3 changed files with 46 additions and 15 deletions
+17 -7
View File
@@ -41,6 +41,11 @@ stdenv.mkDerivation rec {
url = "https://github.com/morganstanley/modern-cpp-kafka/commit/236f8f91f5c3ad6e1055a6f55cd3aebd218e1226.patch";
hash = "sha256-cy568TQUu08sadq79hDz9jMvDqiDjfr+1cLMxFWGm1Q=";
})
(fetchpatch {
name = "macos-find-dylib.patch";
url = "https://github.com/morganstanley/modern-cpp-kafka/commit/dc2753cd95b607a7202b40bad3aad472558bf350.patch";
hash = "sha256-Te3GwAVRDyb6GFWlvkq1mIcNeXCtMyLr+/w1LilUYbE=";
})
];
postPatch = ''
@@ -53,13 +58,18 @@ stdenv.mkDerivation rec {
buildInputs = [ boost ];
propagatedBuildInputs = [ rdkafka ];
cmakeFlags = [
"-DLIBRDKAFKA_INCLUDE_DIR=${rdkafka.out}/include"
"-DGTEST_LIBRARY_DIR=${gtest.out}/lib"
"-DGTEST_INCLUDE_DIR=${gtest.dev}/include"
"-DRAPIDJSON_INCLUDE_DIRS=${rapidjson.out}/include"
"-DCMAKE_CXX_FLAGS=-Wno-uninitialized"
];
cmakeFlags =
let
inherit (lib) cmakeFeature getLib getInclude;
in
[
(cmakeFeature "LIBRDKAFKA_LIBRARY_DIR" "${getLib rdkafka}/lib")
(cmakeFeature "LIBRDKAFKA_INCLUDE_DIR" "${getInclude rdkafka}/include")
(cmakeFeature "GTEST_LIBRARY_DIR" "${getLib gtest}/lib")
(cmakeFeature "GTEST_INCLUDE_DIR" "${getInclude gtest}/include")
(cmakeFeature "RAPIDJSON_INCLUDE_DIRS" "${getInclude rapidjson}/include")
(cmakeFeature "CMAKE_CXX_FLAGS" "-Wno-uninitialized")
];
checkInputs = [
gtest
+28 -7
View File
@@ -4,11 +4,10 @@
fetchFromGitHub,
zlib,
zstd,
pkg-config,
python3,
openssl,
which,
curl,
cmake,
ninja,
}:
stdenv.mkDerivation (finalAttrs: {
@@ -22,10 +21,14 @@ stdenv.mkDerivation (finalAttrs: {
sha256 = "sha256-OCCsxgEO8UvCcC0XwzqpqmaT8dV0Klrspp+2o1FbH2Y=";
};
outputs = [
"out"
"dev"
];
nativeBuildInputs = [
pkg-config
python3
which
cmake
ninja
];
buildInputs = [
@@ -35,12 +38,30 @@ stdenv.mkDerivation (finalAttrs: {
curl
];
env.NIX_CFLAGS_COMPILE = "-Wno-error=strict-overflow";
# examples and tests don't build on darwin statically
cmakeFlags = [
(lib.cmakeBool "RDKAFKA_BUILD_STATIC" stdenv.hostPlatform.isStatic)
(lib.cmakeBool "RDKAFKA_BUILD_TESTS" (
!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isStatic
))
(lib.cmakeBool "RDKAFKA_BUILD_EXAMPLES" (
!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isStatic
))
(lib.cmakeFeature "CMAKE_C_FLAGS" "-Wno-error=strict-overflow")
];
postPatch = ''
patchShebangs .
'';
postFixup = lib.optionalString stdenv.hostPlatform.isStatic ''
# rdkafka changes the library names for static libraries but users in pkgsStatic aren't likely to be aware of this
# make sure the libraries are findable with both names
for pc in rdkafka{,++}; do
ln -s $dev/lib/pkgconfig/$pc{-static,}.pc
done
'';
enableParallelBuilding = true;
meta = with lib; {
@@ -18,7 +18,7 @@ buildPecl {
postPhpize = ''
substituteInPlace configure \
--replace 'SEARCH_PATH="/usr/local /usr"' 'SEARCH_PATH=${rdkafka}'
--replace-fail 'SEARCH_PATH="/usr/local /usr"' 'SEARCH_PATH=${lib.getInclude rdkafka}'
'';
meta = with lib; {