Rubygems: How do I add platform-specific dependency?

The proper way to do this is outlined here. Since the gemspec is evaluated at package time, you need to do it in a native extension. Don’t worry, it’s not that scary since its still just Ruby code (not compiling C or anything).

We are currently using this approach for some client tools for OpenShift (source). Then in your gemspec/Rakefile, instead of adding dependencies, you would add an extension. Note that the file needs to be named ext/mkrf_conf.rb for this to work.

Leave a Comment