@@ -58,6 +58,87 @@ def open_file_with_lock(path, &block)
5858 end
5959 end
6060
61+ require "rubygems/platform"
62+
63+ class Platform
64+ JAVA = Gem ::Platform . new ( "java" )
65+ MSWIN = Gem ::Platform . new ( "mswin32" )
66+ MSWIN64 = Gem ::Platform . new ( "mswin64" )
67+ MINGW = Gem ::Platform . new ( "x86-mingw32" )
68+ X64_MINGW = [ Gem ::Platform . new ( "x64-mingw32" ) ,
69+ Gem ::Platform . new ( "x64-mingw-ucrt" ) ] . freeze
70+ UNIVERSAL_MINGW = Gem ::Platform . new ( "universal-mingw" )
71+ WINDOWS = [ MSWIN , MSWIN64 , UNIVERSAL_MINGW ] . flatten . freeze
72+ X64_LINUX = Gem ::Platform . new ( "x86_64-linux" )
73+ X64_LINUX_MUSL = Gem ::Platform . new ( "x86_64-linux-musl" )
74+
75+ if X64_LINUX === X64_LINUX_MUSL
76+ remove_method :===
77+
78+ def ===( other )
79+ return nil unless Gem ::Platform === other
80+
81+ # universal-mingw32 matches x64-mingw-ucrt
82+ return true if ( @cpu == "universal" || other . cpu == "universal" ) &&
83+ @os . start_with? ( "mingw" ) && other . os . start_with? ( "mingw" )
84+
85+ # cpu
86+ ( [ nil , "universal" ] . include? ( @cpu ) || [ nil , "universal" ] . include? ( other . cpu ) || @cpu == other . cpu ||
87+ ( @cpu == "arm" && other . cpu . start_with? ( "armv" ) ) ) &&
88+
89+ # os
90+ @os == other . os &&
91+
92+ # version
93+ (
94+ ( @os != "linux" && ( @version . nil? || other . version . nil? ) ) ||
95+ ( @os == "linux" && ( normalized_linux_version_ext == other . normalized_linux_version_ext || [ "musl#{ @version } " , "musleabi#{ @version } " , "musleabihf#{ @version } " ] . include? ( other . version ) ) ) ||
96+ @version == other . version
97+ )
98+ end
99+
100+ # This is a copy of RubyGems 3.3.23 or higher `normalized_linux_method`.
101+ # Once only 3.3.23 is supported, we can use the method in RubyGems.
102+ def normalized_linux_version_ext
103+ return nil unless @version
104+
105+ without_gnu_nor_abi_modifiers = @version . sub ( /\A gnu/ , "" ) . sub ( /eabi(hf)?\Z / , "" )
106+ return nil if without_gnu_nor_abi_modifiers . empty?
107+
108+ without_gnu_nor_abi_modifiers
109+ end
110+ end
111+ end
112+
113+ Platform . singleton_class . module_eval do
114+ unless Platform . singleton_methods . include? ( :match_spec? )
115+ def match_spec? ( spec )
116+ match_gem? ( spec . platform , spec . name )
117+ end
118+
119+ def match_gem? ( platform , gem_name )
120+ match_platforms? ( platform , Gem . platforms )
121+ end
122+ end
123+
124+ match_platforms_defined = Gem ::Platform . respond_to? ( :match_platforms? , true )
125+
126+ if !match_platforms_defined || Gem ::Platform . send ( :match_platforms? , Gem ::Platform ::X64_LINUX_MUSL , [ Gem ::Platform ::X64_LINUX ] )
127+
128+ private
129+
130+ remove_method :match_platforms? if match_platforms_defined
131+
132+ def match_platforms? ( platform , platforms )
133+ platforms . any? do |local_platform |
134+ platform . nil? ||
135+ local_platform == platform ||
136+ ( local_platform != Gem ::Platform ::RUBY && platform =~ local_platform )
137+ end
138+ end
139+ end
140+ end
141+
61142 require "rubygems/specification"
62143
63144 # Can be removed once RubyGems 3.5.14 support is dropped
@@ -288,86 +369,6 @@ def matching_specs(platform_only = false)
288369 end
289370 end
290371
291- require "rubygems/platform"
292-
293- class Platform
294- JAVA = Gem ::Platform . new ( "java" )
295- MSWIN = Gem ::Platform . new ( "mswin32" )
296- MSWIN64 = Gem ::Platform . new ( "mswin64" )
297- MINGW = Gem ::Platform . new ( "x86-mingw32" )
298- X64_MINGW = [ Gem ::Platform . new ( "x64-mingw32" ) ,
299- Gem ::Platform . new ( "x64-mingw-ucrt" ) ] . freeze
300- WINDOWS = [ MSWIN , MSWIN64 , MINGW , X64_MINGW ] . flatten . freeze
301- X64_LINUX = Gem ::Platform . new ( "x86_64-linux" )
302- X64_LINUX_MUSL = Gem ::Platform . new ( "x86_64-linux-musl" )
303-
304- if X64_LINUX === X64_LINUX_MUSL
305- remove_method :===
306-
307- def ===( other )
308- return nil unless Gem ::Platform === other
309-
310- # universal-mingw32 matches x64-mingw-ucrt
311- return true if ( @cpu == "universal" || other . cpu == "universal" ) &&
312- @os . start_with? ( "mingw" ) && other . os . start_with? ( "mingw" )
313-
314- # cpu
315- ( [ nil , "universal" ] . include? ( @cpu ) || [ nil , "universal" ] . include? ( other . cpu ) || @cpu == other . cpu ||
316- ( @cpu == "arm" && other . cpu . start_with? ( "armv" ) ) ) &&
317-
318- # os
319- @os == other . os &&
320-
321- # version
322- (
323- ( @os != "linux" && ( @version . nil? || other . version . nil? ) ) ||
324- ( @os == "linux" && ( normalized_linux_version_ext == other . normalized_linux_version_ext || [ "musl#{ @version } " , "musleabi#{ @version } " , "musleabihf#{ @version } " ] . include? ( other . version ) ) ) ||
325- @version == other . version
326- )
327- end
328-
329- # This is a copy of RubyGems 3.3.23 or higher `normalized_linux_method`.
330- # Once only 3.3.23 is supported, we can use the method in RubyGems.
331- def normalized_linux_version_ext
332- return nil unless @version
333-
334- without_gnu_nor_abi_modifiers = @version . sub ( /\A gnu/ , "" ) . sub ( /eabi(hf)?\Z / , "" )
335- return nil if without_gnu_nor_abi_modifiers . empty?
336-
337- without_gnu_nor_abi_modifiers
338- end
339- end
340- end
341-
342- Platform . singleton_class . module_eval do
343- unless Platform . singleton_methods . include? ( :match_spec? )
344- def match_spec? ( spec )
345- match_gem? ( spec . platform , spec . name )
346- end
347-
348- def match_gem? ( platform , gem_name )
349- match_platforms? ( platform , Gem . platforms )
350- end
351- end
352-
353- match_platforms_defined = Gem ::Platform . respond_to? ( :match_platforms? , true )
354-
355- if !match_platforms_defined || Gem ::Platform . send ( :match_platforms? , Gem ::Platform ::X64_LINUX_MUSL , [ Gem ::Platform ::X64_LINUX ] )
356-
357- private
358-
359- remove_method :match_platforms? if match_platforms_defined
360-
361- def match_platforms? ( platform , platforms )
362- platforms . any? do |local_platform |
363- platform . nil? ||
364- local_platform == platform ||
365- ( local_platform != Gem ::Platform ::RUBY && platform =~ local_platform )
366- end
367- end
368- end
369- end
370-
371372 # On universal Rubies, resolve the "universal" arch to the real CPU arch, without changing the extension directory.
372373 class BasicSpecification
373374 if /^universal\. (?<arch>.*?)-/ =~ ( CROSS_COMPILING || RUBY_PLATFORM )
0 commit comments