does using ":platforms =>" in your gemfile work?

jcollum picture jcollum · Dec 7, 2011 · Viewed 18.8k times · Source

I have a Rails app that I'm developing on Windows and deploying to Linux. I suspect I'll just switch entirely over to Linux in the future. Anyway, on Linux I need 'execjs' and 'therubyracer' but I don't need those in Win7. So I put these lines in my gemfile:

gem 'therubyracer', :platforms => :ruby
gem 'execjs', :platforms => :ruby

Ran a bundle install on the Linux VM and the app started up fine. But on Windows I get:

Uncaught exception: Could not find execjs-1.2.11 in any of the sources

Now, from what I read (here under PLATFORMS) it tells me that "If a gem should only be used in a particular platform or set of platforms, you can specify them" and the sample is this:

gem "weakling",   :platforms => :jruby 

And it says "ruby C Ruby (MRI) or Rubinius, but NOT Windows". So to me that says that bundler should be ignoring the execjs line on Windows. However on Windows when I ran bundle install I saw this:

Installing execjs (1.2.11)

So that says to me I'm missing something about the docs or bundler is ignoring the platforms command. Am I doing something wrong?

PS>bundle -v
Bundler version 1.0.21

Answer

Edward Anderson picture Edward Anderson · Jul 19, 2012

: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?