Skip to content

Commit

Permalink
Pare down cross-building configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mudge committed Apr 26, 2024
1 parent f6dbb1d commit 2bc782d
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 225 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/precompile-gem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true
- uses: actions/cache@v4
with:
path: ports/archives
key: archives-ubuntu-${{hashFiles('ext/re2/extconf.rb')}}
- run: |
docker run --rm -v "$(pwd):/re2" -w /re2 \
"ghcr.io/rake-compiler/rake-compiler-dock-image:1.5.0-mri-${{ inputs.platform }}" \
./scripts/test-gem-build gems ${{inputs.platform}}
key: archives-ubuntu-${{ hashFiles('ext/re2/extconf.rb') }}
- run: bundle exec rake gem:${{ inputs.platform }}
- uses: actions/upload-artifact@v4
with:
name: "cruby-${{inputs.platform}}-gem"
path: gems
name: "cruby-${{ inputs.platform }}-gem"
path: pkg/*.gem
70 changes: 34 additions & 36 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ jobs:
with:
ruby-version: "3.3"
bundler-cache: true
- run: ./scripts/test-gem-build gems ruby
- run: bundle exec rake gem
- uses: actions/upload-artifact@v4
with:
name: cruby-gem
path: gems
path: pkg/*.gem

precompile-aarch64-linux:
uses: ./.github/workflows/precompile-gem.yml
Expand Down Expand Up @@ -124,8 +124,8 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: cruby-gem
path: gems
- run: ./scripts/test-gem-install gems --enable-system-libraries
path: pkg
- run: ./scripts/test-gem-install --enable-system-libraries

test-ubuntu:
needs: "build-cruby-gem"
Expand All @@ -144,9 +144,8 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: cruby-gem
path: gems
- run: ./scripts/test-gem-install gems --${{ matrix.sys }}-system-libraries
shell: bash
path: pkg
- run: ./scripts/test-gem-install --${{ matrix.sys }}-system-libraries

test-macos:
needs: "build-cruby-gem"
Expand All @@ -165,9 +164,8 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: cruby-gem
path: gems
- run: ./scripts/test-gem-install gems --${{ matrix.sys }}-system-libraries
shell: bash
path: pkg
- run: ./scripts/test-gem-install --${{ matrix.sys }}-system-libraries

test-windows-2019:
needs: "build-cruby-gem"
Expand All @@ -186,8 +184,8 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: cruby-gem
path: gems
- run: ./scripts/test-gem-install gems --${{ matrix.sys }}-system-libraries
path: pkg
- run: ./scripts/test-gem-install --${{ matrix.sys }}-system-libraries
shell: bash

test-windows-2022:
Expand All @@ -207,8 +205,8 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: cruby-gem
path: gems
- run: ./scripts/test-gem-install gems --${{ matrix.sys }}-system-libraries
path: pkg
- run: ./scripts/test-gem-install --${{ matrix.sys }}-system-libraries
shell: bash

test-freebsd:
Expand All @@ -223,13 +221,13 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: cruby-gem
path: gems
path: pkg
- uses: vmactions/freebsd-vm@v1
with:
usesh: true
copyback: false
prepare: pkg install -y ruby devel/ruby-gems sysutils/rubygem-bundler devel/pkgconf devel/cmake shells/bash devel/re2
run: ./scripts/test-gem-install gems --${{ matrix.sys }}-system-libraries
run: ./scripts/test-gem-install --${{ matrix.sys }}-system-libraries

test-vendored-and-system:
needs: "build-cruby-gem"
Expand All @@ -246,10 +244,10 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: cruby-gem
path: gems
path: pkg
- name: "Link libre2 into Ruby's lib directory"
run: ln -s /usr/lib/x86_64-linux-gnu/libre2.so ${{ steps.setup-ruby.outputs.ruby-prefix }}/lib/libre2.so
- run: ./scripts/test-gem-install gems
- run: ./scripts/test-gem-install

test-precompiled-aarch64-linux:
needs: "precompile-aarch64-linux"
Expand All @@ -263,14 +261,14 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: cruby-aarch64-linux-gem
path: gems
path: pkg
- name: Enable execution of multi-architecture containers by QEMU
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- run: |
docker run --rm -v "$(pwd):/re2" -w /re2 \
--platform=linux/arm64/v8 \
ruby:${{matrix.ruby}} \
./scripts/test-gem-install ./gems
./scripts/test-gem-install
test-precompiled-arm-linux:
needs: "precompile-arm-linux"
Expand All @@ -284,14 +282,14 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: cruby-arm-linux-gem
path: gems
path: pkg
- name: enable execution of multi-architecture containers by qemu
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- run: |
docker run --rm -v "$(pwd):/re2" -w /re2 \
--platform=linux/arm/v7 \
ruby:${{matrix.ruby}} \
./scripts/test-gem-install ./gems
./scripts/test-gem-install
test-precompiled-x86-linux:
needs: "precompile-x86-linux"
Expand All @@ -305,14 +303,14 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: cruby-x86-linux-gem
path: gems
path: pkg
- name: Enable execution of multi-architecture containers by QEMU
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- run: |
docker run --rm -v "$(pwd):/re2" -w /re2 \
--platform=linux/386 \
ruby:${{matrix.ruby}} \
./scripts/test-gem-install ./gems
./scripts/test-gem-install
test-precompiled-x86_64-linux:
needs: "precompile-x86_64-linux"
Expand All @@ -329,8 +327,8 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: cruby-x86_64-linux-gem
path: gems
- run: ./scripts/test-gem-install gems
path: pkg
- run: ./scripts/test-gem-install

test-precompiled-arm64-darwin:
needs: "precompile-arm64-darwin"
Expand All @@ -347,8 +345,8 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: cruby-arm64-darwin-gem
path: gems
- run: ./scripts/test-gem-install gems
path: pkg
- run: ./scripts/test-gem-install

test-precompiled-x86_64-darwin:
needs: "precompile-x86_64-darwin"
Expand All @@ -365,8 +363,8 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: cruby-x86_64-darwin-gem
path: gems
- run: ./scripts/test-gem-install gems
path: pkg
- run: ./scripts/test-gem-install

test-precompiled-x64-mingw-ucrt:
needs: "precompile-x64-mingw-ucrt"
Expand All @@ -383,8 +381,8 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: cruby-x64-mingw-ucrt-gem
path: gems
- run: ./scripts/test-gem-install gems
path: pkg
- run: ./scripts/test-gem-install
shell: bash

test-precompiled-x64-mingw32:
Expand All @@ -402,8 +400,8 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: cruby-x64-mingw32-gem
path: gems
- run: ./scripts/test-gem-install gems
path: pkg
- run: ./scripts/test-gem-install
shell: bash

test-precompiled-x86_64-alpine:
Expand All @@ -420,6 +418,6 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: cruby-x86_64-linux-gem
path: gems
path: pkg
- run: apk add bash libstdc++ gcompat
- run: ./scripts/test-gem-install gems
- run: ./scripts/test-gem-install
104 changes: 19 additions & 85 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
# frozen_string_literal: true

require 'rake/extensiontask'
require 'rspec/core/rake_task'
require 'rake_compiler_dock'
require 'rspec/core/rake_task'
require 'yaml'

require_relative 'ext/re2/recipes'

CLEAN.include FileList['**/*{.o,.so,.dylib,.bundle}'],
FileList['**/extconf.h'],
FileList['**/Makefile'],
FileList['pkg/']

