Skip to content

Commit d607df7

Browse files
authored
reference and update librdkafka sources (#474)
1 parent ce2286c commit d607df7

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

ext/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# Ext
22

3-
This gem depends on the `librdkafka` C library. It is downloaded when
4-
this gem is installed.
3+
This gem depends on the `librdkafka` C library. It is downloaded, stored in
4+
`dist/` directory, and checked into source control.
55

66
To update the `librdkafka` version follow the following steps:
77

88
* Go to https://github.com/confluentinc/librdkafka/releases to get the new
99
version number and asset checksum for `tar.gz`.
1010
* Change the version in `lib/rdkafka/version.rb`
1111
* Change the `sha256` in `lib/rdkafka/version.rb`
12-
* Run `bundle exec rake` in the `ext` directory to download and build
13-
the new version
12+
* Run `bundle exec rake dist:download` in the `ext` directory to download the
13+
new release and place it in the `dist/` for you
14+
* Run `bundle exec rake` in the `ext` directory to build the new version
1415
* Run `docker-compose pull` in the main gem directory to ensure the docker
1516
images used by the tests and run `docker-compose up`
1617
* Finally, run `bundle exec rspec` in the main gem directory to execute

ext/Rakefile

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require File.expand_path('../../lib/rdkafka/version', __FILE__)
4+
require "digest"
45
require "fileutils"
56
require "open-uri"
67

@@ -71,14 +72,50 @@ task :clean do
7172
FileUtils.rm_rf File.join(File.dirname(__FILE__), "tmp")
7273
end
7374

75+
namespace :dist do
76+
task :dir do
77+
ENV["RDKAFKA_DIST_PATH"] ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'dist'))
78+
end
79+
80+
task :file => "dist:dir" do
81+
ENV["RDKAFKA_DIST_FILE"] ||= File.join(ENV["RDKAFKA_DIST_PATH"], "librdkafka_#{Rdkafka::LIBRDKAFKA_VERSION}.tar.gz")
82+
end
83+
84+
task :clean => "dist:file" do
85+
Dir.glob(File.join("#{ENV['RDKAFKA_DIST_PATH']}", "*")).each do |filename|
86+
next if filename.include? ENV["RDKAFKA_DIST_FILE"]
87+
88+
FileUtils.rm_rf filename
89+
end
90+
end
91+
92+
task :download => "dist:file" do
93+
version = Rdkafka::LIBRDKAFKA_VERSION
94+
librdkafka_download = "https://codeload.github.com/confluentinc/librdkafka/tar.gz/v#{version}"
95+
96+
URI.open(librdkafka_download) do |file|
97+
filename = ENV["RDKAFKA_DIST_FILE"]
98+
data = file.read
99+
100+
if Digest::SHA256.hexdigest(data) != Rdkafka::LIBRDKAFKA_SOURCE_SHA256
101+
raise "SHA256 does not match downloaded file"
102+
end
103+
104+
File.write(filename, data)
105+
end
106+
end
107+
108+
task :update => %w[dist:download dist:clean]
109+
end
110+
74111
namespace :build do
75112
desc "Build librdkafka at the given git sha or tag"
76113
task :git, [:ref] do |task, args|
77114
ref = args[:ref]
78115
version = "git-#{ref}"
79116

80117
recipe = MiniPortile.new("librdkafka", version)
81-
recipe.files << "https://github.com/edenhill/librdkafka/archive/#{ref}.tar.gz"
118+
recipe.files << "https://github.com/confluentinc/librdkafka/archive/#{ref}.tar.gz"
82119
recipe.configure_options = ["--host=#{recipe.host}","--enable-static", "--enable-zstd"]
83120
recipe.cook
84121

0 commit comments

Comments
 (0)