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

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

问题描述

我有一个红宝石宝石,它对每个操作系统都有不同的依赖关系.我必须明确地把它们都写下来:

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

在 Mac OS X 上:

On Mac OS X:

gem install livereload

在 Linux 上:

gem install rb-inotify livereload

在 Windows 上:

on Windows:

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

我可以稍微调整一下 gemspec,让每个操作系统的安装说明看起来都像普通的 gem install livereload 吗?

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

推荐答案

概述了正确的方法 这里.由于 gemspec 是在打包时评估的,因此您需要在本机扩展中进行.别担心,这并不可怕,因为它仍然只是 Ruby 代码(不编译 C 或任何东西).

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).

我们目前正在将这种方法用于 OpenShift 的一些客户端工具 (来源).然后在您的 gemspec/Rakefile 中,您将添加一个扩展,而不是添加依赖项.请注意,该文件需要命名为 ext/mkrf_conf.rb 才能正常工作.

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天全站免登陆