Skip to content

Commit 57247bc

Browse files
committed
use librdkafka offline
1 parent fd5a1c5 commit 57247bc

File tree

4 files changed

+57
-27
lines changed

4 files changed

+57
-27
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Rdkafka Changelog
22

3+
## 0.14.1 (2024-07-10)
4+
- [Fix] Switch to local release of librdkafka to mitigate its unavailability.
5+
36
## 0.14.0 (2023-11-21)
47
- [Enhancement] Add `raise_response_error` flag to the `Rdkafka::AbstractHandle`.
58
- [Enhancement] Allow for setting `statistics_callback` as nil to reset predefined settings configured by a different gem (mensfeld)

dist/librdkafka_2.2.0.tar.gz

4.14 MB
Binary file not shown.

ext/Rakefile

+53-26
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,67 @@
11
# frozen_string_literal: true
22

33
require File.expand_path('../../lib/rdkafka/version', __FILE__)
4-
require "mini_portile2"
54
require "fileutils"
65
require "open-uri"
76

87
task :default => :clean do
9-
# Download and compile librdkafka
10-
recipe = MiniPortile.new("librdkafka", Rdkafka::LIBRDKAFKA_VERSION)
8+
# For nix users, nix can't locate the file paths because the packages it's requiring aren't managed by the system but are
9+
# managed by nix itself, so using the normal file paths doesn't work for nix users.
10+
#
11+
# Mini_portile causes an issue because it's dependencies are downloaded on the fly and therefore don't exist/aren't
12+
# accessible in the nix environment
13+
if ENV.fetch('RDKAFKA_EXT_PATH', '').empty?
14+
# Download and compile librdkafka if RDKAFKA_EXT_PATH is not set
15+
require "mini_portile2"
16+
recipe = MiniPortile.new("librdkafka", Rdkafka::LIBRDKAFKA_VERSION)
1117

12-
# Use default homebrew openssl if we're on mac and the directory exists
13-
# and each of flags is not empty
14-
if recipe.host&.include?("darwin") && system("which brew &> /dev/null") && Dir.exist?("#{homebrew_prefix = %x(brew --prefix openssl).strip}")
15-
ENV["CPPFLAGS"] = "-I#{homebrew_prefix}/include" unless ENV["CPPFLAGS"]
16-
ENV["LDFLAGS"] = "-L#{homebrew_prefix}/lib" unless ENV["LDFLAGS"]
17-
end
18+
# Use default homebrew openssl if we're on mac and the directory exists
19+
# and each of flags is not empty
20+
if recipe.host&.include?("darwin") && system("which brew &> /dev/null") && Dir.exist?("#{homebrew_prefix = %x(brew --prefix openssl).strip}")
21+
ENV["CPPFLAGS"] = "-I#{homebrew_prefix}/include" unless ENV["CPPFLAGS"]
22+
ENV["LDFLAGS"] = "-L#{homebrew_prefix}/lib" unless ENV["LDFLAGS"]
23+
end
24+
25+
releases = File.expand_path(File.join(File.dirname(__FILE__), '../dist'))
26+
27+
recipe.files << {
28+
:url => "file://#{releases}/librdkafka_#{Rdkafka::LIBRDKAFKA_VERSION}.tar.gz",
29+
:sha256 => Rdkafka::LIBRDKAFKA_SOURCE_SHA256
30+
}
31+
recipe.configure_options = ["--host=#{recipe.host}"]
32+
33+
# Disable using libc regex engine in favor of the embedded one
34+
# The default regex engine of librdkafka does not always work exactly as most of the users
35+
# would expect, hence this flag allows for changing it to the other one
36+
if ENV.key?('RDKAFKA_DISABLE_REGEX_EXT')
37+
recipe.configure_options << '--disable-regex-ext'
38+
end
1839

19-
recipe.files << {
20-
:url => "https://codeload.github.com/confluentinc/librdkafka/tar.gz/v#{Rdkafka::LIBRDKAFKA_VERSION}",
21-
:sha256 => Rdkafka::LIBRDKAFKA_SOURCE_SHA256
22-
}
23-
recipe.configure_options = ["--host=#{recipe.host}"]
24-
recipe.cook
25-
# Move dynamic library we're interested in
26-
if recipe.host.include?('darwin')
27-
from_extension = '1.dylib'
28-
to_extension = 'dylib'
40+
recipe.cook
41+
# Move dynamic library we're interested in
42+
if recipe.host.include?('darwin')
43+
from_extension = '1.dylib'
44+
to_extension = 'dylib'
45+
else
46+
from_extension = 'so.1'
47+
to_extension = 'so'
48+
end
49+
lib_path = File.join(File.dirname(__FILE__), "ports/#{recipe.host}/librdkafka/#{Rdkafka::LIBRDKAFKA_VERSION}/lib/librdkafka.#{from_extension}")
50+
FileUtils.mv(lib_path, File.join(File.dirname(__FILE__), "librdkafka.#{to_extension}"))
51+
# Cleanup files created by miniportile we don't need in the gem
52+
FileUtils.rm_rf File.join(File.dirname(__FILE__), "tmp")
53+
FileUtils.rm_rf File.join(File.dirname(__FILE__), "ports")
2954
else
30-
from_extension = 'so.1'
31-
to_extension = 'so'
55+
# Otherwise, copy existing libraries to ./ext
56+
if ENV['RDKAFKA_EXT_PATH'].nil? || ENV['RDKAFKA_EXT_PATH'].empty?
57+
raise "RDKAFKA_EXT_PATH must be set in your nix config when running under nix"
58+
end
59+
files = [
60+
File.join(ENV['RDKAFKA_EXT_PATH'], 'lib', 'librdkafka.dylib'),
61+
File.join(ENV['RDKAFKA_EXT_PATH'], 'lib', 'librdkafka.so')
62+
]
63+
files.each { |ext| FileUtils.cp(ext, File.dirname(__FILE__)) if File.exist?(ext) }
3264
end
33-
lib_path = File.join(File.dirname(__FILE__), "ports/#{recipe.host}/librdkafka/#{Rdkafka::LIBRDKAFKA_VERSION}/lib/librdkafka.#{from_extension}")
34-
FileUtils.mv(lib_path, File.join(File.dirname(__FILE__), "librdkafka.#{to_extension}"))
35-
# Cleanup files created by miniportile we don't need in the gem
36-
FileUtils.rm_rf File.join(File.dirname(__FILE__), "tmp")
37-
FileUtils.rm_rf File.join(File.dirname(__FILE__), "ports")
3865
end
3966

4067
task :clean do

lib/rdkafka/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module Rdkafka
4-
VERSION = "0.14.0"
4+
VERSION = "0.14.1"
55
LIBRDKAFKA_VERSION = "2.2.0"
66
LIBRDKAFKA_SOURCE_SHA256 = "af9a820cbecbc64115629471df7c7cecd40403b6c34bfdbb9223152677a47226"
77
end

0 commit comments

Comments
 (0)