Skip to content

Commit

Permalink
Add fat binary gem support for ruby-3.1
Browse files Browse the repository at this point in the history
Ruby-3.1-x64 on Windows has a changed platform string "x64-mingw-ucrt" vc. "x64-mingw32".
Consequentally rake-compiler-dock has a new corresponding platform image.
See https://rubyinstaller.org/2021/12/31/rubyinstaller-3.1.0-1-released.html

Unfortunately the compiler triplet is still "x86_64-w64-mingw32" for both ruby platforms, although the compiled code isn't compatible.
Therefore we have to differ by RUBY_PLATFROM instead of the "host" string.
  • Loading branch information
larskanis committed Jan 1, 2022
1 parent 238bc49 commit 8d37543
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 38 deletions.
31 changes: 19 additions & 12 deletions .cross_rubies
@@ -1,21 +1,28 @@
3.0.0:i686-w64-mingw32
3.0.0:x86_64-w64-mingw32
3.0.0:i686-linux-gnu
3.0.0:x86_64-linux-gnu
3.1.0:x86-mingw32
3.1.0:x64-mingw-ucrt
3.1.0:x86-linux
3.1.0:x86_64-linux
3.1.0:x86_64-darwin
3.1.0:arm64-darwin
3.1.0:aarch64-linux
3.0.0:x86-mingw32
3.0.0:x64-mingw32
3.0.0:x86-linux
3.0.0:x86_64-linux
3.0.0:x86_64-darwin
3.0.0:arm64-darwin
3.0.0:aarch64-linux
2.7.0:i686-w64-mingw32
2.7.0:x86_64-w64-mingw32
2.7.0:i686-linux-gnu
2.7.0:x86_64-linux-gnu
2.7.0:x86-mingw32
2.7.0:x64-mingw32
2.7.0:x86-linux
2.7.0:x86_64-linux
2.7.0:x86_64-darwin
2.7.0:arm64-darwin
2.7.0:aarch64-linux
2.6.0:i686-w64-mingw32
2.6.0:x86_64-w64-mingw32
2.6.0:i686-linux-gnu
2.6.0:x86_64-linux-gnu
2.6.0:x86-mingw32
2.6.0:x64-mingw32
2.6.0:x86-linux
2.6.0:x86_64-linux
2.6.0:x86_64-darwin
2.6.0:arm64-darwin
2.6.0:aarch64-linux
13 changes: 8 additions & 5 deletions ext/nokogiri/extconf.rb
Expand Up @@ -176,7 +176,7 @@ def config_system_libraries?
end

def windows?
RbConfig::CONFIG["target_os"].match?(/mingw32|mswin/)
RbConfig::CONFIG["target_os"].match?(/mingw|mswin/)
end

def solaris?
Expand Down Expand Up @@ -413,10 +413,13 @@ def process_recipe(name, version, static_p, cross_p, cacheable_p = true)
end

MiniPortile.new(name, version).tap do |recipe|

def recipe.port_path
"#{@target}/#{RUBY_PLATFORM}/#{@name}/#{@version}"
end

recipe.target = File.join(PACKAGE_ROOT_DIR, "ports") if cacheable_p
# Prefer host_alias over host in order to use i586-mingw32msvc as
# correct compiler prefix for cross build, but use host if not set.
recipe.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
recipe.host = RbConfig::CONFIG["host"]
recipe.configure_options << "--libdir=#{File.join(recipe.path, "lib")}"

yield recipe
Expand Down Expand Up @@ -473,7 +476,7 @@ def process_recipe(name, version, static_p, cross_p, cacheable_p = true)
"#{key}=#{value.strip}"
end

checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{RUBY_PLATFORM}.installed"
if File.exist?(checkpoint) && !recipe.source_directory
message("Building Nokogiri with a packaged version of #{name}-#{version}.\n")
else
Expand Down
66 changes: 45 additions & 21 deletions rakelib/extensions.rake
Expand Up @@ -3,8 +3,9 @@
require "rbconfig"
require "shellwords"

CrossRuby = Struct.new(:version, :host) do
CrossRuby = Struct.new(:version, :platform) do
WINDOWS_PLATFORM_REGEX = /mingw|mswin/
MINGWUCRT_PLATFORM_REGEX = /mingw-ucrt/
MINGW32_PLATFORM_REGEX = /mingw32/
LINUX_PLATFORM_REGEX = /linux/
X86_LINUX_PLATFORM_REGEX = /x86.*linux/
Expand Down Expand Up @@ -40,42 +41,44 @@ CrossRuby = Struct.new(:version, :host) do
end
end