CLOBBER.include FileList['**/tmp'],
FileList['**/*.log'],
FileList['doc/**'],
FileList['tmp/']
CLOBBER.add("ports/*").exclude(%r{ports/archives$})
re2_gemspec = Gem::Specification.load('re2.gemspec')
dependencies = YAML.load_file(File.join(__dir__, 'dependencies.yml'))
re2_gemspec.files << "ports/archives/#{dependencies['abseil']['version']}.tar.gz"
re2_gemspec.files << "ports/archives/re2-#{dependencies['libre2']['version']}.tar.gz"

RE2_GEM_SPEC = Gem::Specification.load('re2.gemspec')

task :prepare do
puts "Preparing project for gem building..."
recipes = load_recipes
recipes.each { |recipe| recipe.download }
task :download do
load_recipes.each(&:download)
end

task gem: :prepare

Gem::PackageTask.new(RE2_GEM_SPEC) do |p|
p.need_zip = false
p.need_tar = false
end
task gem: :download

CROSS_RUBY_VERSIONS = %w[3.3.0 3.2.0 3.1.0 3.0.0 2.7.0 2.6.0].join(':')
CROSS_RUBY_PLATFORMS = %w[
cross_platforms = %w[
aarch64-linux
arm-linux
arm64-darwin
Expand All @@ -46,13 +30,15 @@ CROSS_RUBY_PLATFORMS = %w[
x86_64-linux
].freeze

ENV['RUBY_CC_VERSION'] = CROSS_RUBY_VERSIONS
ENV['RUBY_CC_VERSION'] = %w[3.3.0 3.2.0 3.1.0 3.0.0 2.7.0 2.6.0].join(':')

Rake::ExtensionTask.new('re2', RE2_GEM_SPEC) do |e|
Gem::PackageTask.new(re2_gemspec).define

Rake::ExtensionTask.new('re2', re2_gemspec) do |e|
e.cross_compile = true
e.cross_config_options << '--enable-cross-build'
e.config_options << '--disable-system-libraries'
e.cross_platform = CROSS_RUBY_PLATFORMS
e.cross_platform = cross_platforms
e.cross_compiling do |spec|
spec.files.reject! { |path| File.fnmatch?('ports/*', path) }
spec.dependencies.reject! { |dep| dep.name == 'mini_portile2' }
Expand All @@ -62,71 +48,19 @@ end
RSpec::Core::RakeTask.new(:spec)

namespace 'gem' do
def gem_builder(platform)
# use Task#invoke because the pkg/*gem task is defined at runtime
Rake::Task["native:#{platform}"].invoke
Rake::Task["pkg/#{RE2_GEM_SPEC.full_name}-#{Gem::Platform.new(platform)}.gem"].invoke
end

CROSS_RUBY_PLATFORMS.each do |platform|
# The Linux x86 image (ghcr.io/rake-compiler/rake-compiler-dock-image:1.3.0-mri-x86_64-linux)
# is based on CentOS 7 and has two versions of cmake installed:
# a 2.8 version in /usr/bin and a 3.25 in /usr/local/bin. The latter is needed by abseil.
cmake =
case platform
when 'x86_64-linux', 'x86-linux'
'/usr/local/bin/cmake'
else
'cmake'
end

cross_platforms.each do |platform|
desc "build native gem for #{platform} platform"
task platform do
RakeCompilerDock.sh <<~SCRIPT, platform: platform, verbose: true
gem install bundler --no-document &&
bundle &&
bundle exec rake gem:#{platform}:builder CMAKE=#{cmake}
bundle exec rake native:#{platform} gem PATH="/usr/local/bin:$PATH"
SCRIPT
end

namespace platform do
desc "build native gem for #{platform} platform (guest container)"
task 'builder' do
gem_builder(platform)
end
end
end

desc 'build all native gems'
multitask 'native' => CROSS_RUBY_PLATFORMS
end

def add_file_to_gem(relative_source_path)
dest_path = File.join(gem_build_path, relative_source_path)
dest_dir = File.dirname(dest_path)

mkdir_p dest_dir unless Dir.exist?(dest_dir)
rm_f dest_path if File.exist?(dest_path)
safe_ln relative_source_path, dest_path

RE2_GEM_SPEC.files << relative_source_path
end

def gem_build_path
File.join 'pkg', RE2_GEM_SPEC.full_name
end

def add_vendored_libraries
dependencies = YAML.load_file(File.join(File.dirname(__FILE__), 'dependencies.yml'))
abseil_archive = File.join('ports', 'archives', "#{dependencies['abseil']['version']}.tar.gz")
libre2_archive = File.join('ports', 'archives', "re2-#{dependencies['libre2']['version']}.tar.gz")

add_file_to_gem(abseil_archive)
add_file_to_gem(libre2_archive)
end

task gem_build_path do
add_vendored_libraries
end
task default: :spec

task default: [:compile, :spec]
CLEAN.add("lib/**/*.{o,so,bundle}", "pkg")
CLOBBER.add("ports")
Loading

0 comments on commit 2bc782d

Please sign in to comment.