Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not consider platform gems as candidates when required_ruby_version is incompatible #5715

Closed
ianks opened this issue Jul 13, 2022 · 6 comments · Fixed by #5784
Closed

Comments

@ianks
Copy link
Collaborator

ianks commented Jul 13, 2022

Describe the problem as clearly as you can

When selecting a spec to use when a platform spec is available, currently Bundler will choose the platform matching gem even when it is not compatible with the required_ruby_version.

The consequences of this means that it's impossible to publish precompiled gems that fallback to compiling from source code on newer Ruby versions. At Shopify, this makes it so we have to use a bunch of hacks to test gems against ruby-head.

Here's a more concrete example of the issue:

it "can fallback to a source gem when platform gems are incompatible with current ruby version" do
  setup_multiplatform_gem_with_source_gem

  source = file_uri_for(gem_repo2)

  gemfile <<~G
    source "#{source}"

    gem "my-precompiled-gem"
  G

  # simulate lockfile which includes both a precompiled gem with:
  # - Gem the current platform (with imcompatible ruby version)
  # - A source gem with compatible ruby version
  lockfile <<-L
    GEM
      remote: #{source}/
      specs:
        my-precompiled-gem (3.0.0)
        my-precompiled-gem (3.0.0-#{Bundler.local_platform})

    PLATFORMS
      ruby
      #{Bundler.local_platform}

    DEPENDENCIES
      my-precompiled-gem

    BUNDLED WITH
        #{Bundler::VERSION}
  L

  expect { install_gemfile(gemfile) }.to_not raise_error
end

def setup_multiplatform_gem_with_source_gem
  build_repo2 do
    build_gem("my-precompiled-gem", "3.0.0")
    build_gem("my-precompiled-gem", "3.0.0") do |s| 
      s.platform = Bundler.local_platform

      # purposely unresolvable
      s.required_ruby_version = ">= 1000.0.0"
    end
  end
end

In the above test, Bundler should choose my-precompiled-gem (3.0.0). Today, it will pick my-precompiled-gem (3.0.0-#{Bundler.local_platform}) and simply raise an error in ensure_specs_are_compatible!.

cc: @flavorjones

@deivid-rodriguez
Copy link
Member

Right, yeah. I'll fix this.

@flavorjones
Copy link
Contributor

Some prior context on related/same issue: #4012

@deivid-rodriguez
Copy link
Member

Yes, I believe they are very similar issues but in that case it was a "resolution from scratch" issue, while in this case it's a "lockfile issue".

@deivid-rodriguez
Copy link
Member

#5784 should fix this!

@ianks
Copy link
Collaborator Author

ianks commented Aug 4, 2022

@deivid-rodriguez thank you so much! when do you think this patch will make it in a release?

@deivid-rodriguez
Copy link
Member

No problem, next week!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants