File: Rakefile

package info (click to toggle)
ruby-re2 2.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,944 kB
  • sloc: ruby: 1,977; cpp: 1,183; makefile: 7
file content (98 lines) | stat: -rw-r--r-- 3,103 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# frozen_string_literal: true

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

require_relative 'ext/re2/recipes'

re2_gemspec = Gem::Specification.load('re2.gemspec')
abseil_recipe, re2_recipe = load_recipes

# Add Abseil and RE2's latest archives to the gem files. (Note these will be
# removed from the precompiled native gems.)
abseil_archive = File.join("ports/archives", File.basename(abseil_recipe.files[0][:url]))
re2_archive = File.join("ports/archives", File.basename(re2_recipe.files[0][:url]))

re2_gemspec.files << abseil_archive
re2_gemspec.files << re2_archive

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

RakeCompilerDock.set_ruby_cc_version("~> 3.1", "~> 4.0")

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_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)

begin
  require 'ruby_memcheck'
  require 'ruby_memcheck/rspec/rake_task'

  namespace :spec do
    RubyMemcheck::RSpec::RakeTask.new(valgrind: :compile)
  end
rescue LoadError
  # Only define the spec:valgrind task if ruby_memcheck is installed
end

namespace :gem do
  cross_platforms.each do |platform|

    # Compile each platform's native gem, packaging up the result. Note we add
    # /usr/local/bin to the PATH as it contains the newest version of CMake in
    # the rake-compiler-dock images.
    desc "Compile and build native gem for #{platform} platform"
    task platform do
      RakeCompilerDock.sh <<~SCRIPT, platform: platform, verbose: true
        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 &&
        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 &&
        sudo apt-get update &&
        sudo apt-get install -y cmake=3.22.2-0kitware1ubuntu20.04.1 cmake-data=3.22.2-0kitware1ubuntu20.04.1 &&
        gem install bundler --no-document &&
        bundle install &&
        bundle exec rake native:#{platform} pkg/#{re2_gemspec.full_name}-#{Gem::Platform.new(platform)}.gem PATH="/usr/local/bin:$PATH"
      SCRIPT
    end
  end
end

# Set up file tasks for Abseil and RE2's archives so they are automatically
# downloaded when required by the gem task.
file abseil_archive do
  abseil_recipe.download
end

file re2_archive do
  re2_recipe.download
end

task default: :spec

CLEAN.add("lib/**/*.{o,so,bundle}", "pkg")
CLOBBER.add("ports")