From 8f85df081a842f6279f4c97000afc38a9fdc3bb7 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 14 Jul 2023 00:41:22 -0700 Subject: [PATCH] Add Windows and other cross-compilation targets 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 --- Rakefile | 13 ++++++++++++- ext/re2/extconf.rb | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index daee260..e942972 100644 --- a/Rakefile +++ b/Rakefile @@ -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 @@ -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 diff --git a/ext/re2/extconf.rb b/ext/re2/extconf.rb index d05723f..8673902 100644 --- a/ext/re2/extconf.rb +++ b/ext/re2/extconf.rb @@ -114,6 +114,21 @@ def cmake_compile_flags(host) ] end +# By default, mini_portile2 might add an unnecessary option: +# 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 # @@ -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