Skip to content

Commit

Permalink
fix: native gems are built with ExtensionTask.no_native=true
Browse files Browse the repository at this point in the history
Specifically, following the advice of @kou at

  rake-compiler/rake-compiler#171

we set `Rake::ExtensionTask.no_native=true` within the
rake-compiler-dock container ("guest") so that:

- the ExtensionTask `cross_compiling` block is called
  - so that we don't package the dependencies' tarballs in /ports
  - so that we don't have mini_portile2 as a dependency (#2078)
  - so that we don't have an extra nokogiri.so/nokogiri.bundle built
    and packaged (#2076)
- we no longer have to hotfix rake-compiler at build time

This also will enable us to more easily do things like removing the C
extension source code from the native gem package (#2077).
  • Loading branch information
flavorjones committed Dec 3, 2020
1 parent 48c9687 commit 17c84fc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
8 changes: 1 addition & 7 deletions concourse/tasks/gem-test/gem-build.sh
Expand Up @@ -25,13 +25,7 @@ bundle install --local || bundle install
bundle exec rake set-version-to-timestamp

if [ -n "${BUILD_NATIVE_GEM:-}" ] ; then
# TODO remove after https://github.com/rake-compiler/rake-compiler/pull/171 is shipped
find /usr/local/rvm/gems -name extensiontask.rb | while read f ; do
echo "rewriting $f"
sudo sed -i 's/callback.call(spec) if callback/@cross_compiling.call(spec) if @cross_compiling/' $f
done

bundle exec rake gem:x86_64-linux:guest
bundle exec rake gem:x86_64-linux:guest FORCE_CROSS_COMPILING=true
else
# TODO we're only compiling so that we retrieve libxml2/libxslt
# tarballs, we can do better a couple of different ways
Expand Down
6 changes: 2 additions & 4 deletions rakelib/cross-ruby.rake
Expand Up @@ -240,12 +240,10 @@ namespace "gem" do
CROSS_RUBIES.find_all { |cr| cr.windows? || cr.linux? }.map(&:platform).uniq.each do |plat|
desc "build native gem for #{plat} platform (host)"
task plat do
# TODO remove `find` after https://github.com/rake-compiler/rake-compiler/pull/171 is shipped
RakeCompilerDock.sh <<~EOT, platform: plat
gem install bundler --no-document &&
bundle &&
find /usr/local/rvm/gems -name extensiontask.rb | while read f ; do sudo sed -i 's/callback.call(spec) if callback/@cross_compiling.call(spec) if @cross_compiling/' $f ; done &&
rake gem:#{plat}:guest MAKE='nice make -j`nproc`'
rake gem:#{plat}:guest MAKE='nice make -j`nproc`' FORCE_CROSS_COMPILING=true
EOT
end

Expand All @@ -267,7 +265,6 @@ namespace "gem" do
CROSS_RUBIES.find_all { |cr| cr.darwin? }.map(&:platform).uniq.each do |plat|
desc "build native gem for #{plat} platform"
task plat do
sh "find ~/.gem -name extensiontask.rb | while read f ; do sed -i '' 's/callback.call(spec) if callback/@cross_compiling.call(spec) if @cross_compiling/' \$f ; done"
Rake::Task["native:#{plat}"].invoke
Rake::Task["pkg/#{HOE.spec.full_name}-#{Gem::Platform.new(plat).to_s}.gem"].invoke
end
Expand Down Expand Up @@ -328,6 +325,7 @@ else
Rake::ExtensionTask.new("nokogiri", HOE.spec) do |ext|
ext.lib_dir = File.join(*['lib', 'nokogiri', ENV['FAT_DIR']].compact)
ext.config_options << ENV['EXTOPTS']
ext.no_native = (ENV["FORCE_CROSS_COMPILING"] == "true")
ext.cross_compile = true
ext.cross_platform = CROSS_RUBIES.map(&:platform).uniq
ext.cross_config_options << "--enable-cross-build"
Expand Down

0 comments on commit 17c84fc

Please sign in to comment.