ext/Rakefile in rdkafka-0.16.1 vs ext/Rakefile in rdkafka-0.17.0
- old
+ new
@@ -1,8 +1,9 @@
# frozen_string_literal: true
require File.expand_path('../../lib/rdkafka/version', __FILE__)
+require "digest"
require "fileutils"
require "open-uri"
task :default => :clean do
# For nix users, nix can't locate the file paths because the packages it's requiring aren't managed by the system but are
@@ -28,10 +29,12 @@
:url => "file://#{releases}/librdkafka_#{Rdkafka::LIBRDKAFKA_VERSION}.tar.gz",
:sha256 => Rdkafka::LIBRDKAFKA_SOURCE_SHA256
}
recipe.configure_options = ["--host=#{recipe.host}"]
+ recipe.patch_files = Dir[File.join(releases, 'patches', "*.patch")].sort
+
# 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'
@@ -69,18 +72,55 @@
FileUtils.rm_f File.join(File.dirname(__FILE__), "librdkafka.so")
FileUtils.rm_rf File.join(File.dirname(__FILE__), "ports")
FileUtils.rm_rf File.join(File.dirname(__FILE__), "tmp")
end
+namespace :dist do
+ task :dir do
+ ENV["RDKAFKA_DIST_PATH"] ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'dist'))
+ end
+
+ task :file => "dist:dir" do
+ ENV["RDKAFKA_DIST_FILE"] ||= File.join(ENV["RDKAFKA_DIST_PATH"], "librdkafka_#{Rdkafka::LIBRDKAFKA_VERSION}.tar.gz")
+ end
+
+ task :clean => "dist:file" do
+ Dir.glob(File.join("#{ENV['RDKAFKA_DIST_PATH']}", "*")).each do |filename|
+ next if filename.include? ENV["RDKAFKA_DIST_FILE"]
+
+ FileUtils.rm_rf filename
+ end
+ end
+
+ task :download => "dist:file" do
+ version = Rdkafka::LIBRDKAFKA_VERSION
+ librdkafka_download = "https://codeload.github.com/confluentinc/librdkafka/tar.gz/v#{version}"
+
+ URI.open(librdkafka_download) do |file|
+ filename = ENV["RDKAFKA_DIST_FILE"]
+ data = file.read
+
+ if Digest::SHA256.hexdigest(data) != Rdkafka::LIBRDKAFKA_SOURCE_SHA256
+ raise "SHA256 does not match downloaded file"
+ end
+
+ File.write(filename, data)
+ end
+ end
+
+ task :update => %w[dist:download dist:clean]
+end
+
namespace :build do
desc "Build librdkafka at the given git sha or tag"
task :git, [:ref] do |task, args|
ref = args[:ref]
version = "git-#{ref}"
recipe = MiniPortile.new("librdkafka", version)
- recipe.files << "https://github.com/edenhill/librdkafka/archive/#{ref}.tar.gz"
+ recipe.files << "https://github.com/confluentinc/librdkafka/archive/#{ref}.tar.gz"
recipe.configure_options = ["--host=#{recipe.host}","--enable-static", "--enable-zstd"]
+ recipe.patch_files = Dir[File.join(releases, 'patches', "*.patch")].sort
recipe.cook
ext = recipe.host.include?("darwin") ? "dylib" : "so"
lib = File.expand_path("ports/#{recipe.host}/librdkafka/#{version}/lib/librdkafka.#{ext}", __dir__)