Rubygems:如何添加平台特定的依赖关系? [英] Rubygems: How do I add platform-specific dependency?

查看:83
本文介绍了Rubygems:如何添加平台特定的依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经 ruby​​ gem ,它对每个操作系统都有不同的依赖关系。


在Mac OS X上:



在Linux上:pre> gem install livereload

  gem install rb-inotify livereload 




$ b

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

code>


我可以调整一下gemspec,所以安装指令看起来像普通的 gem install livereload for each OS?

解决方案

执行此操作的正确方法概述 here 。由于gemspec是在封装时间进行评估的,因此您需要在本机扩展中进行。不要担心,它并不是那么可怕,因为它仍然只是Ruby代码(而不是编译C或其他)。



我们目前使用这种方法来处理OpenShift的一些客户端工具(来源)。然后在你的gemspec / Rakefile中,而不是添加依赖关系,你可以添加一个扩展。请注意,该文件需要命名为 ext / mkrf_conf.rb 才能使用。


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 livereload

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.

这篇关于Rubygems:如何添加平台特定的依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