# How to build gem whose dependencies depend of the platform?

**URL:** <https://www.ruby-forum.com/t/how-to-build-gem-whose-dependencies-depend-of-the-platform/202329>\
**Category:** Ruby\
**Created:** [January 26, 2011, 11:47pm UTC](https://www.ruby-forum.com/t/how-to-build-gem-whose-dependencies-depend-of-the-platform/202329 "2011-01-26T23:47:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 26, 2011, 11:47pm UTC](https://www.ruby-forum.com/t/how-to-build-gem-whose-dependencies-depend-of-the-platform/202329/1 "2011-01-26T23:47:49Z")

</div>

Hi!

I need to build a gem whose dependencies are dependent of the platform  
itself. For example when `gem install my_gem` is issued under Windows,  
then in gemspec i have to have spec.add\_dependency(“gemX”), but if the  
command is executed under linux then i need to have  
spec.add\_dependency(“gemY”).

Is there any easy way to do this or should i just do it like this  
instead:

1. remove all platform specific dependencies from gemspec
2. when loading the gem, then use RUBY\_PLATFORM to decide what gems to  
load and rescue Gem::LoadError to print out friendly messages like  
“please install gemX”

Jarmo

---

<div class="post-metadata">

**Author:** ![juuser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@juuser](https://www.ruby-forum.com/u/juuser)\
**Post date:** [January 26, 2011, 11:51pm UTC](https://www.ruby-forum.com/t/how-to-build-gem-whose-dependencies-depend-of-the-platform/202329/2 "2011-01-26T23:51:36Z")

</div>

On Jan 26, 7:25pm, Jarmo P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 1. remove all platform specific dependencies from gemspec
> 2. when loading the gem, then use RUBY\_PLATFORM to decide what gems to  
> load and rescue Gem::LoadError to print out friendly messages like  
> “please install gemX”

This one is the best approach. Have that clearly in the documentation  
and the error you present to the user is the best option.

The other will be generate one gem for every platform and indicate  
there the dependencies. Lot of work for you 😛

---

<div class="post-metadata">

**Author:** ![juuser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@juuser](https://www.ruby-forum.com/u/juuser)\
**Post date:** [January 29, 2011, 12:33pm UTC](https://www.ruby-forum.com/t/how-to-build-gem-whose-dependencies-depend-of-the-platform/202329/3 "2011-01-29T12:33:45Z")

</div>

Ok, but this is not best solution also since user:

1. gem install mylib
2. create a script and `require "mylib"`
3. run that script
4. get an error about missing dependency
5. nevertheless of just running gem install, user needs to run gem  
install again

It just feels not user friendly way to solve it. Another way would be  
to create separate gems of course, but it’s not a good way either.

## Jarmo P.

IT does really matter - [http://www.itreallymatters.net](http://www.itreallymatters.net)

---

<div class="post-metadata">

**Author:** ![juuser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@juuser](https://www.ruby-forum.com/u/juuser)\
**Post date:** [January 29, 2011, 1:56pm UTC](https://www.ruby-forum.com/t/how-to-build-gem-whose-dependencies-depend-of-the-platform/202329/4 "2011-01-29T13:56:06Z")

</div>

On 2011-01-29, at 12:21, Jarmo P. wrote:

> > > I need to build a gem whose dependencies are dependent of the platform  
> > > itself. For example when `gem install my_gem` is issued under Windows,  
> > > then in gemspec i have to have spec.add\_dependency(“gemX”), but if the  
> > > command is executed under linux then i need to have  
> > > spec.add\_dependency(“gemY”).

I have solved this by making the gem depend on the “bundler” gem, and  
then put the gem dependecies into a Gemfile, and run the equivalent of  
“bundle install” as a post-install script. This takes care of  
everything. The only thing I am missing is that the dependencies are  
visible when inspecting the gem.

Having RubyGems drop the gemspec dependencies in favor of Gemfile  
dependencies would be my preferred way.

–  
With kind regards  
Uwe K.  
Kubosch Consulting  
removed\_email\_address@domain.invalid

> **[kubosch.no - Welcome to Kubosch Consulting](http://www.kubosch.no/)**
>
> kubosch.no - bringing martial arts and information technology together.

---

<div class="post-metadata">

**Author:** ![juuser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@juuser](https://www.ruby-forum.com/u/juuser)\
**Post date:** [January 29, 2011, 6:58pm UTC](https://www.ruby-forum.com/t/how-to-build-gem-whose-dependencies-depend-of-the-platform/202329/5 "2011-01-29T18:58:32Z")

</div>

On Jan 29, 9:55am, Uwe K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 2011-01-29, at 12:21, Jarmo P. wrote:
> 
> > > > I need to build a gem whose dependencies are dependent of the platform  
> > > > itself. For example when `gem install my_gem` is issued under Windows,  
> > > > then in gemspec i have to have spec.add\_dependency(“gemX”), but if the  
> > > > command is executed under linux then i need to have  
> > > > spec.add\_dependency(“gemY”).
> 
> I have solved this by making the gem depend on the “bundler” gem, and then put  
> the gem dependecies into a Gemfile, and run the equivalent of “bundle install” as  
> a post-install script. This takes care of everything. The only thing I am missing  
> is that the dependencies are visible when inspecting the gem.

RubyGems post\_install is not scripts, perhaps you’re using extension  
compilation to make that happen, which is intrusive to the user.

You’re also bringing Bundler when the user might not want it into the  
mix and slowing down the gem loading process.

Bundler is awesome for development, but is awful for runtime  
dependency. You should not be imposing bundler to the user and even  
less for runtime execution.

Also bundler do not handle properly all the platforms, using a  
different concept of “platform” of what RubyGems understand and is  
widely known.

---

<div class="post-metadata">

**Author:** ![juuser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@juuser](https://www.ruby-forum.com/u/juuser)\
**Post date:** [January 29, 2011, 7:01pm UTC](https://www.ruby-forum.com/t/how-to-build-gem-whose-dependencies-depend-of-the-platform/202329/6 "2011-01-29T19:01:02Z")

</div>

On Jan 29, 8:16am, Jarmo P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

You can display a post\_install message after you installed “mylib”  
that tells:

mylib depends on platform specific components, please install “mylib-  
windows” before you start using it.

And still rescue on the LoadError.

The other way around is what I mentioned, but then you will need to  
generate one gem for every RubyGems platform: linux, darwin, freebsd,  
mingw32, mswin32, etc and indicate the proper dependencies.

Even if the gem itself is not different.

I feel that is more work to do, don’t you think?

---

<div class="post-metadata">

**Author:** ![juuser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@juuser](https://www.ruby-forum.com/u/juuser)\
**Post date:** [January 30, 2011, 7:05pm UTC](https://www.ruby-forum.com/t/how-to-build-gem-whose-dependencies-depend-of-the-platform/202329/7 "2011-01-30T19:05:25Z")

</div>

On Jan 30, 8:06am, Uwe K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > RubyGems post\_install is not scripts, perhaps you’re using extension  
> > compilation to make that happen, which is intrusive to the user.
> 
> You are right, I use the extension compilation to run the extra install step.
> 
> How is this intrusive?

If user grant RubyGems sudo to install the gem and it’s dependencies,  
you’re sneaking something that the user was not aware of.

If the user using a gem list find this gem he didn’t install, on  
uninstallation no dependency warning will be triggered, and the  
original gem will not work because of that.

> > You’re also bringing Bundler when the user might not want it into the  
> > mix and slowing down the gem loading process.
> 
> I would rather add Bundler than not have the gem install all its dependencies.  
> The user experience is what matters, and this way all dependencies install  
> correctly and the gem is ready for use regardless of the users platform.

This is similar case to what Hoe did in the past, as add it as  
dependency even that you used for development only. Search for it.

> > Bundler is awesome for development, but is awful for runtime  
> > dependency. You should not be imposing bundler to the user and even  
> > less for runtime execution.
> 
> Why not? Bundler is awesome for runtime dependencies as well. It is the default  
> mechanism for Ruby On Rails runtime dependencies.

> **[IbrasTen.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=ibrasten.com)**
>
> The leading source brandable domain names. Competitive prices. Excellent service. Get your domain name today.

> > Also bundler do not handle properly all the platforms, using a  
> > different concept of “platform” of what RubyGems understand and is  
> > widely known.
> 
> The platform concept of Bundler is different from RubyGems platform, but Bundler  
> handles all platforms properly and the platform concept of Bundler is as well  
> known and as intuitive as RubyGems.

No, it doesn’t, take for example JSON gem, is broken under 1.9.x or  
1.8.x for Windows and even when the user decided to fix it manually,  
bundler always force it’s installation.

> <https://github.com/rubygems/bundler/issues/635>
>
> We've got 4 people working in our team, 2 on Macs, 1 on Linux and 1 on Windows. …They all have Bundler either at 1.0.0 final or something very recent (rc5, 6). And here's what happens:
> \- today I updated the lock file with bundle install on my Mac, and committed the change; a few hours later, the other Mac developer did the same, and his lock file had the Windows gems reversed - e.g.
> 
> my commit:
> 
> \`\`\`
> json (1.4.6)
> json (1.4.6-x86-mingw32)
> \`\`\`
> 
> his commit:
> 
> \`\`\`
> json (1.4.6-x86-mingw32)
> json (1.4.6)
> \`\`\`
> \- when the Linux developer calls bundle install, it's generated without the Windows versions at all
> \- when the Windows developer calls bundle install, it's generated with only the Windows versions (so json 1.4.6 generic disappears)
> 
> It's not a critical bug, as we can always remove those changes from the diff before committing, but it is very annoying...

> <https://github.com/rubygems/bundler/issues/589>
>
> Hello,
> 
> Tried to reach wycats and carllerche on this in the past, and since ther…e is no mailing list, decide to open "a bug".
> 
> The case is covered here:
> 
> http://gist.github.com/536191
> 
> Basically:
> \- Documentation states mswin is Windows
> \- ming is misspelled (is mingw) Minimalist GNU for Windows (MinGW)
> \- ming is excluded from valid platforms
> 
> All the above cases render RubyInstaller useless. First, RubyInstaller is MinGW based, meaning that 'mswin' will not fit the bill.
> 
> Users indicating 'mswin' will force the installation of x86-mswin32 gems, when the platform is x86-mingw32, so if the user already had sqlite3-ruby-1.3.1-x86-mingw32.gem installed, it will attempt to install the mswin32 platform gem instead.
> 
> Users indicating 'ming' will get an error:
> 
> \<pre\>\<code\>
> C:\\Users\\Luis\\Projects\\\_sandbox\\bundle-test\>bundle check
> \`ming\` is not a valid platform. The available options are: \[:jruby, :ruby\_18, :mswin, :ruby\_19, :ruby, :mri, :mri\_18, :mri\_19\]
> \</code\>\</pre\>
> 
> 
> I commented in the past this to Yehuda that if platform :windows is proposed, the correct usage of both x86-mswin32 and x86-mingw32 should be considered.
> 
> I believe the current state and the documentation shown so far will lead to errors for these users and complains to RubyInstaller which, IMHO, are not the root of it.
> 
> Thank you.

---

<div class="post-metadata">

**Author:** ![juuser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@juuser](https://www.ruby-forum.com/u/juuser)\
**Post date:** [January 30, 2011, 11:29pm UTC](https://www.ruby-forum.com/t/how-to-build-gem-whose-dependencies-depend-of-the-platform/202329/8 "2011-01-30T23:29:14Z")

</div>

On 2011-01-30, at 19:02, Luis L. wrote:

> > > RubyGems post\_install is not scripts, perhaps you’re using extension  
> > > compilation to make that happen, which is intrusive to the user.
> > 
> > You are right, I use the extension compilation to run the extra install step.  
> > How is this intrusive?

> If user grant RubyGems sudo to install the gem and it’s dependencies,  
> you’re sneaking something that the user was not aware of.
> 
> If the user using a gem list find this gem he didn’t install, on  
> uninstallation no dependency warning will be triggered, and the  
> original gem will not work because of that.

True. I consider this a flaw and would very much like to solve that,  
too.

> > > You’re also bringing Bundler when the user might not want it into the  
> > > mix and slowing down the gem loading process.
> > 
> > I would rather add Bundler than not have the gem install all its dependencies.  
> > The user experience is what matters, and this way all dependencies install  
> > correctly and the gem is ready for use regardless of the users platform.
> 
> This is similar case to what Hoe did in the past, as add it as  
> dependency even that you used for development only. Search for it.

The difference is that Bundler is a good gem for setting up runtime  
dependencies. It is not a development only gem.

> > > Bundler is awesome for development, but is awful for runtime  
> > > dependency. You should not be imposing bundler to the user and even  
> > > less for runtime execution.
> > 
> > Why not? Bundler is awesome for runtime dependencies as well. It is the  
> > default mechanism for Ruby On Rails runtime dependencies.

> 

> **[IbrasTen.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=ibrasten.com)**
>
> The leading source brandable domain names. Competitive prices. Excellent service. Get your domain name today.

Good article, and valid if your main concern is application startup  
time. My main concerns are ease of installation, and performance after  
startup. Bundler fits that need.

> [Gemfile.lock is generated differently on different platforms · Issue #635 · rubygems/bundler · GitHub](https://github.com/carlhuda/bundler/issues/635)  
> [Bundler platforms for Windows are messed up · Issue #589 · rubygems/bundler · GitHub](https://github.com/carlhuda/bundler/issues/589)

These are valid concerns, and it looks like they are being taken  
seriously, so hopefully they will be sorted out. I appreciate your  
efforts on improving Ruby on Windows.

If your gem hits any of these issues, you need to address them, and  
maybe using Bundler is not your solution. If your gem does not hit  
these issues, maybe you accept your gem will not be used on Windows,  
Bundler is a solution to the original problem of having a valid set of  
gems installed with your gem without the user having to do extra steps.

I would like to hear other solutions than using Bundler that enables the  
correct installation of dependent gems that vary with the user’s  
platform.

–  
With kind regards  
Uwe K.  
Kubosch Consulting  
removed\_email\_address@domain.invalid

> **[kubosch.no - Welcome to Kubosch Consulting](http://www.kubosch.no/)**
>
> kubosch.no - bringing martial arts and information technology together.

---

<div class="post-metadata">

**Author:** ![juuser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@juuser](https://www.ruby-forum.com/u/juuser)\
**Post date:** [January 30, 2011, 12:10pm UTC](https://www.ruby-forum.com/t/how-to-build-gem-whose-dependencies-depend-of-the-platform/202329/9 "2011-01-30T12:10:36Z")

</div>

On 2011-01-29, at 18:55, Luis L. wrote:

> > > > > I need to build a gem whose dependencies are dependent of the platform  
> > > > > itself. For example when `gem install my_gem` is issued under Windows,  
> > > > > then in gemspec i have to have spec.add\_dependency(“gemX”), but if the  
> > > > > command is executed under linux then i need to have  
> > > > > spec.add\_dependency(“gemY”).
> > 
> > I have solved this by making the gem depend on the “bundler” gem, and then put  
> > the gem dependecies into a Gemfile, and run the equivalent of “bundle install” as  
> > a post-install script. This takes care of everything. The only thing I am  
> > missing is that the dependencies are visible when inspecting the gem.
> 
> RubyGems post\_install is not scripts, perhaps you’re using extension  
> compilation to make that happen, which is intrusive to the user.

You are right, I use the extension compilation to run the extra install  
step.

How is this intrusive?

> You’re also bringing Bundler when the user might not want it into the  
> mix and slowing down the gem loading process.

I would rather add Bundler than not have the gem install all its  
dependencies. The user experience is what matters, and this way all  
dependencies install correctly and the gem is ready for use regardless  
of the users platform.

> Bundler is awesome for development, but is awful for runtime  
> dependency. You should not be imposing bundler to the user and even  
> less for runtime execution.

Why not? Bundler is awesome for runtime dependencies as well. It is  
the default mechanism for Ruby On Rails runtime dependencies.

> Also bundler do not handle properly all the platforms, using a  
> different concept of “platform” of what RubyGems understand and is  
> widely known.

The platform concept of Bundler is different from RubyGems platform, but  
Bundler handles all platforms properly and the platform concept of  
Bundler is as well known and as intuitive as RubyGems.

If RubyGems alone would allow developers to solve the problem of  
dependencies varying with the user’s platform, that is what I would use.  
As long as RubyGems falls short to solve the problem, we need to solve  
it some other way. Using Bundler solves the problem, and does it  
nicely.

–  
With kind regards  
Uwe K.  
Kubosch Consulting  
removed\_email\_address@domain.invalid

> **[kubosch.no - Welcome to Kubosch Consulting](http://www.kubosch.no/)**
>
> kubosch.no - bringing martial arts and information technology together.
