-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f396485
Vendor re2 and abseil
stanhu cb320ca
ci: drop support for Ruby 1.9 - 2.2
stanhu 13c1b50
ci: add jobs to test with --disable-system-libraries
stanhu cad0593
Make `rake gem` vendor libre2 and abseil tarballs
stanhu 26e68b7
Add support for building precompiled gems
stanhu f0e2f35
Make cross-compilation for native gems work
stanhu 8f85df0
Add Windows and other cross-compilation targets
stanhu ed95b46
Make --disable-system-libraries the default parameter
stanhu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(':') | ||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
That way no one can accidentally install a precompiled gem with the wrong Ruby version.
There was a problem hiding this comment.
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.