Workaround macOS system Ruby issue picking incorrect native gem archs

This commit is contained in:
Bo Anderson 2022-10-08 18:57:40 +01:00
parent 6858e215dd
commit a776d5f02b
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65
4 changed files with 41 additions and 1 deletions

View File

@ -0,0 +1,20 @@
# typed: strict
# frozen_string_literal: true
require "etc"
# Fixes universal-ruby getting confused whether to install arm64 or x86_64 macOS versions.
# https://github.com/rubygems/rubygems/issues/4234
# This can be removed when either:
# - We stop using system Ruby
# - System Ruby is updated with this patch (shipped with Ruby 3.1 or later):
# https://github.com/ruby/ruby/commit/96ce1d9a0ff64494753ad4730f36a0cd7e7a89e7
# - The Rubygems PR https://github.com/rubygems/rubygems/pull/4238 is merged
# AND we install a new enough Rubygems which includes the said patch, instead of relying the system's version.
platform = Gem::Platform.local.dup
platform.cpu = Etc.uname[:machine] if platform.os == "darwin" && platform.cpu == "universal"
Gem.platforms[Gem.platforms.index(Gem::Platform.local)] = platform
# This doesn't currently exist in system Ruby but it's safer to check.
orig_file = File.join(RbConfig::CONFIG["rubylibdir"], "rubygems", "defaults", "operating_system")
require orig_file if File.exist?(orig_file)

View File

@ -0,0 +1,15 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
# Insert our system Ruby patch script, if neeeded.
# Fixes universal-ruby getting confused whether to install arm64 or x86_64 macOS versions.
# https://github.com/rubygems/rubygems/issues/4234
if RUBY_PLATFORM.match?(/universal\..*-darwin/)
rubylib = File.expand_path("../../rubyext", File.dirname(__FILE__))
ENV["RUBYLIB"] = rubylib
$LOAD_PATH.unshift(rubylib) unless $LOAD_PATH.include?(rubylib)
require "rubygems/defaults/operating_system" if defined?(Gem) # Reload if already loaded.
end
require "rubygems"
load Gem.activate_bin_path("bundler", "bundle", ">= 0.a")

View File

@ -263,7 +263,11 @@ module Homebrew
HOMEBREW_REPOSITORY/"Dockerfile", HOMEBREW_REPOSITORY/"Dockerfile",
*HOMEBREW_LIBRARY.glob("Homebrew/*.sh"), *HOMEBREW_LIBRARY.glob("Homebrew/*.sh"),
*HOMEBREW_LIBRARY.glob("Homebrew/shims/**/*").map(&:realpath).uniq *HOMEBREW_LIBRARY.glob("Homebrew/shims/**/*").map(&:realpath).uniq
.reject { |path| path.directory? || path.basename.to_s == "cc" }, .reject(&:directory?)
.reject { |path| path.basename.to_s == "cc" }
.select do |path|
%r{^#! ?/bin/(?:ba)?sh( |$)}.match?(path.read(13)) || path.extname == ".sh"
end,
*HOMEBREW_LIBRARY.glob("Homebrew/{dev-,}cmd/*.sh"), *HOMEBREW_LIBRARY.glob("Homebrew/{dev-,}cmd/*.sh"),
*HOMEBREW_LIBRARY.glob("Homebrew/{cask/,}utils/*.sh"), *HOMEBREW_LIBRARY.glob("Homebrew/{cask/,}utils/*.sh"),
] ]

View File

@ -60,6 +60,7 @@ module Homebrew
paths = ENV.fetch("PATH").split(":") paths = ENV.fetch("PATH").split(":")
paths.unshift(ruby_bindir) unless paths.include?(ruby_bindir) paths.unshift(ruby_bindir) unless paths.include?(ruby_bindir)
paths.unshift(Gem.bindir) unless paths.include?(Gem.bindir) paths.unshift(Gem.bindir) unless paths.include?(Gem.bindir)
paths.unshift(HOMEBREW_SHIMS_PATH/"ruby") unless paths.include?(HOMEBREW_SHIMS_PATH/"ruby")
ENV["PATH"] = paths.compact.join(":") ENV["PATH"] = paths.compact.join(":")
# Set envs so the above binaries can be invoked. # Set envs so the above binaries can be invoked.