rdkafka 0.22.0.beta1-x86_64-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.github/CODEOWNERS +3 -0
  3. data/.github/FUNDING.yml +1 -0
  4. data/.github/workflows/ci_linux_x86_64_gnu.yml +249 -0
  5. data/.github/workflows/ci_linux_x86_64_musl.yml +205 -0
  6. data/.github/workflows/ci_macos_arm64.yml +306 -0
  7. data/.github/workflows/push_linux_x86_64_gnu.yml +64 -0
  8. data/.github/workflows/push_linux_x86_64_musl.yml +77 -0
  9. data/.github/workflows/push_macos_arm64.yml +54 -0
  10. data/.github/workflows/push_ruby.yml +37 -0
  11. data/.github/workflows/verify-action-pins.yml +16 -0
  12. data/.gitignore +14 -0
  13. data/.rspec +2 -0
  14. data/.ruby-gemset +1 -0
  15. data/.ruby-version +1 -0
  16. data/.yardopts +2 -0
  17. data/CHANGELOG.md +247 -0
  18. data/Gemfile +5 -0
  19. data/MIT-LICENSE +22 -0
  20. data/README.md +178 -0
  21. data/Rakefile +96 -0
  22. data/docker-compose.yml +25 -0
  23. data/ext/README.md +19 -0
  24. data/ext/Rakefile +131 -0
  25. data/ext/build_common.sh +361 -0
  26. data/ext/build_linux_x86_64_gnu.sh +306 -0
  27. data/ext/build_linux_x86_64_musl.sh +763 -0
  28. data/ext/build_macos_arm64.sh +550 -0
  29. data/ext/librdkafka.so +0 -0
  30. data/lib/rdkafka/abstract_handle.rb +116 -0
  31. data/lib/rdkafka/admin/acl_binding_result.rb +51 -0
  32. data/lib/rdkafka/admin/config_binding_result.rb +30 -0
  33. data/lib/rdkafka/admin/config_resource_binding_result.rb +18 -0
  34. data/lib/rdkafka/admin/create_acl_handle.rb +28 -0
  35. data/lib/rdkafka/admin/create_acl_report.rb +24 -0
  36. data/lib/rdkafka/admin/create_partitions_handle.rb +27 -0
  37. data/lib/rdkafka/admin/create_partitions_report.rb +6 -0
  38. data/lib/rdkafka/admin/create_topic_handle.rb +29 -0
  39. data/lib/rdkafka/admin/create_topic_report.rb +24 -0
  40. data/lib/rdkafka/admin/delete_acl_handle.rb +30 -0
  41. data/lib/rdkafka/admin/delete_acl_report.rb +23 -0
  42. data/lib/rdkafka/admin/delete_groups_handle.rb +28 -0
  43. data/lib/rdkafka/admin/delete_groups_report.rb +24 -0
  44. data/lib/rdkafka/admin/delete_topic_handle.rb +29 -0
  45. data/lib/rdkafka/admin/delete_topic_report.rb +24 -0
  46. data/lib/rdkafka/admin/describe_acl_handle.rb +30 -0
  47. data/lib/rdkafka/admin/describe_acl_report.rb +24 -0
  48. data/lib/rdkafka/admin/describe_configs_handle.rb +33 -0
  49. data/lib/rdkafka/admin/describe_configs_report.rb +54 -0
  50. data/lib/rdkafka/admin/incremental_alter_configs_handle.rb +33 -0
  51. data/lib/rdkafka/admin/incremental_alter_configs_report.rb +54 -0
  52. data/lib/rdkafka/admin.rb +833 -0
  53. data/lib/rdkafka/bindings.rb +566 -0
  54. data/lib/rdkafka/callbacks.rb +415 -0
  55. data/lib/rdkafka/config.rb +398 -0
  56. data/lib/rdkafka/consumer/headers.rb +79 -0
  57. data/lib/rdkafka/consumer/message.rb +86 -0
  58. data/lib/rdkafka/consumer/partition.rb +51 -0
  59. data/lib/rdkafka/consumer/topic_partition_list.rb +169 -0
  60. data/lib/rdkafka/consumer.rb +653 -0
  61. data/lib/rdkafka/error.rb +101 -0
  62. data/lib/rdkafka/helpers/oauth.rb +58 -0
  63. data/lib/rdkafka/helpers/time.rb +14 -0
  64. data/lib/rdkafka/metadata.rb +115 -0
  65. data/lib/rdkafka/native_kafka.rb +139 -0
  66. data/lib/rdkafka/producer/delivery_handle.rb +40 -0
  67. data/lib/rdkafka/producer/delivery_report.rb +46 -0
  68. data/lib/rdkafka/producer/partitions_count_cache.rb +216 -0
  69. data/lib/rdkafka/producer.rb +430 -0
  70. data/lib/rdkafka/version.rb +7 -0
  71. data/lib/rdkafka.rb +54 -0
  72. data/rdkafka.gemspec +65 -0
  73. data/renovate.json +92 -0
  74. data/spec/rdkafka/abstract_handle_spec.rb +117 -0
  75. data/spec/rdkafka/admin/create_acl_handle_spec.rb +56 -0
  76. data/spec/rdkafka/admin/create_acl_report_spec.rb +18 -0
  77. data/spec/rdkafka/admin/create_topic_handle_spec.rb +52 -0
  78. data/spec/rdkafka/admin/create_topic_report_spec.rb +16 -0
  79. data/spec/rdkafka/admin/delete_acl_handle_spec.rb +85 -0
  80. data/spec/rdkafka/admin/delete_acl_report_spec.rb +72 -0
  81. data/spec/rdkafka/admin/delete_topic_handle_spec.rb +52 -0
  82. data/spec/rdkafka/admin/delete_topic_report_spec.rb +16 -0
  83. data/spec/rdkafka/admin/describe_acl_handle_spec.rb +85 -0
  84. data/spec/rdkafka/admin/describe_acl_report_spec.rb +73 -0
  85. data/spec/rdkafka/admin_spec.rb +770 -0
  86. data/spec/rdkafka/bindings_spec.rb +223 -0
  87. data/spec/rdkafka/callbacks_spec.rb +20 -0
  88. data/spec/rdkafka/config_spec.rb +258 -0
  89. data/spec/rdkafka/consumer/headers_spec.rb +73 -0
  90. data/spec/rdkafka/consumer/message_spec.rb +139 -0
  91. data/spec/rdkafka/consumer/partition_spec.rb +57 -0
  92. data/spec/rdkafka/consumer/topic_partition_list_spec.rb +248 -0
  93. data/spec/rdkafka/consumer_spec.rb +1274 -0
  94. data/spec/rdkafka/error_spec.rb +89 -0
  95. data/spec/rdkafka/metadata_spec.rb +79 -0
  96. data/spec/rdkafka/native_kafka_spec.rb +130 -0
  97. data/spec/rdkafka/producer/delivery_handle_spec.rb +45 -0
  98. data/spec/rdkafka/producer/delivery_report_spec.rb +25 -0
  99. data/spec/rdkafka/producer/partitions_count_cache_spec.rb +359 -0
  100. data/spec/rdkafka/producer_spec.rb +1052 -0
  101. data/spec/spec_helper.rb +195 -0
  102. metadata +276 -0
