1
- # Ruby Gem native extensions
1
+ # Building Ruby gem native extensions
2
2
3
- Some Ruby Gems depend on C/C++ native extensions which makes it platform dependent. ` nokogiri ` will
4
- be one of these. [ Traveling Ruby] ( https://github.com/phusion/traveling-ruby ) provides a solution to
5
- include native extensions for several specific platforms, however, the extensions provided by
6
- Traveling Ruby is quite outdated and it is quite non-trivial to build its packages. I encountered
7
- failures with ` yum update ` in the ` chroot ` environment every now and then. Thus, I would rather
8
- build it on my own.
3
+ Some Ruby gems depend on C/C++ native extensions which are platform dependent. ` nokogiri ` is one of
4
+ these. Fortunately, [ Traveling Ruby] ( https://github.com/phusion/traveling-ruby ) provides a solution
5
+ to include native extensions for several specific platforms. However, those extensions provided by
6
+ Traveling Ruby are quite obsolete and it is quite non-trivial to build those packages using
7
+ Traveling Ruby. I encountered failures with ` yum update ` in the ` chroot ` environment every now and
8
+ then. Thus, I would rather build it on my own.
9
9
10
- As a workaround, we can build specific library in ` centos:centos6 ` container and copy over the
11
- extensions. Note that the final artifact of the extension should contain the following (use
12
- ` nokogiri ` as an example), which can be found at
13
- ` ruby/2.2.0/extensions/x86_64-linux/2.2.0-static/xxxx ` in your bundle ` --path ` :
10
+ As a workaround, we can build specific library in ` centos:centos6 ` container and copy those
11
+ extensions after the build. Note that the final artifact of an extension should contain the
12
+ following (use ` nokogiri ` as an example), which can be found at your bundle ` --path ` :
14
13
15
14
```
16
15
2.2.0
@@ -33,7 +32,13 @@ tar zcvf nokogiri-1.8.2.tar.gz 2.2.0
33
32
```
34
33
35
34
Alternatively, the Dockerfile provided in the directory will generate ` nokogiri-1.8.2.tar.gz ` and
36
- store it into ` /opt/build ` . And we can use this tarball as an upgrade for what ` Traveling Ruby `
37
- provides.
35
+ store it into ` /opt/build/target ` . And we can use this tarball as an upgrade for what ` Traveling Ruby `
36
+ provides. To build native extensions for more gems, add those gem into ` Gemfile ` , and run the
37
+ following:
38
+
39
+ ```
40
+ $ docker build -t rubygem-native-builder .
41
+ $ docker cp rubygem-native-builder:/opt/build/target /path/to/host/directory
42
+ ```
38
43
39
44
Have fun!
0 commit comments