Does Using ":Platforms =>" in Your Gemfile Work

does using :platforms = in your gemfile work?

:platforms => :ruby does indeed exclude gems from being installed on Windows.

However, it does not work in a cygwin environment. In cygwin, it considers the platform to be :mri.

You'll also notice that ruby -e 'puts RUBY_PLATFORM' outputs i386-cygwin, not i386-mingw32 or i386-mswin like it would on Windows ruby.

Were you working in a cygwin environment?

What exactly is the 'platforms' argument for gem in Gemfile?


Also note: I searched https://api.rubyonrails.org/ for 'gem', 'group', and 'platforms' but I couldn't spot an explanation there.

Makes sense, Gemfiles aren't part of Rails. They are provided by Bundler.

Is this code telling the Gemfile: "only install tzinfo-data gem if the platform is one of these: mingw, mswin, x64_mingw, jruby; if it's any other operating system, don't install it"?

Yes, exactly. You can read about their exact meanings in the Platform section of the Gemfile docs.

In particular, the tzinfo gem needs an up-to-date time zone databases. It will use the one installed on the operating system. If the operating system doesn't provide one, or if it doesn't keep it up to date, you can install the tzinfo-data gem. Most non-Windows machines maintain their own time zone database.

Platforms added to Gemfile.lock

After digging into this with fresh eyes in the morning here's what happened.

I checked my bash history and saw that I ran bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java before the commit I posted in the question. This obviously adds more platforms in your Gemfile.lock and subsequently platform specific dependencies.

I believe I ran this in the terminal to get rid of what I thought was an error around tzinfo-data. More info on that "error" here https://github.com/tzinfo/tzinfo-data/issues/12.

Rather than editing the Gemfile.lock directly, I ran bundle lock --remove-platform x86-mingw32 x86-mswin32 x64-mingw32 java and this made the appropriate edits to my lock file. More info here http://bundler.io/v1.16/bundle_lock.html.

Heroku no longer throwing an error when deploying as expected. Hope this helps someone in the future.

using bundler to load different versions of gems for different platforms

You can do it like that:

# Windows
gem "eventmachine", "~> 1.0.0.beta.4.1", :platform => [:mswin, :mingw]

# C Ruby (MRI) or Rubinius, but NOT Windows
gem "eventmachine", :platform => :ruby

Full list of available platforms:

ruby      C Ruby (MRI) or Rubinius, but NOT Windows
ruby_18 ruby AND version 1.8
ruby_19 ruby AND version 1.9
ruby_20 ruby AND version 2.0
mri Same as ruby, but not Rubinius
mri_18 mri AND version 1.8
mri_19 mri AND version 1.9
mri_20 mri AND version 2.0
rbx Same as ruby, but only Rubinius (not MRI)
jruby JRuby
mswin Windows
mingw Windows 'mingw32' platform (aka RubyInstaller)
mingw_18 mingw AND version 1.8
mingw_19 mingw AND version 1.9
mingw_20 mingw AND version 2.0

You can find more information in Gemfile(5) man page here (see 'Platforms' section).

Another approach is to use RUBY_PLATFORM constant:

if RUBY_PLATFORM =~ /win32/
gem "eventmachine", "~> 1.0.0.beta.4.1"
else
gem "eventmachine"
end

I haven't seen full list of available values for RUBY_PLATFORM but you can run

ruby -e 'puts RUBY_PLATFORM'

on both your platforms and see the difference.

Make bundler use different gems for different platforms

This is a known issue in Bundler. The workarounds are either:

  • Generate a Gemfile.lock on a system similar enough to your production environment that you get results that match your production platform. Effectively, that means you can only generate the Gemfile.lock file on Windows if your production system is Windows.
  • Don't commit a Gemfile.lock file at all, and determine dependencies on the production machine at deploy time (bundle install without --deploy). While not recommended in general, this is an often-used workaround until the bug is fixed. For example, this is the recommended solution offered by Heroku.
  • Switch to JRuby, which would have the same platform string across both Windows and Linux (java). I don't recommend this seriously, but I believe it would fix the problem.
  • Fix the problem in the Bundler source code, i.e., help the Bundler team fix the bug. :)

Running bundle or rspec adds line to Gemfile.lock

This was caused by global bundler config. Setting to false stopped the behavior.

specific_platform (BUNDLE_SPECIFIC_PLATFORM): Allow bundler to resolve for the specific running platform and store it in the lockfile, instead of only using a generic platform. A specific platform is the exact platform triple reported by Gem::Platform.local, such as x86_64-darwin-16 or universal-java-1.8. On the other hand, generic platforms are those such as ruby, mswin, or java. In this example, x86_64-darwin-16 would map to ruby and universal-java-1.8 to java.

Rails: Handling different gem versions for different operating systems

If anyone running into this. This was a known bug that was fixed in bundler version v2.2.11

From: How to change the version of bundler used in Cloud Functions deployment?

This is bundler's regression since bundler v2.2.8. https://github.com/rubygems/rubygems/issues/4366

Fix is here: https://github.com/rubygems/rubygems/pull/3655



Related Topics



Leave a reply



Submit