Skip to content

Commit 79d5de6

Browse files
authored
rdkafka: switch to cmake, split outputs, remove static library from non-static targets, fix static build (#349725)
2 parents 181ac6f + 0aca4a2 commit 79d5de6

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

pkgs/by-name/mo/modern-cpp-kafka/package.nix

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ stdenv.mkDerivation rec {
4141
url = "https://github.com/morganstanley/modern-cpp-kafka/commit/236f8f91f5c3ad6e1055a6f55cd3aebd218e1226.patch";
4242
hash = "sha256-cy568TQUu08sadq79hDz9jMvDqiDjfr+1cLMxFWGm1Q=";
4343
})
44+
(fetchpatch {
45+
name = "macos-find-dylib.patch";
46+
url = "https://github.com/morganstanley/modern-cpp-kafka/commit/dc2753cd95b607a7202b40bad3aad472558bf350.patch";
47+
hash = "sha256-Te3GwAVRDyb6GFWlvkq1mIcNeXCtMyLr+/w1LilUYbE=";
48+
})
4449
];
4550

4651
postPatch = ''
@@ -53,13 +58,18 @@ stdenv.mkDerivation rec {
5358
buildInputs = [ boost ];
5459
propagatedBuildInputs = [ rdkafka ];
5560

56-
cmakeFlags = [
57-
"-DLIBRDKAFKA_INCLUDE_DIR=${rdkafka.out}/include"
58-
"-DGTEST_LIBRARY_DIR=${gtest.out}/lib"
59-
"-DGTEST_INCLUDE_DIR=${gtest.dev}/include"
60-
"-DRAPIDJSON_INCLUDE_DIRS=${rapidjson.out}/include"
61-
"-DCMAKE_CXX_FLAGS=-Wno-uninitialized"
62-
];
61+
cmakeFlags =
62+
let
63+
inherit (lib) cmakeFeature getLib getInclude;
64+
in
65+
[
66+
(cmakeFeature "LIBRDKAFKA_LIBRARY_DIR" "${getLib rdkafka}/lib")
67+
(cmakeFeature "LIBRDKAFKA_INCLUDE_DIR" "${getInclude rdkafka}/include")
68+
(cmakeFeature "GTEST_LIBRARY_DIR" "${getLib gtest}/lib")
69+
(cmakeFeature "GTEST_INCLUDE_DIR" "${getInclude gtest}/include")
70+
(cmakeFeature "RAPIDJSON_INCLUDE_DIRS" "${getInclude rapidjson}/include")
71+
(cmakeFeature "CMAKE_CXX_FLAGS" "-Wno-uninitialized")
72+
];
6373

6474
checkInputs = [
6575
gtest

pkgs/by-name/rd/rdkafka/package.nix

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
fetchFromGitHub,
55
zlib,
66
zstd,
7-
pkg-config,
8-
python3,
97
openssl,
10-
which,
118
curl,
9+
cmake,
10+
ninja,
1211
}:
1312

1413
stdenv.mkDerivation (finalAttrs: {
@@ -22,10 +21,14 @@ stdenv.mkDerivation (finalAttrs: {
2221
sha256 = "sha256-OCCsxgEO8UvCcC0XwzqpqmaT8dV0Klrspp+2o1FbH2Y=";
2322
};
2423

24+
outputs = [
25+
"out"
26+
"dev"
27+
];
28+
2529
nativeBuildInputs = [
26-
pkg-config
27-
python3
28-
which
30+
cmake
31+
ninja
2932
];
3033

3134
buildInputs = [
@@ -35,12 +38,30 @@ stdenv.mkDerivation (finalAttrs: {
3538
curl
3639
];
3740

38-
env.NIX_CFLAGS_COMPILE = "-Wno-error=strict-overflow";
41+
# examples and tests don't build on darwin statically
42+
cmakeFlags = [
43+
(lib.cmakeBool "RDKAFKA_BUILD_STATIC" stdenv.hostPlatform.isStatic)
44+
(lib.cmakeBool "RDKAFKA_BUILD_TESTS" (
45+
!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isStatic
46+
))
47+
(lib.cmakeBool "RDKAFKA_BUILD_EXAMPLES" (
48+
!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isStatic
49+
))
50+
(lib.cmakeFeature "CMAKE_C_FLAGS" "-Wno-error=strict-overflow")
51+
];
3952

4053
postPatch = ''
4154
patchShebangs .
4255
'';
4356

57+
postFixup = lib.optionalString stdenv.hostPlatform.isStatic ''
58+
# rdkafka changes the library names for static libraries but users in pkgsStatic aren't likely to be aware of this
59+
# make sure the libraries are findable with both names
60+
for pc in rdkafka{,++}; do
61+
ln -s $dev/lib/pkgconfig/$pc{-static,}.pc
62+
done
63+
'';
64+
4465
enableParallelBuilding = true;
4566

4667
meta = with lib; {

pkgs/development/php-packages/rdkafka/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ buildPecl {
1818

1919
postPhpize = ''
2020
substituteInPlace configure \
21-
--replace 'SEARCH_PATH="/usr/local /usr"' 'SEARCH_PATH=${rdkafka}'
21+
--replace-fail 'SEARCH_PATH="/usr/local /usr"' 'SEARCH_PATH=${lib.getInclude rdkafka}'
2222
'';
2323

2424
meta = with lib; {

0 commit comments

Comments
 (0)