How to repack a ruby ​​stone with native extensions

I need to install a series of ruby ​​stones (all with C extensions) on a production server on which no development tools are installed. First, I would like to build gems on the dev server, and then repack and install production servers on my native stone.

However, apparently, there are no standard methods for packaging gem with native extensions for redistribution. I know about the rake compiler, but not one of the troublesome gems works with it. In particular, I work with gems json-1.7.5, rb-inotify-0.8.8 and ffi-1.2.1.

Any pointers on how to complete this task or documentation on this subject are appreciated.

+4
source share
3 answers

Using Jordan Sissel fpm , you can use various input archives (including gems), as well as compile and package them as (among others) DEB or RPM.

Below is an example for compiling json gem into a deb package:

cd /tmp fpm -s gem -t deb json 

This will download the latest version of json gem and create the rubygem-json-1.5.7-1.amd64.deb in /tmp , which you can install on your server. Note that the compilation field and destination server must be identical. At least the distribution and bitness, the ruby ​​version and its file layout, as well as the available downloadable libraries should be the same. Basically, all the restrictions that your distribution applies to are related to ...

However, in the long run, it was much easier for me to simply install the compiler on the target servers and use rbenv or rvm on the server. For most small and medium-sized devices, this is much easier to use, since you do not need to pre-compile and send everything to your servers.

+2
source

Hi You could do this with: gem-compiler

You need to give RubyGems the name of the file you want to compile:

 $ gem compile yajl-ruby-1.1.0.gem 

The above command unpacks, compiles existing existing extensions and repackages everything like a binary stone:

 Unpacking gem: 'yajl-ruby-1.1.0' in temporary directory... Building native extensions. This could take a while... Successfully built RubyGem Name: yajl-ruby Version: 1.1.0 File: yajl-ruby-1.1.0-x86-mingw32.gem 

There is a well-written documentation here: https://github.com/luislavena/gem-compiler . I use it, as well as my own gem server. You just need to be careful with the distribution, because some gems collected on a wheeze will not work on jessie, etc.

+1
source

You will have to build them in a system that works almost exactly for this. If you link to shared libraries that are located elsewhere or have slightly different versions, this may not work at all. Sometimes you have slack where it will work with a number of versions, but this cannot be guaranteed.

For this reason, there is no way to batch connect with native extensions; there are too many possible combinations of libraries.

You also need to make sure that you are using the same architecture, including 32-bit or 64-bit, as required.

Sometimes you are lucky and you have a package for your OS that can install them for you, but they will not work with rvm or rbenv .

0
source

All Articles