Merge pull request #14093 from Bo98/rubyext-upstream

rubyext: align workaround with upstream
This commit is contained in:
Bo Anderson 2022-11-05 01:40:53 +00:00 committed by GitHub
commit 5eae127553
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,19 +1,31 @@
# typed: strict # typed: false
# frozen_string_literal: true # frozen_string_literal: true
require "etc"
# Fixes universal-ruby getting confused whether to install arm64 or x86_64 macOS versions. # 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 integrated into Bundler: https://github.com/rubygems/rubygems/pull/5978
# This can be removed when either: module Gem
# - We stop using system Ruby # @private
# - System Ruby is updated with this patch (shipped with Ruby 3.1 or later): class Specification
# https://github.com/ruby/ruby/commit/96ce1d9a0ff64494753ad4730f36a0cd7e7a89e7 if /^universal\.(?<arch>.*?)-/ =~ (CROSS_COMPILING || RUBY_PLATFORM)
# - The Rubygems PR https://github.com/rubygems/rubygems/pull/4238 is merged local_platform = Platform.local
# AND we install a new enough Rubygems which includes the said patch, instead of relying the system's version. if local_platform.cpu == "universal"
platform = Gem::Platform.local.dup ORIGINAL_LOCAL_PLATFORM = local_platform.to_s.freeze
platform.cpu = Etc.uname[:machine] if platform.os == "darwin" && platform.cpu == "universal"
Gem.platforms[Gem.platforms.index(Gem::Platform.local)] = platform local_platform.cpu = if arch == "arm64e" # arm64e is only permitted for Apple system binaries
"arm64"
else
arch
end
def extensions_dir
Gem.default_ext_dir_for(base_dir) ||
File.join(base_dir, "extensions", ORIGINAL_LOCAL_PLATFORM,
Gem.extension_api_version)
end
end
end
end
end
# This doesn't currently exist in system Ruby but it's safer to check. # 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") orig_file = File.join(RbConfig::CONFIG["rubylibdir"], "rubygems", "defaults", "operating_system")