def platform
@platform ||= case host
when /\Ax86_64.*mingw32/
"x64-mingw32"
when /\Ai[3-6]86.*mingw32/
"x86-mingw32"
when /\Ax86_64.*linux/
"x86_64-linux"
when /\Ai[3-6]86.*linux/
"x86-linux"
when /\Aaarch64-linux/
def host
@host ||= case platform
when "x64-mingw-ucrt"
"x86_64-w64-mingw32"
when "x64-mingw32"
"x86_64-w64-mingw32"
when "x86-mingw32"
"i686-w64-mingw32"
when "x86_64-linux"
"x86_64-linux-gnu"
when "x86-linux"
"i686-linux-gnu"
when "aarch64-linux"
"aarch64-linux"
when /\Ax86_64-darwin/
when "x86_64-darwin"
"x86_64-darwin"
when /\Aarm64-darwin/
when "arm64-darwin"
"arm64-darwin"
else
raise "CrossRuby.platform: unsupported host: #{host}"
raise "CrossRuby.platform: unsupported platform: #{platform}"
end
end

def tool(name)
(@binutils_prefix ||= case platform
when "x64-mingw32"
when "x64-mingw-ucrt", "x64-mingw32"
"x86_64-w64-mingw32-"
when "x86-mingw32"
"i686-w64-mingw32-"
when "x86_64-linux"
"x86_64-redhat-linux-"
when "x86-linux"
"i686-redhat-linux-"
when /a.*64.*linux/
when "aarch64-linux"
"aarch64-linux-gnu-"
when /x86_64.*darwin/
when "x86_64-darwin"
"x86_64-apple-darwin-"
when /a.*64.*darwin/
when "arm64-darwin"
"aarch64-apple-darwin-"
else
raise "CrossRuby.tool: unmatched platform: #{platform}"
Expand All @@ -84,7 +87,7 @@ CrossRuby = Struct.new(:version, :host) do

def target_file_format
case platform
when "x64-mingw32"
when "x64-mingw-ucrt", "x64-mingw32"
"pei-x86-64"
when "x86-mingw32"
"pei-i386"
Expand Down Expand Up @@ -113,6 +116,8 @@ CrossRuby = Struct.new(:version, :host) do

def libruby_dll
case platform
when "x64-mingw-ucrt"
"x64-ucrt-ruby#{api_ver_suffix}.dll"
when "x64-mingw32"
"x64-msvcrt-ruby#{api_ver_suffix}.dll"
when "x86-mingw32"
Expand All @@ -133,6 +138,25 @@ CrossRuby = Struct.new(:version, :host) do
"advapi32.dll",
libruby_dll,
]
when MINGWUCRT_PLATFORM_REGEX
[
"kernel32.dll",
"ws2_32.dll",
"advapi32.dll",
"api-ms-win-crt-convert-l1-1-0.dll",
"api-ms-win-crt-environment-l1-1-0.dll",
"api-ms-win-crt-filesystem-l1-1-0.dll",
"api-ms-win-crt-heap-l1-1-0.dll",
"api-ms-win-crt-locale-l1-1-0.dll",
"api-ms-win-crt-math-l1-1-0.dll",
"api-ms-win-crt-private-l1-1-0.dll",
"api-ms-win-crt-runtime-l1-1-0.dll",
"api-ms-win-crt-stdio-l1-1-0.dll",
"api-ms-win-crt-string-l1-1-0.dll",
"api-ms-win-crt-time-l1-1-0.dll",
"api-ms-win-crt-utility-l1-1-0.dll",
libruby_dll,
]
when X86_LINUX_PLATFORM_REGEX
[
"libm.so.6",
Expand Down Expand Up @@ -282,7 +306,7 @@ namespace "gem" do
desc "build native gem for #{plat} platform"
task plat do
RakeCompilerDock.sh(<<~EOT, platform: plat)
rvm use 3.0 &&
rvm use 3.1.0 &&
gem install bundler --no-document &&
bundle &&
bundle exec rake gem:#{plat}:builder MAKE='nice make -j`nproc`'
Expand Down

0 comments on commit 8d37543

Please sign in to comment.