Skip to content

Commit

Permalink
Add Windows and other cross-compilation targets
Browse files Browse the repository at this point in the history
Windows builds were previously failing because mini_portile2 adds an
unnecessary option to the `cmake` configure step.

This commit adds other targets:

-  arm-linux
-  arm64-darwin
-  x64-mingw-ucrt
-  x86-linux
-  x86-mingw32
  • Loading branch information
stanhu committed Jul 14, 2023
1 parent f0e2f35 commit 4a15480
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ end
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
Expand Down Expand Up @@ -56,7 +60,14 @@ namespace 'gem' do
# 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 = platform == 'x86_64-linux' ? '/usr/local/bin/cmake' : 'cmake'
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
Expand Down
16 changes: 16 additions & 0 deletions ext/re2/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ def cmake_compile_flags(host)
]
end

# By default, mini_portile2 might add an unnecessary options:
# https://github.com/flavorjones/mini_portile/blob/5084a2aeab12076f534cf0cabc81a4d5f84b5c25/lib/mini_portile2/mini_portile_cmake.rb#L17
def delete_cmake_generator_option!(options)
indices = []

options.each_with_index do |element, index|
if element == '-G' && index + 1 < options.length
indices << index
indices << index + 1
end
end

indices.reverse_each { |index| options.delete_at(index) }
end

#
# main
#
Expand Down Expand Up @@ -240,6 +255,7 @@ def process_recipe(name, version)
'-DCMAKE_INSTALL_LIBDIR=lib'
]
recipe.configure_options += cmake_compile_flags(recipe.host)
delete_cmake_generator_option!(recipe.configure_options)

yield recipe

Expand Down

0 comments on commit 4a15480

Please sign in to comment.