Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Bundler doesn't respect other than the native platform while resolving the gems to install #5337

Closed
larskanis opened this issue Jan 19, 2017 · 9 comments

Comments

@larskanis
Copy link
Contributor

larskanis commented Jan 19, 2017

Original issue is oneclick/rubyinstaller2#7 : Nokogiri installs successfully on RubyInstaller2 when --platform=ruby is used. There is also a fat binary gem for x86-mingw32, but it is limited to Ruby versions 2.0 to 2.3. It can not be installed on Ruby-2.4.0 due to this ruby version constraint, which is expected behavior. However bundler doesn't use the platform=ruby gem version as an alternative, regardless whether it is already installed or not.

Installed versions (with nokogiri installed as platform=ruby):

C:\Users\lars\railstest>ruby --version
ruby 2.4.0p0 (2016-12-24 revision 57164) [i386-mingw32]

C:\Users\lars\railstest>bundle --version
Bundler version 1.14.0.pre.2

C:\Users\lars\railstest>gem list nokogiri
*** LOCAL GEMS ***
nokogiri (1.7.0.1)

Using a fresh Rails-5.0.1 project (generated per rails new railstest) with this Gemfile .

When platform ruby is added per bundle lock, I would expect, that the installed version will be used. But instead an older nokogiri version (1.6.6.4) for x86-mingw32 is installed. This version doesn't work on Ruby-2.4, since it doesn't contain the Ruby-2.4 binary extension, but it wasn't labeled with proper ruby version constraints to that point in time:

C:\Users\lars\railstest>bundle lock --add-platform=ruby
Fetching gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Resolving dependencies........................................................................................................................................................................................................................................
Writing lockfile to C:/Users/lars/railstest/Gemfile.lock

C:\Users\lars\railstest>bundle
Fetching gem metadata from https://rubygems.org/.........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Using rake 12.0.0
[...]
Installing nokogiri 1.6.6.4 (x86-mingw32)
[...]
Bundle complete! 12 Gemfile dependencies, 56 gems now installed.

When the platform x86-mingw32 is explicit removed, the bundle install fails with a dependency issue - although the nokogiri gem is already locally installed in the latest version 1.7.0.1 :

C:\Users\lars\railstest>rm Gemfile.lock

C:\Users\lars\railstest>bundle lock --add-platform=ruby --remove-platform=x86-mingw32
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform mingw, mswin, x64_mingw, jruby`.
Fetching gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Resolving dependencies..............................................
Writing lockfile to C:/Users/lars/railstest/Gemfile.lock

C:\Users\lars\railstest>bundle
Fetching gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Resolving dependencies......
Bundler could not find compatible versions for gem "ruby ":
  In Gemfile:
    ruby

    ruby  x86-mingw32

    jquery-rails was resolved to 4.2.2, which depends on
      rails-dom-testing (< 3, >= 1) was resolved to 2.0.2, which depends on
        nokogiri (~> 1.6) was resolved to 1.7.0.1, which depends on
          ruby  (< 2.4) x86-mingw32

Could not find gem 'ruby  (< 2.4) x86-mingw32', which is required by gem
'nokogiri (~> 1.6)', in any of the sources.

C:\Users\lars\railstest>gem list nokogiri
*** LOCAL GEMS ***
nokogiri (1.7.0.1)

Is there a way to let bundler choose the platform=ruby version of the gem? Why is the bundle lock platform setting not respected?

@segiddins
Copy link
Member

You might want to look at the force_ruby_platform setting introduced in 1.14

@larskanis
Copy link
Contributor Author

If I use the setting force_ruby_platform , I get a bundler crash. See #5344

@larskanis
Copy link
Contributor Author

Using force_ruby_platform works. However since it forces the installation of platform=ruby gems exclusively, it is IMHO it's not a real solution. In case of nokogiri it should install the platform=ruby gem, because the native gem doesn't fit to the running ruby version.

@larskanis
Copy link
Contributor Author

larskanis commented Jan 24, 2017

rake-compiler-1.0.3+ adds ruby version constraints to all generated native gems. This issue will therefore probably affect many future gems that are built via rake-compiler (or rake-compiler-dock).

@twk3
Copy link

twk3 commented Mar 3, 2017

@segiddins if we were able to set force_ruby_platform for specific gems rather than the entire gemfile, I think that would help.

@segiddins
Copy link
Member

I dont think that is likely to happen any time soon, sorry

@larskanis
Copy link
Contributor Author

larskanis commented Mar 3, 2017 via email

@kasunvp
Copy link

kasunvp commented Mar 5, 2017

This is a viable solution tzinfo/tzinfo-data#12 (comment)
And just removing the line gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] from the generated Gemfile and doing a budle update resolves the issue for me on Linux (Ubuntu 16.04).

@segiddins
Copy link
Member

Closing, I don't think there's anything actionable for us here, given force_ruby_platform exists.

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

No branches or pull requests

4 participants