Skip to content

Commit

Permalink
Rakefile: extract cross-ruby tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Feb 29, 2020
1 parent 063b750 commit a265687
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 71 deletions.
71 changes: 0 additions & 71 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -143,77 +143,6 @@ Nokogiri is built with the packaged libraries: #{libs}.
end
end

# ----------------------------------------

def verify_dll(dll, cross_ruby)
dll_imports = cross_ruby.dlls
dump = `#{['env', 'LANG=C', cross_ruby.tool('objdump'), '-p', dll].shelljoin}`
if cross_ruby.windows?
raise "unexpected file format for generated dll #{dll}" unless /file format #{Regexp.quote(cross_ruby.target)}\s/ === dump
raise "export function Init_nokogiri not in dll #{dll}" unless /Table.*\sInit_nokogiri\s/mi === dump

# Verify that the expected DLL dependencies match the actual dependencies
# and that no further dependencies exist.
dll_imports_is = dump.scan(/DLL Name: (.*)$/).map(&:first).map(&:downcase).uniq
if dll_imports_is.sort != dll_imports.sort
raise "unexpected dll imports #{dll_imports_is.inspect} in #{dll}"
end
else
# Verify that the expected so dependencies match the actual dependencies
# and that no further dependencies exist.
dll_imports_is = dump.scan(/NEEDED\s+(.*)/).map(&:first).uniq
if dll_imports_is.sort != dll_imports.sort
raise "unexpected so imports #{dll_imports_is.inspect} in #{dll} (expected #{dll_imports.inspect})"
end

# Verify that the expected so version requirements match the actual dependencies.
dll_ref_versions_list = dump.scan(/0x[\da-f]+ 0x[\da-f]+ \d+ (\w+)_([\d\.]+)$/i)
# Build a hash of library versions like {"LIBUDEV"=>"183", "GLIBC"=>"2.17"}
dll_ref_versions_is = dll_ref_versions_list.each.with_object({}) do |(lib, ver), h|
if !h[lib] || ver.split(".").map(&:to_i).pack("C*") > h[lib].split(".").map(&:to_i).pack("C*")
h[lib] = ver
end
end
if dll_ref_versions_is != cross_ruby.dll_ref_versions
raise "unexpected so version requirements #{dll_ref_versions_is.inspect} in #{dll}"
end
end
puts "#{dll}: Looks good!"
end

CROSS_RUBIES.each do |cross_ruby|
task "tmp/#{cross_ruby.platform}/stage/lib/nokogiri/#{cross_ruby.minor_ver}/nokogiri.so" do |t|
verify_dll t.name, cross_ruby
end
end

namespace "gem" do
CROSS_RUBIES.map(&:platform).uniq.each do |plat|
desc "build native fat binary gems for windows and linux"
multitask "native" => plat

desc "build native gem for #{plat} platform"
task plat do
RakeCompilerDock.sh <<-EOT, platform: plat
gem install bundler &&
bundle &&
rake native:#{plat} pkg/#{HOE.spec.full_name}-#{plat}.gem MAKE='nice make -j`nproc`' RUBY_CC_VERSION=#{ENV['RUBY_CC_VERSION']}
EOT
end
end

desc "build native fat binary gems for windows"
multitask "windows" => CROSS_RUBIES.map(&:platform).uniq.grep(WINDOWS_PLATFORM_REGEX)

desc "build native fat binary gems for linux"
multitask "linux" => CROSS_RUBIES.map(&:platform).uniq.grep(LINUX_PLATFORM_REGEX)

desc "build a jruby gem with docker"
task "jruby" do
RakeCompilerDock.sh "gem install bundler && bundle && rake java gem", rubyvm: 'jruby'
end
end

require_relative "tasks/concourse"
require_relative "tasks/css-generate"
require_relative "tasks/debug"
Expand Down
69 changes: 69 additions & 0 deletions tasks/cross-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,72 @@ def dll_ref_versions
end

ENV["RUBY_CC_VERSION"] ||= CROSS_RUBIES.map(&:ver).uniq.join(":")

def verify_dll(dll, cross_ruby)
dll_imports = cross_ruby.dlls
dump = `#{["env", "LANG=C", cross_ruby.tool("objdump"), "-p", dll].shelljoin}`
if cross_ruby.windows?
raise "unexpected file format for generated dll #{dll}" unless /file format #{Regexp.quote(cross_ruby.target)}\s/ === dump
raise "export function Init_nokogiri not in dll #{dll}" unless /Table.*\sInit_nokogiri\s/mi === dump

# Verify that the expected DLL dependencies match the actual dependencies
# and that no further dependencies exist.
dll_imports_is = dump.scan(/DLL Name: (.*)$/).map(&:first).map(&:downcase).uniq
if dll_imports_is.sort != dll_imports.sort
raise "unexpected dll imports #{dll_imports_is.inspect} in #{dll}"
end
else
# Verify that the expected so dependencies match the actual dependencies
# and that no further dependencies exist.
dll_imports_is = dump.scan(/NEEDED\s+(.*)/).map(&:first).uniq
if dll_imports_is.sort != dll_imports.sort
raise "unexpected so imports #{dll_imports_is.inspect} in #{dll} (expected #{dll_imports.inspect})"
end

# Verify that the expected so version requirements match the actual dependencies.
dll_ref_versions_list = dump.scan(/0x[\da-f]+ 0x[\da-f]+ \d+ (\w+)_([\d\.]+)$/i)
# Build a hash of library versions like {"LIBUDEV"=>"183", "GLIBC"=>"2.17"}
dll_ref_versions_is = dll_ref_versions_list.each.with_object({}) do |(lib, ver), h|
if !h[lib] || ver.split(".").map(&:to_i).pack("C*") > h[lib].split(".").map(&:to_i).pack("C*")
h[lib] = ver
end
end
if dll_ref_versions_is != cross_ruby.dll_ref_versions
raise "unexpected so version requirements #{dll_ref_versions_is.inspect} in #{dll}"
end
end
puts "#{dll}: Looks good!"
end

CROSS_RUBIES.each do |cross_ruby|
task "tmp/#{cross_ruby.platform}/stage/lib/nokogiri/#{cross_ruby.minor_ver}/nokogiri.so" do |t|
verify_dll t.name, cross_ruby
end
end

namespace "gem" do
CROSS_RUBIES.map(&:platform).uniq.each do |plat|
desc "build native fat binary gems for windows and linux"
multitask "native" => plat

desc "build native gem for #{plat} platform"
task plat do
RakeCompilerDock.sh <<-EOT, platform: plat
gem install bundler --no-document &&
bundle &&
rake native:#{plat} pkg/#{HOE.spec.full_name}-#{plat}.gem MAKE='nice make -j`nproc`' RUBY_CC_VERSION=#{ENV["RUBY_CC_VERSION"]}
EOT
end
end

desc "build native fat binary gems for windows"
multitask "windows" => CROSS_RUBIES.map(&:platform).uniq.grep(WINDOWS_PLATFORM_REGEX)

desc "build native fat binary gems for linux"
multitask "linux" => CROSS_RUBIES.map(&:platform).uniq.grep(LINUX_PLATFORM_REGEX)

desc "build a jruby gem with docker"
task "jruby" do
RakeCompilerDock.sh "gem install bundler --no-document && bundle && rake java gem", rubyvm: "jruby"
end
end

0 comments on commit a265687

Please sign in to comment.