require File.expand_path('../../lib/rdkafka/version', __FILE__) require "mini_portile2" require "fileutils" task :default => :clean do # MiniPortile#download_file_http is a monkey patch that removes the download # progress indicator. This indicator relies on the 'Content Length' response # headers, which is not set by GitHub class MiniPortile def download_file_http(url, full_path, _count) filename = File.basename(full_path) with_tempfile(filename, full_path) do |temp_file| params = { 'Accept-Encoding' => 'identity' } OpenURI.open_uri(url, 'rb', params) do |io| temp_file.write(io.read) end output end end end # Download and compile librdkafka 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") && Dir.exist?("/usr/local/opt/openssl") ENV["CPPFLAGS"] = "-I/usr/local/opt/openssl/include" unless ENV["CPPFLAGS"] ENV["LDFLAGS"] = "-L/usr/local/opt/openssl/lib" unless ENV["LDFLAGS"] 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' 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") end task :clean do FileUtils.rm_f File.join(File.dirname(__FILE__), "librdkafka.dylib") 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 :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.configure_options = ["--host=#{recipe.host}","--enable-static", "--enable-zstd"] recipe.cook ext = recipe.host.include?("darwin") ? "dylib" : "so" lib = File.expand_path("ports/#{recipe.host}/librdkafka/#{version}/lib/librdkafka.#{ext}", __dir__) # Copy will copy the content, following any symlinks FileUtils.cp(lib, __dir__) end end