Skip to content

Commit

Permalink
v0.13.1-offline-librdkafka
Browse files Browse the repository at this point in the history
  • Loading branch information
mensfeld committed Jul 11, 2024
1 parent d563ff6 commit b7bb7a4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.13.1 (2024-07-10)
- [Fix] Switch to local release of librdkafka to mitigate its unavailability.

# 0.13.0
* Support cooperative sticky partition assignment in the rebalance callback (methodmissing)
* Support both string and symbol header keys (ColinDKelley)
Expand Down
Binary file added dist/librdkafka_2.0.2.tar.gz
Binary file not shown.
79 changes: 53 additions & 26 deletions ext/Rakefile
Original file line number Diff line number Diff line change
@@ -1,40 +1,67 @@
# frozen_string_literal: true

require File.expand_path('../../lib/rdkafka/version', __FILE__)
require "mini_portile2"
require "fileutils"
require "open-uri"

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

# Use default homebrew openssl if we're on mac and the directory exists
# and each of flags is not empty
if recipe.host&.include?("darwin") && system("which brew &> /dev/null") && Dir.exist?("#{homebrew_prefix = %x(brew --prefix openssl).strip}")
ENV["CPPFLAGS"] = "-I#{homebrew_prefix}/include" unless ENV["CPPFLAGS"]
ENV["LDFLAGS"] = "-L#{homebrew_prefix}/lib" unless ENV["LDFLAGS"]
end
# Use default homebrew openssl if we're on mac and the directory exists
# and each of flags is not empty
if recipe.host&.include?("darwin") && system("which brew &> /dev/null") && Dir.exist?("#{homebrew_prefix = %x(brew --prefix openssl).strip}")
ENV["CPPFLAGS"] = "-I#{homebrew_prefix}/include" unless ENV["CPPFLAGS"]
ENV["LDFLAGS"] = "-L#{homebrew_prefix}/lib" unless ENV["LDFLAGS"]
end

releases = File.expand_path(File.join(File.dirname(__FILE__), '../dist'))

recipe.files << {
:url => "file://#{releases}/librdkafka_#{Rdkafka::LIBRDKAFKA_VERSION}.tar.gz",
:sha256 => Rdkafka::LIBRDKAFKA_SOURCE_SHA256
}
recipe.configure_options = ["--host=#{recipe.host}"]

# Disable using libc regex engine in favor of the embedded one
# The default regex engine of librdkafka does not always work exactly as most of the users
# would expect, hence this flag allows for changing it to the other one
if ENV.key?('RDKAFKA_DISABLE_REGEX_EXT')
recipe.configure_options << '--disable-regex-ext'
end

recipe.files << {
:url => "https://codeload.github.com/edenhill/librdkafka/tar.gz/v#{Rdkafka::LIBRDKAFKA_VERSION}",
:sha256 => Rdkafka::LIBRDKAFKA_SOURCE_SHA256
}
recipe.configure_options = ["--host=#{recipe.host}"]
recipe.cook
# Move dynamic library we're interested in
if recipe.host.include?('darwin')
from_extension = '1.dylib'
to_extension = 'dylib'
recipe.cook
# Move dynamic library we're interested in
if recipe.host.include?('darwin')
from_extension = '1.dylib'
to_extension = 'dylib'
else
from_extension = 'so.1'
to_extension = 'so'
end
lib_path = File.join(File.dirname(__FILE__), "ports/#{recipe.host}/librdkafka/#{Rdkafka::LIBRDKAFKA_VERSION}/lib/librdkafka.#{from_extension}")
FileUtils.mv(lib_path, File.join(File.dirname(__FILE__), "librdkafka.#{to_extension}"))
# Cleanup files created by miniportile we don't need in the gem
FileUtils.rm_rf File.join(File.dirname(__FILE__), "tmp")
FileUtils.rm_rf File.join(File.dirname(__FILE__), "ports")
else
from_extension = 'so.1'
to_extension = 'so'
# Otherwise, copy existing libraries to ./ext
if ENV['RDKAFKA_EXT_PATH'].nil? || ENV['RDKAFKA_EXT_PATH'].empty?
raise "RDKAFKA_EXT_PATH must be set in your nix config when running under nix"
end
files = [
File.join(ENV['RDKAFKA_EXT_PATH'], 'lib', 'librdkafka.dylib'),
File.join(ENV['RDKAFKA_EXT_PATH'], 'lib', 'librdkafka.so')
]
files.each { |ext| FileUtils.cp(ext, File.dirname(__FILE__)) if File.exist?(ext) }
end
lib_path = File.join(File.dirname(__FILE__), "ports/#{recipe.host}/librdkafka/#{Rdkafka::LIBRDKAFKA_VERSION}/lib/librdkafka.#{from_extension}")
FileUtils.mv(lib_path, File.join(File.dirname(__FILE__), "librdkafka.#{to_extension}"))
# Cleanup files created by miniportile we don't need in the gem
FileUtils.rm_rf File.join(File.dirname(__FILE__), "tmp")
FileUtils.rm_rf File.join(File.dirname(__FILE__), "ports")
end

task :clean do
Expand Down
2 changes: 1 addition & 1 deletion lib/rdkafka/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Rdkafka
VERSION = "0.13.0"
VERSION = "0.13.1"
LIBRDKAFKA_VERSION = "2.0.2"
LIBRDKAFKA_SOURCE_SHA256 = "f321bcb1e015a34114c83cf1aa7b99ee260236aab096b85c003170c90a47ca9d"
end

0 comments on commit b7bb7a4

Please sign in to comment.