Debian Codegraph @

Rakefile

raw
1 # frozen_string_literal: true
2
3 require 'rake/extensiontask'
4 require 'rake_compiler_dock'
5 require 'rspec/core/rake_task'
6
7 require_relative 'ext/re2/recipes'
8
9 re2_gemspec = Gem::Specification.load('re2.gemspec')
10 abseil_recipe, re2_recipe = load_recipes
11
12 # Add Abseil and RE2's latest archives to the gem files. (Note these will be
13 # removed from the precompiled native gems.)
14 abseil_archive = File.join("ports/archives", File.basename(abseil_recipe.files[0][:url]))
15 re2_archive = File.join("ports/archives", File.basename(re2_recipe.files[0][:url]))
16
17 re2_gemspec.files << abseil_archive
18 re2_gemspec.files << re2_archive
19
20 cross_platforms = %w[
21 aarch64-linux-gnu
22 aarch64-linux-musl
23 arm-linux-gnu
24 arm-linux-musl
25 arm64-darwin
26 x64-mingw-ucrt
27 x86_64-darwin
28 x86_64-linux-gnu
29 x86_64-linux-musl
30 ].freeze
31
32 RakeCompilerDock.set_ruby_cc_version("~> 3.1", "~> 4.0")
33
34 Gem::PackageTask.new(re2_gemspec).define
35
36 Rake::ExtensionTask.new('re2', re2_gemspec) do |e|
37 e.cross_compile = true
38 e.cross_config_options << '--enable-cross-build'
39 e.config_options << '--disable-system-libraries'
40 e.cross_platform = cross_platforms
41 e.cross_compiling do |spec|
42 spec.files.reject! { |path| File.fnmatch?('ports/*', path) }
43 spec.dependencies.reject! { |dep| dep.name == 'mini_portile2' }
44 end
45 end
46
47 RSpec::Core::RakeTask.new(:spec)
48
49 begin
50 require 'ruby_memcheck'
51 require 'ruby_memcheck/rspec/rake_task'
52
53 namespace :spec do
54 RubyMemcheck::RSpec::RakeTask.new(valgrind: :compile)
55 end
56 rescue LoadError
57 # Only define the spec:valgrind task if ruby_memcheck is installed
58 end
59
60 namespace :gem do
61 cross_platforms.each do |platform|
62
63 # Compile each platform's native gem, packaging up the result. Note we add
64 # /usr/local/bin to the PATH as it contains the newest version of CMake in
65 # the rake-compiler-dock images.
66 desc "Compile and build native gem for #{platform} platform"
67 task platform do
68 RakeCompilerDock.sh <<~SCRIPT, platform: platform, verbose: true
69 wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null &&
70 echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ focal main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null &&
71 sudo apt-get update &&
72 sudo apt-get install -y cmake=3.22.2-0kitware1ubuntu20.04.1 cmake-data=3.22.2-0kitware1ubuntu20.04.1 &&
73 gem install bundler --no-document &&
74 bundle install &&
75 bundle exec rake native:#{platform} pkg/#{re2_gemspec.full_name}-#{Gem::Platform.new(platform)}.gem PATH="/usr/local/bin:$PATH"
76 SCRIPT
77 end
78 end
79 end
80
81 # Set up file tasks for Abseil and RE2's archives so they are automatically
82 # downloaded when required by the gem task.
83 file abseil_archive do
84 abseil_recipe.download
85 end
86
87 file re2_archive do
88 re2_recipe.download
89 end
90
91 task default: :spec
92
93 CLEAN.add("lib/**/*.{o,so,bundle}", "pkg")
94 CLOBBER.add("ports")