Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vendor re2 and abseil #67

Merged
merged 8 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 18 additions & 28 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ jobs:
- 2.5
- 2.4
- 2.3
- 2.2
- 2.1.9
libre2:
- version: "20150501"
soname: 0
Expand Down Expand Up @@ -55,41 +53,32 @@ jobs:
with:
ruby-version: "${{ matrix.ruby }}"
bundler-cache: true
- run: bundle exec rake compile -- --enable-system-libraries
- run: bundle exec rake

legacy:
name: Legacy Ruby ${{ matrix.ruby }} - libre2 ABI version ${{ matrix.libre2.soname }}
vendor:
name: Ruby ${{ matrix.ruby }} - vendored libre2 and abseil
runs-on: ubuntu-20.04
container:
image: "mudge/re2-ci:${{ matrix.ruby }}"
options: "--add-host rubygems.org:151.101.129.227 --add-host api.rubygems.org:151.101.129.227"
strategy:
matrix:
ruby:
- 1.8
- 1.9.1
- '2.0'
libre2:
- version: "20150501"
soname: 0
- version: "20200302"
soname: 1
- version: "20200303"
soname: 6
- version: "20200501"
soname: 7
- version: "20200706"
soname: 8
- version: "20201101"
soname: 9
- version: "20221201"
soname: 10
- '3.2'
- '3.1'
- '3.0'
- 2.7
- 2.6
- 2.5
- 2.4
- 2.3
steps:
- uses: actions/checkout@v3
- name: Download and install specific release of libre2
- name: Install build dependencies
run: |
curl -Lo libre2-dev.deb https://github.com/mudge/re2-ci/releases/download/v1/libre2-dev_${{ matrix.libre2.version }}_amd64.deb
dpkg -i libre2-dev.deb
sudo apt-get install -y build-essential cmake
- uses: ruby/setup-ruby@v1
with:
ruby-version: "${{ matrix.ruby }}"
bundler-cache: true
- name: Configure Bundler for Ruby dependencies
run: bundle config --local path vendor/bundle
- name: Generate Gemfile.lock
Expand All @@ -100,4 +89,5 @@ jobs:
path: vendor/bundle
key: gems-v1-${{ runner.os }}-${{ matrix.ruby }}-${{ hashFiles('Gemfile.lock') }}
- run: bundle install --jobs 4
- run: bundle exec rake compile -- --disable-system-libraries
- run: bundle exec rake
115 changes: 113 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,121 @@
# frozen_string_literal: true

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

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_GEM_SPEC = Gem::Specification.load('re2.gemspec')

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

Rake::ExtensionTask.new('re2')
CROSS_RUBY_VERSIONS = %w[3.2.0 3.1.0 3.0.0 2.7.0].join(':')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to support all the way to Ruby 2.3.0? I'm inclined to keep it at 2.7.0 and set the gemspec to:

spec.required_ruby_version = ">= 2.7.0", 

That way no one can accidentally install a precompiled gem with the wrong Ruby version.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no way for us to only ship precompiled binaries for 2.7+ while still supporting system libraries for Rubies older than that then I'm happy to follow @flavorjones' lead with nokogiri and sqlite3 and set the required Ruby for the whole gem to match.

CROSS_RUBY_PLATFORMS = %w[
aarch64-linux
arm-linux
arm64-darwin
x64-mingw-ucrt
x86-linux
x86-mingw32
x86_64-darwin
x86_64-linux
].freeze

ENV['RUBY_CC_VERSION'] = CROSS_RUBY_VERSIONS

Rake::ExtensionTask.new('re2', RE2_GEM_SPEC) 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_compiling do |spec|
spec.files.reject! { |path| File.fnmatch?('ports/*', path) }
spec.dependencies.reject! { |dep| dep.name == 'mini_portile2' }
end
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

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}
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'
task '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 :spec => :compile
task :default => :spec

9 changes: 9 additions & 0 deletions dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
libre2:
version: "2023-07-01"
sha256: "18cf85922e27fad3ed9c96a27733037da445f35eb1a2744c306a37c6d11e95c4"
# sha-256 hash provided in https://github.com/google/re2/releases/download/2023-07-01/re2-2023-07-01.tar.gz

abseil:
version: "20230125.3"
sha256: 5366d7e7fa7ba0d915014d387b66d0d002c03236448e1ba9ef98122c13b35c36
# sha-256 hash provided in https://github.com/abseil/abseil-cpp/archive/refs/tags/20230125.3.tar.gz
Loading