@@ -0,0 +1,550 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # Simple librdkafka build script for macOS with Kerberos support
4
+ # Usage: ./build-librdkafka-macos.sh
5
+ #
6
+ # Expected directory structure:
7
+ # ext/build_macos.sh (this script)
8
+ # ext/build-common.sh (shared functions)
9
+ # dist/librdkafka-*.tar.gz (librdkafka source tarball)
10
+ # dist/patches/*.patch (optional Ruby-specific patches)
11
+ #
12
+ set -euo pipefail
13
+
14
+ # Source common functions and constants
15
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16
+ source "$SCRIPT_DIR/build_common.sh"
17
+
18
+ # Platform-specific paths
19
+ DIST_DIR="$SCRIPT_DIR/../dist"
20
+ PATCHES_DIR="$DIST_DIR/patches"
21
+ BUILD_DIR="$(pwd)/build-tmp-macos"
22
+ DEPS_PREFIX="/tmp/macos-deps"
23
+
24
+ # macOS-specific dependency check
25
+ check_macos_dependencies() {
26
+ log "Checking macOS build dependencies..."
27
+
28
+ # Check for Xcode Command Line Tools
29
+ if ! xcode-select -p &> /dev/null; then
30
+ error "Xcode Command Line Tools not found. Install with: xcode-select --install"
31
+ fi
32
+
33
+ # Check for required tools (in addition to common ones)
34
+ local missing_tools=()
35
+
36
+ command -v gcc &> /dev/null || missing_tools+=("gcc")
37
+ command -v clang &> /dev/null || missing_tools+=("clang")
38
+
39
+ if [ ${#missing_tools[@]} -gt 0 ]; then
40
+ error "Missing required tools: ${missing_tools[*]}"
41
+ fi
42
+
43
+ log "✅ All required tools found"
44
+
45
+ # Show system info
46
+ log "Build environment:"
47
+ log " - macOS version: $(sw_vers -productVersion)"
48
+ log " - Architecture: $(uname -m)"
49
+ log " - Xcode tools: $(xcode-select -p)"
50
+ }
51
+
52
+ # macOS-specific compiler setup
53
+ setup_macos_compiler() {
54
+ local arch="$1"
55
+
56
+ # Get the proper macOS SDK path
57
+ MACOS_SDK_PATH=$(xcrun --show-sdk-path)
58
+ log "Using macOS SDK: $MACOS_SDK_PATH"
59
+
60
+ # Set macOS-specific flags
61
+ export CC="$(xcrun -find clang)"
62
+ export CFLAGS="-fPIC -O2 -arch $arch -isysroot $MACOS_SDK_PATH"
63
+ export CXXFLAGS="-fPIC -O2 -arch $arch -isysroot $MACOS_SDK_PATH"
64
+ export CPPFLAGS="-isysroot $MACOS_SDK_PATH"
65
+
66
+ log "Applied $arch specific flags"
67
+ }
68
+
69
+ # Build static OpenSSL for macOS
70
+ build_openssl_macos() {
71
+ local arch="$1"
72
+ local openssl_prefix="$2"
73
+ local openssl_dir="$3"
74
+
75
+ cd "$openssl_dir"
76
+
77
+ if [ ! -f "$openssl_prefix/lib/libssl.a" ]; then
78
+ log "Configuring and building static OpenSSL..."
79
+ make clean 2>/dev/null || true
80
+
81
+ setup_macos_compiler "$arch"
82
+
83
+ # Configure OpenSSL for macOS
84
+ if [ "$arch" = "arm64" ]; then
85
+ ./Configure darwin64-arm64-cc \
86
+ no-shared \
87
+ no-dso \
88
+ --prefix="$openssl_prefix" \
89
+ --openssldir="$openssl_prefix/ssl"
90
+ else
91
+ ./Configure darwin64-x86_64-cc \
92
+ no-shared \
93
+ no-dso \
94
+ --prefix="$openssl_prefix" \
95
+ --openssldir="$openssl_prefix/ssl"
96
+ fi
97
+
98
+ make -j$(get_cpu_count)
99
+ make install
100
+
101
+ # Verify the build
102
+ if [ ! -f "$openssl_prefix/lib/libssl.a" ] || [ ! -f "$openssl_prefix/lib/libcrypto.a" ]; then
103
+ error "Failed to build static OpenSSL"
104
+ fi
105
+
106
+ log "✅ Static OpenSSL built successfully at $openssl_prefix"
107
+ else
108
+ log "Static OpenSSL already built, skipping..."
109
+ fi
110
+ }
111
+
112
+ # Build static MIT Kerberos for macOS
113
+ build_krb5_macos() {
114
+ local arch="$1"
115
+ local krb5_prefix="$2"
116
+ local krb5_dir="$3"
117
+
118
+ cd "$krb5_dir/src"
119
+
120
+ if [ ! -f "$krb5_prefix/lib/libgssapi_krb5.a" ]; then
121
+ log "Configuring and building static MIT Kerberos..."
122
+ make clean 2>/dev/null || true
123
+
124
+ setup_macos_compiler "$arch"
125
+
126
+ # Configure MIT Kerberos for macOS
127
+ ./configure \
128
+ --disable-shared \
129
+ --enable-static \
130
+ --prefix="$krb5_prefix" \
131
+ --without-ldap \
132
+ --without-tcl \
133
+ --without-keyutils \
134
+ --disable-rpath \
135
+ --without-system-verto \
136
+ --disable-thread-support \
137
+ --disable-aesni
138
+
139
+ # Build everything except the problematic kadmin tools (same as Linux)
140
+ log "Building Kerberos (will ignore kadmin build failures)..."
141
+ make -j$(get_cpu_count) || {
142
+ log "Full build failed (expected due to kadmin), continuing with libraries..."
143
+ # The libraries should be built even if kadmin fails
144
+ true
145
+ }
146
+
147
+ # Install what was successfully built
148
+ make install || {
149
+ log "Full install failed, installing individual components..."
150
+ # Try to install the core libraries manually
151
+ make install-mkdirs 2>/dev/null || true
152
+ make -C util install 2>/dev/null || true
153
+ make -C lib install 2>/dev/null || true
154
+ make -C plugins/kdb/db2 install 2>/dev/null || true
155
+ }
156
+
157
+ # Verify we got the essential libraries
158
+ if [ ! -f "$krb5_prefix/lib/libgssapi_krb5.a" ]; then
159
+ error "Failed to build essential Kerberos libraries"
160
+ fi
161
+
162
+ log "✅ Static MIT Kerberos built successfully at $krb5_prefix"
163
+ else
164
+ log "Static MIT Kerberos already built, skipping..."
165
+ fi
166
+ }
167
+
168
+ # Build static Cyrus SASL for macOS with Kerberos support
169
+ build_sasl_macos() {
170
+ local arch="$1"
171
+ local sasl_prefix="$2"
172
+ local sasl_dir="$3"
173
+ local openssl_prefix="$4"
174
+ local krb5_prefix="$5"
175
+
176
+ cd "$sasl_dir"
177
+
178
+ if [ ! -f "$sasl_prefix/lib/libsasl2.a" ]; then
179
+ log "Configuring and building static Cyrus SASL with Kerberos support..."
180
+ make clean 2>/dev/null || true
181
+
182
+ setup_macos_compiler "$arch"
183
+ export CPPFLAGS="$CPPFLAGS -I$openssl_prefix/include -I$krb5_prefix/include"
184
+ export LDFLAGS="-L$openssl_prefix/lib -L$krb5_prefix/lib"
185
+
186
+ # Configure SASL with Kerberos/GSSAPI support (now ENABLED)
187
+ ./configure \
188
+ --disable-shared \
189
+ --enable-static \
190
+ --prefix="$sasl_prefix" \
191
+ --without-dblib \
192
+ --disable-gdbm \
193
+ --disable-macos-framework \
194
+ --disable-sample \
195
+ --disable-obsolete_cram_attr \
196
+ --disable-obsolete_digest_attr \
197
+ --enable-gssapi="$krb5_prefix" \
198
+ --disable-krb4 \
199
+ --with-openssl="$openssl_prefix"
200
+
201
+ make -j$(get_cpu_count)
202
+ make install
203
+
204
+ # Verify the build
205
+ if [ ! -f "$sasl_prefix/lib/libsasl2.a" ]; then
206
+ error "Failed to build static Cyrus SASL"
207
+ fi
208
+
209
+ log "✅ Static Cyrus SASL with Kerberos support built successfully at $sasl_prefix"
210
+ else
211
+ log "Static Cyrus SASL already built, skipping..."
212
+ fi
213
+ }
214
+
215
+ # Build generic static library for macOS
216
+ build_static_lib_macos() {
217
+ local lib_name="$1"
218
+ local arch="$2"
219
+ local prefix="$3"
220
+ local source_dir="$4"
221
+ local configure_args="$5"
222
+
223
+ cd "$source_dir"
224
+
225
+ local lib_file="$prefix/lib/lib${lib_name}.a"
226
+ if [ ! -f "$lib_file" ]; then
227
+ log "Configuring and building static $lib_name..."
228
+ make clean 2>/dev/null || true
229
+
230
+ setup_macos_compiler "$arch"
231
+
232
+ # Run configure with provided arguments
233
+ eval "./configure --prefix=\"$prefix\" $configure_args"
234
+
235
+ make -j$(get_cpu_count)
236
+ make install
237
+
238
+ # Verify the build
239
+ if [ ! -f "$lib_file" ]; then
240
+ error "Failed to build static $lib_name"
241
+ fi
242
+
243
+ log "✅ Static $lib_name built successfully at $prefix"
244
+ else
245
+ log "Static $lib_name already built, skipping..."
246
+ fi
247
+ }
248
+
249
+ # Check common and macOS-specific dependencies
250
+ check_common_dependencies
251
+ check_macos_dependencies
252
+
253
+ # Auto-detect librdkafka tarball
254
+ log "Looking for librdkafka tarball in $DIST_DIR..."
255
+ LIBRDKAFKA_TARBALL=$(find_librdkafka_tarball "$DIST_DIR")
256
+ log "Found librdkafka tarball: $LIBRDKAFKA_TARBALL"
257
+
258
+ # Verify librdkafka tarball checksum if available
259
+ verify_librdkafka_checksum "$LIBRDKAFKA_TARBALL"
260
+
261
+ # Find patches
262
+ PATCHES_FOUND=()
263
+ find_patches "$PATCHES_DIR" PATCHES_FOUND
264
+
265
+ # Detect architecture early since we need it for dependency building
266
+ ARCH=$(uname -m)
267
+ log "Detected architecture: $ARCH"
268
+
269
+ security_log "Starting secure build with checksum verification enabled"
270
+ log "Building self-contained librdkafka for macOS with Kerberos support"
271
+ log "Dependencies to build:"
272
+ log " - OpenSSL: $OPENSSL_VERSION"
273
+ log " - Cyrus SASL: $CYRUS_SASL_VERSION (with Kerberos support)"
274
+ log " - MIT Kerberos: $KRB5_VERSION"
275
+ log " - zlib: $ZLIB_VERSION"
276
+ log " - ZStd: $ZSTD_VERSION"
277
+ log "librdkafka source: $LIBRDKAFKA_TARBALL"
278
+ log "Build directory: $BUILD_DIR"
279
+
280
+ # Create build directory
281
+ mkdir -p "$BUILD_DIR"
282
+ cd "$BUILD_DIR"
283
+
284
+ # Build static OpenSSL first (other deps might need it)
285
+ log "Building static OpenSSL $OPENSSL_VERSION..."
286
+ OPENSSL_PREFIX="$DEPS_PREFIX/static-openssl-$OPENSSL_VERSION"
287
+ OPENSSL_TARBALL="openssl-$OPENSSL_VERSION.tar.gz"
288
+ OPENSSL_DIR="openssl-$OPENSSL_VERSION"
289
+
290
+ secure_download "$(get_openssl_url)" "$OPENSSL_TARBALL"
291
+ extract_if_needed "$OPENSSL_TARBALL" "$OPENSSL_DIR"
292
+ build_openssl_macos "$ARCH" "$OPENSSL_PREFIX" "$OPENSSL_DIR"
293
+
294
+ cd "$BUILD_DIR"
295
+
296
+ # Build static MIT Kerberos (before SASL since SASL needs it)
297
+ log "Building static MIT Kerberos $KRB5_VERSION..."
298
+ KRB5_PREFIX="$DEPS_PREFIX/static-krb5-$KRB5_VERSION"
299
+ KRB5_TARBALL="krb5-$KRB5_VERSION.tar.gz"
300
+ KRB5_DIR="krb5-$KRB5_VERSION"
301
+
302
+ secure_download "$(get_krb5_url)" "$KRB5_TARBALL"
303
+ extract_if_needed "$KRB5_TARBALL" "$KRB5_DIR"
304
+ build_krb5_macos "$ARCH" "$KRB5_PREFIX" "$KRB5_DIR"
305
+
306
+ cd "$BUILD_DIR"
307
+
308
+ # Build static Cyrus SASL (after OpenSSL and Kerberos since it needs both)
309
+ log "Building static Cyrus SASL $CYRUS_SASL_VERSION with Kerberos support..."
310
+ SASL_PREFIX="$DEPS_PREFIX/static-sasl-$CYRUS_SASL_VERSION"
311
+ SASL_TARBALL="cyrus-sasl-$CYRUS_SASL_VERSION.tar.gz"
312
+ SASL_DIR="cyrus-sasl-$CYRUS_SASL_VERSION"
313
+
314
+ secure_download "$(get_sasl_url)" "$SASL_TARBALL"
315
+ extract_if_needed "$SASL_TARBALL" "$SASL_DIR"
316
+ build_sasl_macos "$ARCH" "$SASL_PREFIX" "$SASL_DIR" "$OPENSSL_PREFIX" "$KRB5_PREFIX"
317
+
318
+ cd "$BUILD_DIR"
319
+
320
+ # Build static ZStd
321
+ log "Building static ZStd $ZSTD_VERSION..."
322
+ ZSTD_PREFIX="$DEPS_PREFIX/static-zstd-$ZSTD_VERSION"
323
+ ZSTD_TARBALL="zstd-$ZSTD_VERSION.tar.gz"
324
+ ZSTD_DIR="zstd-$ZSTD_VERSION"
325
+
326
+ secure_download "$(get_zstd_url)" "$ZSTD_TARBALL"
327
+ extract_if_needed "$ZSTD_TARBALL" "$ZSTD_DIR"
328
+ cd "$ZSTD_DIR"
329
+
330
+ if [ ! -f "$ZSTD_PREFIX/lib/libzstd.a" ]; then
331
+ log "Configuring and building static ZStd..."
332
+ make clean 2>/dev/null || true
333
+
334
+ setup_macos_compiler "$ARCH"
335
+
336
+ # Build static library using ZStd's Makefile
337
+ make lib-mt CFLAGS="$CFLAGS" PREFIX="$ZSTD_PREFIX" -j$(get_cpu_count)
338
+ make install PREFIX="$ZSTD_PREFIX"
339
+
340
+ # Verify the build
341
+ if [ ! -f "$ZSTD_PREFIX/lib/libzstd.a" ]; then
342
+ error "Failed to build static ZStd"
343
+ fi
344
+
345
+ log "✅ Static ZStd built successfully at $ZSTD_PREFIX"
346
+ else
347
+ log "Static ZStd already built, skipping..."
348
+ fi
349
+
350
+ cd "$BUILD_DIR"
351
+
352
+ # Build static zlib
353
+ log "Building static zlib $ZLIB_VERSION..."
354
+ ZLIB_PREFIX="$DEPS_PREFIX/static-zlib-$ZLIB_VERSION"
355
+ ZLIB_TARBALL="zlib-$ZLIB_VERSION.tar.gz"
356
+ ZLIB_DIR="zlib-$ZLIB_VERSION"
357
+
358
+ secure_download "$(get_zlib_url)" "$ZLIB_TARBALL"
359
+ extract_if_needed "$ZLIB_TARBALL" "$ZLIB_DIR"
360
+ build_static_lib_macos "z" "$ARCH" "$ZLIB_PREFIX" "$ZLIB_DIR" "--static"
361
+
362
+ cd "$BUILD_DIR"
363
+
364
+ # Completely disable pkg-config to prevent Homebrew library detection
365
+ log "Disabling pkg-config to prevent Homebrew interference..."
366
+ export PKG_CONFIG=""
367
+ export PKG_CONFIG_PATH=""
368
+ export PKG_CONFIG_LIBDIR=""
369
+
370
+ # Create a dummy pkg-config that always fails
371
+ mkdir -p "$BUILD_DIR/no-pkg-config"
372
+ cat > "$BUILD_DIR/no-pkg-config/pkg-config" << 'EOF'
373
+ #!/bin/sh
374
+ # Dummy pkg-config that always fails to prevent Homebrew detection
375
+ exit 1
376
+ EOF
377
+ chmod +x "$BUILD_DIR/no-pkg-config/pkg-config"
378
+
379
+ # Put our dummy pkg-config first in PATH
380
+ export PATH="$BUILD_DIR/no-pkg-config:$PATH"
381
+
382
+ log "pkg-config disabled - configure will use manual library detection only"
383
+
384
+ # Extract librdkafka
385
+ log "Extracting librdkafka..."
386
+ tar xzf "$LIBRDKAFKA_TARBALL"
387
+ cd "librdkafka-$LIBRDKAFKA_VERSION"
388
+
389
+ # Fix permissions and apply patches
390
+ fix_configure_permissions
391
+ apply_patches PATCHES_FOUND
392
+
393
+ # Set compiler flags for librdkafka
394
+ setup_macos_compiler "$ARCH"
395
+
396
+ # Configure librdkafka with static dependencies INCLUDING Kerberos
397
+ log "Configuring librdkafka with static dependencies including Kerberos..."
398
+
399
+ # Tell configure that math functions don't need -lm on macOS
400
+ export ac_cv_lib_m_floor=yes
401
+ export ac_cv_lib_m_ceil=yes
402
+ export ac_cv_lib_m_sqrt=yes
403
+ export ac_cv_lib_m_pow=yes
404
+ export LIBS="" # Clear any LIBS that might include -lm
405
+
406
+ # Use our static libraries instead of system versions (now including Kerberos)
407
+ export CPPFLAGS="$CPPFLAGS -I$OPENSSL_PREFIX/include -I$SASL_PREFIX/include -I$KRB5_PREFIX/include -I$ZLIB_PREFIX/include -I$ZSTD_PREFIX/include"
408
+ export LDFLAGS="-L$OPENSSL_PREFIX/lib -L$SASL_PREFIX/lib -L$KRB5_PREFIX/lib -L$ZLIB_PREFIX/lib -L$ZSTD_PREFIX/lib"
409
+
410
+ if [ -f configure ]; then
411
+ log "Using mklove configure script"
412
+ ./configure \
413
+ --enable-static \
414
+ --disable-shared \
415
+ --disable-curl \
416
+ --enable-gssapi
417
+ else
418
+ error "No configure script found"
419
+ fi
420
+
421
+ # Fix system library path for linking
422
+ MACOS_SDK_PATH=$(xcrun --show-sdk-path)
423
+ export LDFLAGS="$LDFLAGS -L$MACOS_SDK_PATH/usr/lib"
424
+
425
+ # Build librdkafka
426
+ log "Compiling librdkafka..."
427
+ make clean || true
428
+
429
+ # Build with LIBS override, but ignore dylib build failures
430
+ make -j$(get_cpu_count) LIBS="" || {
431
+ log "Build failed (expected - dylib linking issue), checking if static library was created..."
432
+ }
433
+
434
+ # Verify static library exists (this is what we actually need)
435
+ if [ ! -f src/librdkafka.a ]; then
436
+ error "librdkafka.a not found after build"
437
+ fi
438
+
439
+ log "✅ Static librdkafka.a built successfully"
440
+
441
+ # Remove the dylib check since we're building our own
442
+ # Don't check for src/librdkafka.1.dylib
443
+
444
+ log "librdkafka built successfully - proceeding to create custom self-contained dylib"
445
+
446
+ # Create self-contained dylib with Kerberos libraries included
447
+ log "Creating self-contained librdkafka.dylib with Kerberos support..."
448
+
449
+ # Create self-contained shared library by linking all static dependencies (NOW INCLUDING KERBEROS)
450
+ # This is the macOS equivalent of your Linux gcc -shared command
451
+ clang -dynamiclib -fPIC \
452
+ -Wl,-force_load,src/librdkafka.a \
453
+ -Wl,-force_load,"$SASL_PREFIX/lib/libsasl2.a" \
454
+ -Wl,-force_load,"$KRB5_PREFIX/lib/libgssapi_krb5.a" \
455
+ -Wl,-force_load,"$KRB5_PREFIX/lib/libkrb5.a" \
456
+ -Wl,-force_load,"$KRB5_PREFIX/lib/libk5crypto.a" \
457
+ -Wl,-force_load,"$KRB5_PREFIX/lib/libcom_err.a" \
458
+ -Wl,-force_load,"$KRB5_PREFIX/lib/libkrb5support.a" \
459
+ -Wl,-force_load,"$OPENSSL_PREFIX/lib/libssl.a" \
460
+ -Wl,-force_load,"$OPENSSL_PREFIX/lib/libcrypto.a" \
461
+ -Wl,-force_load,"$ZLIB_PREFIX/lib/libz.a" \
462
+ -Wl,-force_load,"$ZSTD_PREFIX/lib/libzstd.a" \
463
+ -o librdkafka.dylib \
464
+ -lpthread -lc -arch $ARCH -lresolv \
465
+ -install_name @rpath/librdkafka.dylib \
466
+ -Wl,-undefined,dynamic_lookup
467
+
468
+ if [ ! -f librdkafka.dylib ]; then
469
+ error "Failed to create self-contained librdkafka.dylib"
470
+ fi
471
+
472
+ log "✅ Self-contained librdkafka.dylib with Kerberos support created successfully"
473
+
474
+ # Verify the self-contained build
475
+ log "Verifying self-contained build..."
476
+ file librdkafka.dylib
477
+
478
+ log "Checking dependencies with otool (should only show system libraries):"
479
+ otool -L librdkafka.dylib
480
+
481
+ # Check for external dependencies that shouldn't be there (strict like Linux version)
482
+ log "Checking for external dependencies (should only show system libraries):"
483
+ EXTERNAL_DEPS=$(otool -L librdkafka.dylib | grep -v "librdkafka.dylib" | grep -v "/usr/lib/" | grep -v "/System/Library/" | grep -v "@rpath" || true)
484
+ if [ -n "$EXTERNAL_DEPS" ]; then
485
+ error "Found external dependencies - library is not self-contained: $EXTERNAL_DEPS"
486
+ else
487
+ log "✅ No external dependencies found - library is self-contained!"
488
+ fi
489
+
490
+ log "Checking exported symbols:"
491
+ # Avoid SIGPIPE by not using head in a pipe
492
+ nm -gU librdkafka.dylib > /tmp/symbols.txt 2>/dev/null || true
493
+ if [ -f /tmp/symbols.txt ]; then
494
+ head -10 /tmp/symbols.txt
495
+ rm -f /tmp/symbols.txt
496
+ else
497
+ log "Could not extract symbols (this is normal)"
498
+ fi
499
+
500
+ # Force output flush and add small delay
501
+ sync
502
+ sleep 1
503
+
504
+ # Copy to output directory
505
+ OUTPUT_DIR="$SCRIPT_DIR"
506
+ cp librdkafka.dylib "$OUTPUT_DIR/"
507
+ cp src/librdkafka.a "$OUTPUT_DIR/"
508
+
509
+ log "Build artifacts copied to: $OUTPUT_DIR/"
510
+ log " - librdkafka.dylib (shared library)"
511
+ log " - librdkafka.a (static library)"
512
+
513
+ # Force another flush
514
+ sync
515
+ sleep 1
516
+
517
+ # Print summaries
518
+ print_security_summary
519
+
520
+ # Enhanced summary for macOS with Kerberos
521
+ sync
522
+ echo ""
523
+ echo "🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉"
524
+ log "Build completed successfully!"
525
+ log "📦 Self-contained librdkafka built for macOS $ARCH with Kerberos support:"
526
+ log " ✅ Static library: librdkafka.a"
527
+ log " ✅ Self-contained dylib: librdkafka.dylib (with bundled dependencies)"
528
+ log " ✅ Static OpenSSL: $OPENSSL_VERSION (SSL/TLS support) - bundled"
529
+ log " ✅ Static Cyrus SASL: $CYRUS_SASL_VERSION (authentication for AWS MSK) - bundled"
530
+ log " ✅ Static MIT Kerberos: $KRB5_VERSION (GSSAPI/Kerberos authentication) - bundled"
531
+ log " ✅ Static zlib: $ZLIB_VERSION (compression) - bundled"
532
+ log " ✅ Static ZStd: $ZSTD_VERSION (high-performance compression) - bundled"
533
+ log ""
534
+ log "🎯 Ready for deployment on macOS systems"
535
+ log "☁️ Compatible with AWS MSK and other secured Kafka clusters"
536
+ log "🔐 Supply chain security: All dependencies cryptographically verified"
537
+ log "📦 Self-contained: Ready for Ruby FFI distribution"
538
+ log "🔑 Kerberos/GSSAPI support: Full feature parity with Linux build"
539
+ log ""
540
+ log "Location: $OUTPUT_DIR/librdkafka.dylib"
541
+ echo "🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉"
542
+
543
+ # Force final flush
544
+ sync
545
+
546
+ # Cleanup
547
+ cleanup_build_dir "$BUILD_DIR"
548
+
549
+ # Reset environment variables
550
+ unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
data/ext/librdkafka.so ADDED
Binary file
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdkafka
4
+ # This class serves as an abstract base class to represent handles within the Rdkafka module.
5
+ # As a subclass of `FFI::Struct`, this class provides a blueprint for other specific handle
6
+ # classes to inherit from, ensuring they adhere to a particular structure and behavior.
7
+ #
8
+ # Subclasses must define their own layout, and the layout must start with:
9
+ #
10
+ # layout :pending, :bool,
11
+ # :response, :int
12
+ class AbstractHandle < FFI::Struct
13
+ include Helpers::Time
14
+
15
+ # Registry for registering all the handles.
16
+ REGISTRY = {}
17
+ # Default wait timeout is 31 years
18
+ MAX_WAIT_TIMEOUT_FOREVER = 10_000_000_000
19
+
20
+ private_constant :MAX_WAIT_TIMEOUT_FOREVER
21
+
22
+ class << self
23
+ # Adds handle to the register
24
+ #
25
+ # @param handle [AbstractHandle] any handle we want to register
26
+ def register(handle)
27
+ address = handle.to_ptr.address
28
+ REGISTRY[address] = handle
29
+ end
30
+
31
+ # Removes handle from the register based on the handle address
32
+ #
33
+ # @param address [Integer] address of the registered handle we want to remove
34
+ def remove(address)
35
+ REGISTRY.delete(address)
36
+ end
37
+ end
38
+
39
+ def initialize
40
+ @mutex = Thread::Mutex.new
41
+ @resource = Thread::ConditionVariable.new
42
+
43
+ super
44
+ end
45
+
46
+ # Whether the handle is still pending.
47
+ #
48
+ # @return [Boolean]
49
+ def pending?
50
+ self[:pending]
51
+ end
52
+
53
+ # Wait for the operation to complete or raise an error if this takes longer than the timeout.
54
+ # If there is a timeout this does not mean the operation failed, rdkafka might still be working
55
+ # on the operation. In this case it is possible to call wait again.
56
+ #
57
+ # @param max_wait_timeout [Numeric, nil] Amount of time to wait before timing out.
58
+ # If this is nil we will wait forever
59
+ # @param raise_response_error [Boolean] should we raise error when waiting finishes
60
+ #
61
+ # @return [Object] Operation-specific result
62
+ #
63
+ # @raise [RdkafkaError] When the operation failed
64
+ # @raise [WaitTimeoutError] When the timeout has been reached and the handle is still pending
65
+ def wait(max_wait_timeout: 60, raise_response_error: true)
66
+ timeout = max_wait_timeout ? monotonic_now + max_wait_timeout : MAX_WAIT_TIMEOUT_FOREVER
67
+
68
+ @mutex.synchronize do
69
+ loop do
70
+ if pending?
71
+ to_wait = (timeout - monotonic_now)
72
+
73
+ if to_wait.positive?
74
+ @resource.wait(@mutex, to_wait)
75
+ else
76
+ raise WaitTimeoutError.new(
77
+ "Waiting for #{operation_name} timed out after #{max_wait_timeout} seconds"
78
+ )
79
+ end
80
+ elsif self[:response] != 0 && raise_response_error
81
+ raise_error
82
+ else
83
+ return create_result
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ # Unlock the resources
90
+ def unlock
91
+ @mutex.synchronize do
92
+ self[:pending] = false
93
+ @resource.broadcast
94
+ end
95
+ end
96
+
97
+ # @return [String] the name of the operation (e.g. "delivery")
98
+ def operation_name
99
+ raise "Must be implemented by subclass!"
100
+ end
101
+
102
+ # @return [Object] operation-specific result
103
+ def create_result
104
+ raise "Must be implemented by subclass!"
105
+ end
106
+
107
+ # Allow subclasses to override
108
+ def raise_error
109
+ raise RdkafkaError.new(self[:response])
110
+ end
111
+
112
+ # Error that is raised when waiting for the handle to complete
113
+ # takes longer than the specified timeout.
114
+ class WaitTimeoutError < RuntimeError; end
115
+ end
116
+ end