开发者

Rubygems: How do I add platform-specific dependency?

开发者 https://www.devze.com 2023-02-02 04:14 出处:网络
I\'ve a ruby gem that has different dependencies for each OS. I have to explicitly write all of them down:

I've a ruby gem that has different dependencies for each OS. I have to explicitly write all of them down:

On Mac OS X:

gem install livereloa开发者_JS百科d

on Linux:

gem install rb-inotify livereload

on Windows:

gem install eventmachine-win32 win32-changenotify win32-event livereload

Can I tweak a gemspec a bit so installation instructions would look like plain gem install livereload for every OS?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号