From a07d3d36660a4c950181b5d350ace82e48d69f7c Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Thu, 2 Jan 2025 20:21:20 +0900 Subject: [PATCH 01/14] Support "windows" as an OS platform, and add matching for it. Needed for upcoming arm64-windows architecture. --- bundler/lib/bundler/rubygems_ext.rb | 3 ++- bundler/spec/commands/install_spec.rb | 11 +++++++++++ bundler/spec/support/platforms.rb | 8 ++++++-- lib/rubygems/platform.rb | 1 + 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/bundler/lib/bundler/rubygems_ext.rb b/bundler/lib/bundler/rubygems_ext.rb index bc7f65c7f7eb..9dddbb6c6e01 100644 --- a/bundler/lib/bundler/rubygems_ext.rb +++ b/bundler/lib/bundler/rubygems_ext.rb @@ -297,7 +297,8 @@ class Platform MINGW = Gem::Platform.new("x86-mingw32") X64_MINGW = [Gem::Platform.new("x64-mingw32"), Gem::Platform.new("x64-mingw-ucrt")].freeze - WINDOWS = [MSWIN, MSWIN64, MINGW, X64_MINGW].flatten.freeze + WINDOWS = [Gem::Platform.new("windows"), + MSWIN, MSWIN64, MINGW, X64_MINGW].flatten.freeze X64_LINUX = Gem::Platform.new("x86_64-linux") X64_LINUX_MUSL = Gem::Platform.new("x86_64-linux-musl") diff --git a/bundler/spec/commands/install_spec.rb b/bundler/spec/commands/install_spec.rb index 1c99a1877ae0..f7ae34e4556d 100644 --- a/bundler/spec/commands/install_spec.rb +++ b/bundler/spec/commands/install_spec.rb @@ -291,6 +291,17 @@ expect(the_bundle).to include_gems("platform_specific 1.0 x86-mswin32") end end + + it "installs gems for arm64-windows" do + simulate_platform arm64_windows do + install_gemfile <<-G + source "https://gem.repo1" + gem "platform_specific" + G + + expect(the_bundle).to include_gems("platform_specific 1.0 arm64-windows") + end + end end describe "doing bundle install foo" do diff --git a/bundler/spec/support/platforms.rb b/bundler/spec/support/platforms.rb index 526e1c09a9c0..792b30dc7baa 100644 --- a/bundler/spec/support/platforms.rb +++ b/bundler/spec/support/platforms.rb @@ -44,8 +44,12 @@ def x64_mingw_ucrt Gem::Platform.new(["x64", "mingw", "ucrt"]) end + def arm64_windows + Gem::Platform.new(["arm64", "windows", nil]) + end + def windows_platforms - [x86_mswin32, x64_mswin64, x86_mingw32, x64_mingw32, x64_mingw_ucrt] + [x86_mswin32, x64_mswin64, x86_mingw32, x64_mingw32, x64_mingw_ucrt, arm64_windows] end def all_platforms @@ -59,7 +63,7 @@ def not_local def local_tag if RUBY_PLATFORM == "java" :jruby - elsif ["x64-mingw32", "x64-mingw-ucrt"].include?(RUBY_PLATFORM) + elsif RUBY_PLATFORM.match?(/windows|mingw|mswin/) :windows else :ruby diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb index 450c2141676e..c6a3f3c3f83a 100644 --- a/lib/rubygems/platform.rb +++ b/lib/rubygems/platform.rb @@ -125,6 +125,7 @@ def initialize(arch) when /^dotnet$/ then ["dotnet", nil] when /^dotnet([\d.]*)/ then ["dotnet", $1] when /linux-?(\w+)?/ then ["linux", $1] + when /windows/ then ["windows", nil] when /mingw32/ then ["mingw32", nil] when /mingw-?(\w+)?/ then ["mingw", $1] when /(mswin\d+)(\_(\d+))?/ then From d420ffa894475c0354ea25431dce83a0713a3161 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Thu, 2 Jan 2025 20:26:17 +0900 Subject: [PATCH 02/14] Add version matcher for windows --- lib/rubygems/platform.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb index c6a3f3c3f83a..1a18ac46bbb6 100644 --- a/lib/rubygems/platform.rb +++ b/lib/rubygems/platform.rb @@ -125,7 +125,7 @@ def initialize(arch) when /^dotnet$/ then ["dotnet", nil] when /^dotnet([\d.]*)/ then ["dotnet", $1] when /linux-?(\w+)?/ then ["linux", $1] - when /windows/ then ["windows", nil] + when /windows-?(\w+)?/ then ["windows", $1] when /mingw32/ then ["mingw32", nil] when /mingw-?(\w+)?/ then ["mingw", $1] when /(mswin\d+)(\_(\d+))?/ then From e9131117b10df26a825ca7531bf6591f394611b0 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Thu, 2 Jan 2025 20:37:46 +0900 Subject: [PATCH 03/14] Add more tests --- bundler/spec/runtime/platform_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundler/spec/runtime/platform_spec.rb b/bundler/spec/runtime/platform_spec.rb index 007733d3deb7..9da9e4c03a16 100644 --- a/bundler/spec/runtime/platform_spec.rb +++ b/bundler/spec/runtime/platform_spec.rb @@ -438,7 +438,7 @@ end end - %w[x86-mswin32 x64-mswin64 x86-mingw32 x64-mingw32 x64-mingw-ucrt].each do |arch| + %w[arm64-windows arm64-windows-version x86-mswin32 x64-mswin64 x86-mingw32 x64-mingw32 x64-mingw-ucrt].each do |arch| it "allows specifying platform windows on #{arch} arch" do platform = send(arch.tr("-", "_")) From cc3f47e924dbb5c1667e9eb147ebe42be6ec440f Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Thu, 2 Jan 2025 20:48:12 +0900 Subject: [PATCH 04/14] Use actual example --- bundler/spec/runtime/platform_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundler/spec/runtime/platform_spec.rb b/bundler/spec/runtime/platform_spec.rb index 9da9e4c03a16..54a6ec461703 100644 --- a/bundler/spec/runtime/platform_spec.rb +++ b/bundler/spec/runtime/platform_spec.rb @@ -438,7 +438,7 @@ end end - %w[arm64-windows arm64-windows-version x86-mswin32 x64-mswin64 x86-mingw32 x64-mingw32 x64-mingw-ucrt].each do |arch| + %w[arm64-windows arm64-windows-ucrt x86-mswin32 x64-mswin64 x86-mingw32 x64-mingw32 x64-mingw-ucrt].each do |arch| it "allows specifying platform windows on #{arch} arch" do platform = send(arch.tr("-", "_")) From 6cb17a110682628494a97a19c29182325daf4fb0 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Thu, 2 Jan 2025 21:06:06 +0900 Subject: [PATCH 05/14] Fix test --- bundler/spec/commands/install_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundler/spec/commands/install_spec.rb b/bundler/spec/commands/install_spec.rb index b0da48ade156..a1344769b013 100644 --- a/bundler/spec/commands/install_spec.rb +++ b/bundler/spec/commands/install_spec.rb @@ -293,7 +293,7 @@ end it "installs gems for aarch64-mingw-ucrt" do - simulate_platform aarch64_windows_ucrt do + simulate_platform aarch64_mingw_ucrt do install_gemfile <<-G source "https://gem.repo1" gem "platform_specific" From e3e047cb121bf8256f6b8ed6b33a713720ef003e Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Thu, 2 Jan 2025 22:01:21 +0900 Subject: [PATCH 06/14] Fix specs --- bundler/spec/support/builders.rb | 8 ++++++++ bundler/spec/support/platforms.rb | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/bundler/spec/support/builders.rb b/bundler/spec/support/builders.rb index 340b3f5dd9fe..73e1a1306a09 100644 --- a/bundler/spec/support/builders.rb +++ b/bundler/spec/support/builders.rb @@ -118,6 +118,14 @@ def build_repo1 s.platform = "x64-mingw-ucrt" end + build_gem "platform_specific" do |s| + s.platform = "aarch64-mingw" + end + + build_gem "platform_specific" do |s| + s.platform = "aarch64-mingw-ucrt" + end + build_gem "platform_specific" do |s| s.platform = "x86-darwin-100" end diff --git a/bundler/spec/support/platforms.rb b/bundler/spec/support/platforms.rb index 663a10aba68c..b2f35e989ec2 100644 --- a/bundler/spec/support/platforms.rb +++ b/bundler/spec/support/platforms.rb @@ -44,12 +44,16 @@ def x64_mingw_ucrt Gem::Platform.new(["x64", "mingw", "ucrt"]) end + def aarch64_mingw + Gem::Platform.new(["aarch64", "mingw", nil]) + end + def aarch64_mingw_ucrt - Gem::Platform.new(["arm64", "mingw", "ucrt"]) + Gem::Platform.new(["aarch64", "mingw", "ucrt"]) end def windows_platforms - [x86_mswin32, x64_mswin64, x86_mingw32, x64_mingw32, x64_mingw_ucrt, aarch64_mingw_ucrt] + [x86_mswin32, x64_mswin64, x86_mingw32, x64_mingw32, x64_mingw_ucrt, aarch64_mingw, aarch64_mingw_ucrt] end def all_platforms From 3ba3fe1ead607fd4d94dd78616c97c8b84e6b6f7 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Thu, 2 Jan 2025 22:53:04 +0900 Subject: [PATCH 07/14] Make mingw a generic platform --- bundler/lib/bundler/gem_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundler/lib/bundler/gem_helpers.rb b/bundler/lib/bundler/gem_helpers.rb index 75243873f26c..25da0b14d2f6 100644 --- a/bundler/lib/bundler/gem_helpers.rb +++ b/bundler/lib/bundler/gem_helpers.rb @@ -10,8 +10,8 @@ module GemHelpers [Gem::Platform.new("universal-mingw32"), Gem::Platform.new("universal-mingw32")], [Gem::Platform.new("x64-mingw32"), Gem::Platform.new("x64-mingw32")], [Gem::Platform.new("x86_64-mingw32"), Gem::Platform.new("x64-mingw32")], - [Gem::Platform.new("x64-mingw-ucrt"), Gem::Platform.new("x64-mingw-ucrt")], [Gem::Platform.new("mingw32"), Gem::Platform.new("x86-mingw32")], + [Gem::Platform.new("mingw"), Gem::Platform.new("mingw")], ].freeze def generic(p) From df9473e0254978c98ea55c5dd6128cb5a2bf4a22 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Thu, 2 Jan 2025 23:15:59 +0900 Subject: [PATCH 08/14] Make mingw generic --- bundler/spec/other/ext_spec.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bundler/spec/other/ext_spec.rb b/bundler/spec/other/ext_spec.rb index 9fc0414b4d33..71608f6c0e7c 100644 --- a/bundler/spec/other/ext_spec.rb +++ b/bundler/spec/other/ext_spec.rb @@ -45,8 +45,13 @@ expect(generic(pl("x86_64-mingw32"))).to eq(pl("x64-mingw32")) end - it "converts 64-bit mingw UCRT platform variants into x64-mingw-ucrt" do - expect(generic(pl("x64-mingw-ucrt"))).to eq(pl("x64-mingw-ucrt")) + it "converts 64-bit mingw UCRT platform variants into mingw" do + expect(generic(pl("x64-mingw-ucrt"))).to eq(pl("mingw")) + end + + it "converts aarch64 mingw platform variants into mingw" do + expect(generic(pl("aarch64-mingw"))).to eq(pl("mingw")) + expect(generic(pl("aarch64-mingw-ucrt"))).to eq(pl("mingw")) end end From e72ada1575854966571092ff21ae1108006724d8 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Thu, 2 Jan 2025 23:36:16 +0900 Subject: [PATCH 09/14] Add additional spec --- bundler/spec/runtime/platform_spec.rb | 34 ++++++++++++++++++++++++++- bundler/spec/support/builders.rb | 4 ---- bundler/spec/support/platforms.rb | 6 +---- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/bundler/spec/runtime/platform_spec.rb b/bundler/spec/runtime/platform_spec.rb index 3ca29cd0f372..e455dedf6deb 100644 --- a/bundler/spec/runtime/platform_spec.rb +++ b/bundler/spec/runtime/platform_spec.rb @@ -438,7 +438,7 @@ end end - %w[aarch64-mingw aarch64-mingw-ucrt x86-mswin32 x64-mswin64 x86-mingw32 x64-mingw32 x64-mingw-ucrt].each do |arch| + %w[aarch64-mingw-ucrt x86-mswin32 x64-mswin64 x86-mingw32 x64-mingw32 x64-mingw-ucrt].each do |arch| it "allows specifying platform windows on #{arch} arch" do platform = send(arch.tr("-", "_")) @@ -469,4 +469,36 @@ end end end + + %w[aarch64-mingw x64-mingw x64-mingw-foobar].each do |arch| + it "does not find platform-specific gems on #{arch} arch" do + platform = Gem::Platform.new(arch) + + simulate_windows platform do + lockfile <<-L + GEM + remote: https://gem.repo1/ + specs: + platform_specific (1.0-#{platform}) + requires_platform_specific (1.0) + platform_specific + + PLATFORMS + #{platform} + + DEPENDENCIES + requires_platform_specific + L + + install_gemfile <<-G + source "https://gem.repo1" + gem "platform_specific", :platforms => [:windows] + G + + bundle "install" + + expect(the_bundle).to_not include_gems "platform_specific 1.0 #{platform}" + end + end + end end diff --git a/bundler/spec/support/builders.rb b/bundler/spec/support/builders.rb index 73e1a1306a09..0cbea697805b 100644 --- a/bundler/spec/support/builders.rb +++ b/bundler/spec/support/builders.rb @@ -118,10 +118,6 @@ def build_repo1 s.platform = "x64-mingw-ucrt" end - build_gem "platform_specific" do |s| - s.platform = "aarch64-mingw" - end - build_gem "platform_specific" do |s| s.platform = "aarch64-mingw-ucrt" end diff --git a/bundler/spec/support/platforms.rb b/bundler/spec/support/platforms.rb index b2f35e989ec2..3101a7ec988e 100644 --- a/bundler/spec/support/platforms.rb +++ b/bundler/spec/support/platforms.rb @@ -44,16 +44,12 @@ def x64_mingw_ucrt Gem::Platform.new(["x64", "mingw", "ucrt"]) end - def aarch64_mingw - Gem::Platform.new(["aarch64", "mingw", nil]) - end - def aarch64_mingw_ucrt Gem::Platform.new(["aarch64", "mingw", "ucrt"]) end def windows_platforms - [x86_mswin32, x64_mswin64, x86_mingw32, x64_mingw32, x64_mingw_ucrt, aarch64_mingw, aarch64_mingw_ucrt] + [x86_mswin32, x64_mswin64, x86_mingw32, x64_mingw32, x64_mingw_ucrt, aarch64_mingw_ucrt] end def all_platforms From 9160b3f849fb8574969652add8a9a5d324927306 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Fri, 3 Jan 2025 00:06:30 +0900 Subject: [PATCH 10/14] Fix specs --- bundler/spec/runtime/platform_spec.rb | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/bundler/spec/runtime/platform_spec.rb b/bundler/spec/runtime/platform_spec.rb index e455dedf6deb..1b503dfb9ce8 100644 --- a/bundler/spec/runtime/platform_spec.rb +++ b/bundler/spec/runtime/platform_spec.rb @@ -476,28 +476,16 @@ simulate_windows platform do lockfile <<-L - GEM - remote: https://gem.repo1/ - specs: - platform_specific (1.0-#{platform}) - requires_platform_specific (1.0) - platform_specific - PLATFORMS #{platform} - - DEPENDENCIES - requires_platform_specific L - install_gemfile <<-G - source "https://gem.repo1" - gem "platform_specific", :platforms => [:windows] - G - - bundle "install" - - expect(the_bundle).to_not include_gems "platform_specific 1.0 #{platform}" + expect do + install_gemfile <<-G + source "https://gem.repo1" + gem "platform_specific", :platforms => [:windows] + G + end.to raise_error(RuntimeError, /Could not find gem 'platform_specific windows' in rubygems repository/) end end end From b2c6b02b4445c5813cfe7c6ccaddd88dde47f295 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Fri, 3 Jan 2025 00:33:31 +0900 Subject: [PATCH 11/14] Fix spec --- bundler/spec/runtime/platform_spec.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bundler/spec/runtime/platform_spec.rb b/bundler/spec/runtime/platform_spec.rb index 1b503dfb9ce8..08767d7fe368 100644 --- a/bundler/spec/runtime/platform_spec.rb +++ b/bundler/spec/runtime/platform_spec.rb @@ -480,12 +480,14 @@ #{platform} L - expect do - install_gemfile <<-G - source "https://gem.repo1" - gem "platform_specific", :platforms => [:windows] - G - end.to raise_error(RuntimeError, /Could not find gem 'platform_specific windows' in rubygems repository/) + install_gemfile <<-G + source "https://gem.repo1" + gem "platform_specific", :platforms => [:windows] + G + + bundle "install" + + expect(the_bundle).to_not include_gems "platform_specific 1.0 #{platform}" end end end From 2849b1d2f526fe14ae0eef6f1380c039d348f751 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Fri, 3 Jan 2025 01:53:06 +0900 Subject: [PATCH 12/14] Fix spec --- bundler/spec/support/platforms.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundler/spec/support/platforms.rb b/bundler/spec/support/platforms.rb index 3101a7ec988e..16191ef89cf6 100644 --- a/bundler/spec/support/platforms.rb +++ b/bundler/spec/support/platforms.rb @@ -109,7 +109,7 @@ def lockfile_platforms(*extra, defaults: default_locked_platforms) end def default_locked_platforms - [local_platform, generic_local_platform] + [local_platform, generic_local_platform] - Gem::Platform.new("mingw") end end end From 01293fd855e0f65322bd40f6ecb54a7f4b384545 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Fri, 3 Jan 2025 07:20:52 +0900 Subject: [PATCH 13/14] Fix specs --- bundler/spec/support/platforms.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundler/spec/support/platforms.rb b/bundler/spec/support/platforms.rb index 16191ef89cf6..e3070dd2a444 100644 --- a/bundler/spec/support/platforms.rb +++ b/bundler/spec/support/platforms.rb @@ -109,7 +109,7 @@ def lockfile_platforms(*extra, defaults: default_locked_platforms) end def default_locked_platforms - [local_platform, generic_local_platform] - Gem::Platform.new("mingw") + [local_platform, generic_local_platform] - [Gem::Platform.new("mingw")] end end end From bf69dd063b04cf6efff4b32018bde0d18b2480de Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Fri, 3 Jan 2025 07:37:12 +0900 Subject: [PATCH 14/14] Add test for gem platform value --- test/rubygems/test_gem_platform.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/rubygems/test_gem_platform.rb b/test/rubygems/test_gem_platform.rb index 070c8007bc00..c95107f5d438 100644 --- a/test/rubygems/test_gem_platform.rb +++ b/test/rubygems/test_gem_platform.rb @@ -123,6 +123,7 @@ def test_initialize "i386-linux-gnu" => ["x86", "linux", "gnu"], "i386-mingw32" => ["x86", "mingw32", nil], "x64-mingw-ucrt" => ["x64", "mingw", "ucrt"], + "aarch64-mingw-ucrt" => ["aarch64", "mingw", "ucrt"], "i386-mswin32" => ["x86", "mswin32", nil], "i386-mswin32_80" => ["x86", "mswin32", "80"], "i386-mswin32-80" => ["x86", "mswin32", "80"],