rake-compiler-dock 0.7.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.gitignore +4 -0
  5. data/Dockerfile.jruby +9 -5
  6. data/{Dockerfile.mri → Dockerfile.mri.erb} +81 -23
  7. data/History.md +23 -0
  8. data/README.md +62 -10
  9. data/Rakefile +36 -4
  10. data/{lib/rake_compiler_dock → build}/gem_helper.rb +0 -15
  11. data/build/parallel_docker_build.rb +102 -0
  12. data/build/patches/{ruby-2.5.3 → ruby-2.5.7}/no_sendfile.patch +1 -1
  13. data/build/patches/ruby-2.7.0/no_sendfile.patch +24 -0
  14. data/build/patches2/hoe-3.20.0/0001-Load-encrypted-private-key-using-ENV-GEM_PRIVATE_KEY.patch +32 -0
  15. data/build/patches2/rake-compiler-1.1.0/0001-Allow-parallel-builds-of-cross-rubies.patch +119 -0
  16. data/build/patches2/rake-compiler-1.1.0/0001-Enable-build-of-static-libruby.patch +28 -0
  17. data/build/patches2/rake-compiler-1.1.0/0001-Fix-determining-of-ruby-versions-in-rake-native-gem.patch +44 -0
  18. data/build/patches2/rake-compiler-1.1.0/0002-Extend-mingw-search-pattern-to-find-x86_64-gcc.patch +26 -0
  19. data/build/patches2/rake-compiler-1.1.0/0002-Strip-cross-built-shared-library-files-while-linking.patch +29 -0
  20. data/build/patches2/ruby-2.7.0/ruby2_keywords.patch +15 -0
  21. data/build/runas +2 -0
  22. data/build/sudoers +1 -1
  23. data/lib/rake_compiler_dock.rb +10 -0
  24. data/lib/rake_compiler_dock/docker_check.rb +12 -6
  25. data/lib/rake_compiler_dock/starter.rb +68 -53
  26. data/lib/rake_compiler_dock/version.rb +2 -2
  27. data/test/test_environment_variables.rb +2 -2
  28. data/test/test_parallel_docker_build.rb +57 -0
  29. metadata +39 -8
  30. metadata.gz.sig +2 -0
  31. data/build/patches/rake-compiler-1.0.7/enable-static.diff +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f8966fb1c1fe4aec8b3e82b034c7f1327cefc6c632d5e7d5308d1edbf5d5d58
4
- data.tar.gz: 5d8f0f1075017802cbe0592ea481683f4958806ce3e1fb47f12fe1e2e5763679
3
+ metadata.gz: f619b5de824d49259e240b44270af56e87018e9678833f07de25992d71651557
4
+ data.tar.gz: 1ed31831b3763adf6a7b25005e58f47773fc633b728a7d92cfa6f26698fe72ef
5
5
  SHA512:
6
- metadata.gz: 87eb25a8c230147d54c119e4738c2c95a9afe49d88c3dc463cc64f712fae18d9b237cfe7270292d6044969c7fcd0f215a33b5e74ad8b2578c0823d7dc1496039
7
- data.tar.gz: 42a89f7a0f73263d06165e0d12da16b2a0c7c58618641e45734d04df3c8c1dad9891502169c1123dcb47bd0cfb232e115eb1159847d7fecd6d9774cf3733b1ca
6
+ metadata.gz: 2aac49b389b5cbaeca4ffa98f09921fb5fa46bf4710cfda7cb299b8eb3c7dd03c15e7a6181fa4a267b94f9ec69b2086a57d65b9d8d136e4ffc0c26c63dad1941
7
+ data.tar.gz: cff042d7790888b2f7bd024475100ecdb6d9b70126fe0b6cd82b086e8897382d7b612d3e4d68de87ba9df28c7c5ea3fe013493b57ea34038735b0d19923f66b8
Binary file
Binary file
data/.gitignore CHANGED
@@ -1,5 +1,9 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
+ /Dockerfile.mri.x86-linux
4
+ /Dockerfile.mri.x86-mingw32
5
+ /Dockerfile.mri.x86_64-linux
6
+ /Dockerfile.mri.x64-mingw32
3
7
  /Gemfile.lock
4
8
  /_yardoc/
5
9
  /coverage/
@@ -1,16 +1,20 @@
1
1
  FROM ubuntu:18.04
2
2
 
3
3
  RUN apt-get -y update && \
4
- apt-get install -y curl git-core xz-utils wget unzip sudo gpg dirmngr openjdk-11-jdk-headless
4
+ apt-get install -y curl git-core xz-utils wget unzip sudo gpg dirmngr openjdk-11-jdk-headless && \
5
+ rm -rf /var/lib/apt/lists/*
5
6
 
6
7
  # Add "rvm" as system group, to avoid conflicts with host GIDs typically starting with 1000
7
8
  RUN groupadd -r rvm && useradd -r -g rvm -G sudo -p "" --create-home rvm && \
8
9
  echo "source /etc/profile.d/rvm.sh" >> /etc/rubybashrc
9
10
  USER rvm
10
11
 
12
+ RUN mkdir ~/.gnupg && \
13
+ echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf
14
+
11
15
  # install rvm, RVM 1.26.0+ has signed releases, source rvm for usage outside of package scripts
12
16
  RUN gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB && \
13
- (curl -L http://get.rvm.io | sudo bash -s stable) && \
17
+ (curl -L http://get.rvm.io | sudo bash) && \
14
18
  bash -c " \
15
19
  source /etc/rubybashrc && \
16
20
  rvmsudo rvm cleanup all "
@@ -22,7 +26,7 @@ ENV BASH_ENV /etc/rubybashrc
22
26
  # install rubies and fix permissions on
23
27
  RUN bash -c " \
24
28
  export CFLAGS='-s -O3 -fno-fast-math -fPIC' && \
25
- for v in jruby-9.2.5.0 ; do \
29
+ for v in jruby-9.2.9.0 ; do \
26
30
  rvm install --binary \$v --patch \$(echo ~/patches/ruby-\$v/* | tr ' ' ','); \
27
31
  done && \
28
32
  rvm cleanup all && \
@@ -42,8 +46,8 @@ RUN sudo mkdir -p /usr/local/rake-compiler && \
42
46
 
43
47
  USER root
44
48
 
45
- RUN bash -c "rvm alias create default jruby-9.2.5.0"
46
- RUN echo "rvm use jruby-9.2.5.0 > /dev/null" >> /etc/rubybashrc
49
+ RUN bash -c "rvm alias create default jruby-9.2.9.0"
50
+ RUN echo "rvm use jruby-9.2.9.0 > /dev/null" >> /etc/rubybashrc
47
51
 
48
52
  # Add rvm to the global bashrc
49
53
  RUN echo "source /etc/profile.d/rvm.sh" >> /etc/bash.bashrc
@@ -1,16 +1,21 @@
1
- FROM ubuntu:16.04
1
+ FROM ubuntu:<%= platform=~/linux/ ? "16.04" : "18.04" %>
2
2
 
3
3
  RUN apt-get -y update && \
4
- apt-get install -y curl git-core xz-utils build-essential wget unzip sudo gnupg2 dirmngr
4
+ apt-get install -y curl git-core xz-utils build-essential wget unzip sudo gnupg2 dirmngr && \
5
+ rm -rf /var/lib/apt/lists/*
5
6
 
6
7
  # Add "rvm" as system group, to avoid conflicts with host GIDs typically starting with 1000
7
8
  RUN groupadd -r rvm && useradd -r -g rvm -G sudo -p "" --create-home rvm && \
8
9
  echo "source /etc/profile.d/rvm.sh" >> /etc/rubybashrc
9
10
  USER rvm
10
11
 
12
+ RUN mkdir ~/.gnupg && \
13
+ chmod 700 ~/.gnupg && \
14
+ echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf
15
+
11
16
  # install rvm, RVM 1.26.0+ has signed releases, source rvm for usage outside of package scripts
12
17
  RUN gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB && \
13
- (curl -L http://get.rvm.io | sudo bash -s stable) && \
18
+ (curl -L http://get.rvm.io | sudo bash) && \
14
19
  bash -c " \
15
20
  source /etc/rubybashrc && \
16
21
  rvmsudo rvm cleanup all "
@@ -22,7 +27,7 @@ ENV BASH_ENV /etc/rubybashrc
22
27
  # install rubies and fix permissions on
23
28
  RUN bash -c " \
24
29
  export CFLAGS='-s -O3 -fno-fast-math -fPIC' && \
25
- for v in 2.5.3 ; do \
30
+ for v in 2.5.7 ; do \
26
31
  rvm install \$v --patch \$(echo ~/patches/ruby-\$v/* | tr ' ' ','); \
27
32
  done && \
28
33
  rvm cleanup all && \
@@ -32,6 +37,7 @@ RUN bash -c " \
32
37
  # do not generate documentation for gems
33
38
  RUN echo "gem: --no-ri --no-rdoc" >> ~/.gemrc && \
34
39
  bash -c " \
40
+ rvm all do gem update --system --no-document && \
35
41
  rvm all do gem install --no-document bundler 'bundler:~>1.16' rake-compiler hoe mini_portile rubygems-tasks mini_portile2 && \
36
42
  find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw "
37
43
 
@@ -43,33 +49,57 @@ RUN sudo mkdir -p /usr/local/rake-compiler && \
43
49
  # Add cross compilers for Windows and Linux
44
50
  USER root
45
51
  RUN apt-get -y update && \
46
- apt-get install -y gcc-mingw-w64-x86-64 gcc-mingw-w64-i686 g++-mingw-w64-x86-64 g++-mingw-w64-i686 \
47
- gcc-multilib moreutils
52
+ apt-get install -y moreutils <%
53
+ if platform=~/x86-mingw32/ %> gcc-mingw-w64-i686 g++-mingw-w64-i686 <% end %><%
54
+ if platform=~/x64-mingw32/ %> gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 <% end %><%
55
+ if platform=~/x86-linux/ %> gcc-multilib g++-multilib <% end %> && \
56
+ rm -rf /var/lib/apt/lists/*
57
+
58
+ RUN bash -c " \
59
+ rvm alias create default 2.5.7 && \
60
+ rvm use default "
48
61
 
49
- # Create dev tools i686-linux-gnu-*
62
+ <% if platform=~/linux/ %>
63
+ # Create dev tools x86-linux-*
50
64
  COPY build/mk_i686.rb /root/
51
65
  RUN bash -c " \
52
- rvm alias create default 2.5.3 && \
53
- rvm use default && \
54
66
  ruby /root/mk_i686.rb "
67
+ <% end %>
55
68
 
56
69
  USER rvm
57
70
 
71
+ COPY build/patches2 /home/rvm/patches/
58
72
  # Patch rake-compiler to build and install static libraries for Linux rubies
59
- RUN cd /usr/local/rvm/gems/ruby-2.5.3/gems/rake-compiler-1.0.7 && \
60
- ( git apply /home/rvm/patches/rake-compiler-1.0.7/*.diff || true )
73
+ RUN cd /usr/local/rvm/gems/ruby-2.5.7/gems/rake-compiler-1.1.0 && \
74
+ ( git apply /home/rvm/patches/rake-compiler-1.1.0/*.patch || true )
75
+ RUN cd /usr/local/rvm/gems/ruby-2.5.7/gems/hoe-3.20.0 && \
76
+ ( git apply /home/rvm/patches/hoe-3.20.0/*.patch || true )
77
+
78
+
79
+ # Patch ruby-2.7.0 for cross build
80
+ USER root
81
+ RUN curl -SL http://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.0.tar.xz | tar -xJC /root/ && \
82
+ cd /root/ruby-2.7.0 && \
83
+ git apply /home/rvm/patches/ruby-2.7.0/*.patch && \
84
+ cd .. && \
85
+ mkdir -p /usr/local/rake-compiler/sources/ && \
86
+ tar cjf /usr/local/rake-compiler/sources/ruby-2.7.0.tar.bz2 ruby-2.7.0 && \
87
+ chown rvm /usr/local/rake-compiler -R && \
88
+ rm -rf /root/ruby-2.7.0
89
+ USER rvm
90
+
61
91
 
62
- ENV XRUBIES 2.6.0 2.5.0 2.4.0 2.3.0 2.2.2
92
+ ENV XRUBIES 2.7.0 2.6.0 2.5.0 2.4.0 2.3.0 2.2.2
63
93
 
64
94
  # First do downloads sequentially since they can not run in parallel
65
95
  # Then build all xruby versions in parallel
66
96
  # Then cleanup all build artifacts
67
97
  RUN for rv in $XRUBIES; do \
68
- bash -c "rake-compiler /home/rvm/.rake-compiler/sources/ruby-$rv/Makefile.in VERSION=$rv HOST=x86_64-linux-gnu"; \
98
+ bash -c "rake-compiler prepare-sources VERSION=$rv HOST=x86_64-linux"; \
69
99
  done; \
70
100
  for rv in $XRUBIES; do \
71
- for host in i686-linux-gnu x86_64-linux-gnu i686-w64-mingw32 x86_64-w64-mingw32; do \
72
- echo -n "'rake-compiler cross-ruby VERSION=$rv HOST=$host' " >> ~/xbuild_rubies; \
101
+ for host in <%= target %>; do \
102
+ echo -n "'env MAKE=\"make V=0\" rake-compiler cross-ruby VERSION=$rv HOST=$host' " >> ~/xbuild_rubies; \
73
103
  done; \
74
104
  done && \
75
105
  cat ~/xbuild_rubies; \
@@ -79,33 +109,61 @@ RUN for rv in $XRUBIES; do \
79
109
  rm -rf ~/.rake-compiler/builds ~/.rake-compiler/sources && \
80
110
  find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw "
81
111
 
112
+ <% if platform=~/linux/ %>
82
113
  # Avoid linking against libruby shared object.
83
114
  # See also https://github.com/rake-compiler/rake-compiler-dock/issues/13
84
115
  RUN find /usr/local/rake-compiler/ruby/*linux*/ -name libruby.so | xargs rm
85
116
  RUN find /usr/local/rake-compiler/ruby/*linux*/ -name libruby-static.a | while read f ; do cp $f `echo $f | sed s/-static//` ; done
86
117
  RUN find /usr/local/rake-compiler/ruby/*linux*/ -name libruby.a | while read f ; do ar t $f | xargs ar d $f ; done
87
118
  RUN find /usr/local/rake-compiler/ruby/*linux*/ -name mkmf.rb | while read f ; do sed -i ':a;N;$!ba;s/TRY_LINK = [^\n]*\n[^\n]*\n[^\n]*LOCAL_LIBS)/& -lruby-static/' $f ; done
119
+ <% end %>
88
120
 
121
+ <% if platform=~/mingw/ %>
89
122
  # RubyInstaller doesn't install libgcc -> link it static.
90
123
  RUN find /usr/local/rake-compiler/ruby/*mingw*/ -name rbconfig.rb | while read f ; do sed -i 's/."LDFLAGS". = "/&-static-libgcc /' $f ; done
124
+ # Raise Windows-API to Vista (affects ruby < 2.6 only)
125
+ RUN find /usr/local/rake-compiler/ruby -name rbconfig.rb | while read f ; do sed -i 's/0x0501/0x0600/' $f ; done
126
+ # Don't link to static libruby
127
+ RUN find /usr/local/rake-compiler/ruby -name *msvcrt-ruby*.dll.a | while read f ; do n=`echo $f | sed s/.dll//` ; mv $f $n ; done
128
+ <% end %>
91
129
 
92
130
  USER root
93
131
 
94
132
  # Add more libraries and tools to support cross build
95
- RUN dpkg --add-architecture i386 && \
133
+ RUN <%
134
+ if platform=~/x86-linux/ %> dpkg --add-architecture i386 && <% end %> \
96
135
  apt-get -y update && \
97
- apt-get install -y libc6-dev:i386 libudev-dev libudev-dev:i386 cmake
136
+ apt-get install -y cmake <%
137
+ if platform=~/x86-linux/ %> libc6-dev:i386 libudev-dev:i386 <% end %><%
138
+ if platform=~/x86_64-linux/ %> libudev-dev <% end %> && \
139
+ rm -rf /var/lib/apt/lists/*
98
140
 
99
141
  # Fix paths in rake-compiler/config.yml and add rvm and mingw-tools to the global bashrc
100
142
  RUN sed -i -- "s:/root/.rake-compiler:/usr/local/rake-compiler:g" /usr/local/rake-compiler/config.yml && \
101
143
  echo "source /etc/profile.d/rvm.sh" >> /etc/bash.bashrc
102
144
 
103
- # # Install wrappers for strip commands as a workaround for "Protocol error" in boot2docker.
145
+ <% if platform=~/mingw/ %>
146
+ # Install wrappers for strip commands as a workaround for "Protocol error" in boot2docker.
104
147
  COPY build/strip_wrapper /root/
105
- RUN mv /usr/bin/i686-w64-mingw32-strip /usr/bin/i686-w64-mingw32-strip.bin && \
106
- mv /usr/bin/x86_64-w64-mingw32-strip /usr/bin/x86_64-w64-mingw32-strip.bin && \
107
- ln /root/strip_wrapper /usr/bin/i686-w64-mingw32-strip && \
108
- ln /root/strip_wrapper /usr/bin/x86_64-w64-mingw32-strip
148
+ RUN mv /usr/bin/<%= target %>-strip /usr/bin/<%= target %>-strip.bin && \
149
+ ln /root/strip_wrapper /usr/bin/<%= target %>-strip
150
+
151
+ # Don't link to winpthread.dll but link static, since the DLL is not distributed with RubyInstaller
152
+ RUN find / -name libwinpthread.dll.a | xargs rm
153
+ RUN find / -name libwinpthread-1.dll | xargs rm
154
+
155
+ # Use posix pthread for mingw so that C++ standard library for thread could be
156
+ # available such as std::thread, std::mutex, so on.
157
+ # https://sourceware.org/pthreads-win32/
158
+ RUN printf "1\n" | update-alternatives --config <%= target %>-gcc && \
159
+ printf "1\n" | update-alternatives --config <%= target %>-g++
160
+ <% end %>
161
+
162
+ <% if platform=~/linux/ %>
163
+ # Make the system to have GLIBC 2.12 instead of 2.23 so that
164
+ # generated ruby package can run on CentOS 6 with GLIBC 2.12
165
+ RUN sed -i 's/__GLIBC_MINOR__\t[0-9][0-9]/__GLIBC_MINOR__\t12/' /usr/include/features.h
166
+ <% end %>
109
167
 
110
168
  # Install SIGINT forwarder
111
169
  COPY build/sigfw.c /root/
@@ -117,6 +175,6 @@ COPY build/runas /usr/local/bin/
117
175
  # Install sudoers configuration
118
176
  COPY build/sudoers /etc/sudoers.d/rake-compiler-dock
119
177
 
120
- ENV RUBY_CC_VERSION 2.6.0:2.5.0:2.4.0:2.3.0:2.2.2
178
+ ENV RUBY_CC_VERSION 2.7.0:2.6.0:2.5.0:2.4.0:2.3.0:2.2.2
121
179
 
122
180
  CMD bash
data/History.md CHANGED
@@ -1,3 +1,26 @@
1
+ 1.0.0 / 2020-01-04
2
+ ------------------
3
+ * Add ruby-2.7.0 cross ruby.
4
+ * Use per-target docker images.
5
+ There are currently 5 docker images:
6
+ * larskanis/rake-compiler-dock-mri-x86-mingw32
7
+ * larskanis/rake-compiler-dock-mri-x64-mingw32
8
+ * larskanis/rake-compiler-dock-mri-x86-linux
9
+ * larskanis/rake-compiler-dock-mri-x86_64-linux
10
+ * larskanis/rake-compiler-dock-jruby
11
+ Since every image has only the taget specific compilers and rubies, care has to be taken, that only rake tasks are triggered, that belong to the specific target.
12
+ See the README.md for more information.
13
+ * Ensure the separate docker images always use as much as possible common docker images layers to avoid increased download sizes.
14
+ * Pass GEM_PRIVATE_KEY_PASSPHRASE to the container.
15
+ * Update JRuby to 9.2.9.0 and native CRuby to 2.5.7.
16
+ * Create empty ~/.gem to be used for gem signing key.
17
+ * Ensure terminal is in cooked mode after build.
18
+ This fixes terminal misconfiguration after parallel builds.
19
+ * Raise Windows-API to Vista (affects ruby < 2.6 only)
20
+ * Use posix pthread for mingw so that C++ standard library for thread could be available such as std::thread, std::mutex, so on.
21
+ * Make the system to have GLIBC 2.12 instead of 2.23 so that generated ruby package can run on CentOS 6 with GLIBC 2.12
22
+
23
+
1
24
  0.7.2 / 2019-03-18
2
25
  ------------------
3
26
  * Fix missing libruby.a of cross rubies. Fixes #26
data/README.md CHANGED
@@ -16,7 +16,7 @@ Install docker natively on Linux:
16
16
 
17
17
  $ sudo apt-get install docker.io
18
18
 
19
- ... or install [docker-toolbox for Windows and OSX](https://www.docker.com/docker-toolbox) or boot2docker on [Windows](https://github.com/boot2docker/windows-installer/releases) or [OS X](https://github.com/boot2docker/osx-installer/releases) .
19
+ ... or install [docker-toolbox for Windows and OSX](https://github.com/docker/toolbox/releases) or boot2docker on [Windows](https://github.com/boot2docker/windows-installer/releases) or [OS X](https://github.com/boot2docker/osx-installer/releases) .
20
20
 
21
21
  Install rake-compiler-dock as a gem. The docker image is downloaded later on demand:
22
22
 
@@ -34,16 +34,19 @@ Rake-compiler-dock provides the necessary tools to build Ruby extensions for Win
34
34
  It is intended to be used in conjunction with [rake-compiler's](https://github.com/rake-compiler/rake-compiler) cross build capability.
35
35
  Your Rakefile should enable cross compilation like so:
36
36
 
37
- Rake::ExtensionTask.new('my_extension', my_gem_spec) do |ext|
37
+ exttask = Rake::ExtensionTask.new('my_extension', my_gem_spec) do |ext|
38
38
  ext.cross_compile = true
39
39
  ext.cross_platform = %w[x86-mingw32 x64-mingw32 x86-linux x86_64-linux]
40
40
  end
41
41
 
42
- It may also be used to build ffi based binary gems like [libusb](https://github.com/larskanis/libusb), but currently doesn't provide any additional build helpers for this use case, beyond docker invocation and cross compilers.
42
+ See below, how to invoke cross builds in your Rakefile.
43
+
44
+ Additionally it may also be used to build ffi based binary gems like [libusb](https://github.com/larskanis/libusb), but currently doesn't provide any additional build helpers for this use case, beyond docker invocation and cross compilers.
43
45
 
44
46
  ### Interactive Usage
45
47
 
46
48
  Rake-compiler-dock offers the shell command `rake-compiler-dock` and a [ruby API](http://www.rubydoc.info/gems/rake-compiler-dock/RakeCompilerDock) for issuing commands within the docker image, described below.
49
+ There dedicated are images for `x86-mingw32`, `x64-mingw32`, `x86-linux`, `x86_64-linux` and `jruby` targets.
47
50
 
48
51
  `rake-compiler-dock` without arguments starts an interactive shell session.
49
52
  This is best suited to try out and debug a build.
@@ -55,16 +58,22 @@ But note, that all other changes to the file system of the container are dropped
55
58
  All commands are executed with the same user and group of the host.
56
59
  This is done by copying user account data into the container and sudo to it.
57
60
 
58
- To build x86 and x64 Windows and Linux binary gems interactively, it can be called like this:
61
+ To build x86 Windows and x86_64 Linux binary gems interactively, it can be called like this:
59
62
 
60
63
  user@host:$ cd your-gem-dir/
61
- user@host:$ rake-compiler-dock # this enters a container with an interactive shell
64
+ user@host:$ rake-compiler-dock # this enters a container with an interactive shell for x86 Windows (default)
62
65
  user@5b53794ada92:$ bundle
63
66
  user@5b53794ada92:$ rake cross native gem
64
67
  user@5b53794ada92:$ exit
65
68
  user@host:$ ls pkg/*.gem
66
- your-gem-1.0.0.gem your-gem-1.0.0-x64-mingw32.gem your-gem-1.0.0-x86-mingw32.gem
67
- your-gem-1.0.0-x86_64-linux.gem your-gem-1.0.0-x86-linux.gem
69
+ your-gem-1.0.0.gem your-gem-1.0.0-x86-mingw32.gem
70
+
71
+ user@host:$ RCD_PLATFORM=x86_64-linux rake-compiler-dock # this enters a container for amd64 Linux target
72
+ user@adc55b2b92a9:$ bundle
73
+ user@adc55b2b92a9:$ rake cross native gem
74
+ user@adc55b2b92a9:$ exit
75
+ user@host:$ ls pkg/*.gem
76
+ your-gem-1.0.0.gem your-gem-1.0.0-x86_64-linux.gem
68
77
 
69
78
  Or non-interactive:
70
79
 
@@ -105,13 +114,52 @@ This can be done like this:
105
114
  task 'gem:native' do
106
115
  require 'rake_compiler_dock'
107
116
  sh "bundle package" # Avoid repeated downloads of gems by using gem files from the host.
108
- RakeCompilerDock.sh "bundle --local && rake cross native gem"
117
+ %w[ x86-mingw32 x64-mingw32 x86-linux x86_64-linux ].each do |plat|
118
+ RakeCompilerDock.sh "bundle --local && rake native:#{plat} gem", platform: plat
119
+ end
109
120
  RakeCompilerDock.sh "bundle --local && rake java gem", rubyvm: :jruby
110
121
  end
111
122
 
123
+ This runs the `bundle` and `rake` commands once for each platform.
124
+ That is once for the jruby gems and 4 times for the specified MRI platforms.
125
+
126
+ ### Run builds in parallel
127
+
128
+ rake-compiler-dock uses dedicated docker images per build target (since rake-compiler-dock-1.0).
129
+ Because each target runs in a separate docker container, it is simple to run all targets in parallel.
130
+ The following example defines `rake gem:native` as a multitask and separates the preparation which should run only once.
131
+ It also shows how gem signing can be done with parallel builds.
132
+ Please note, that parallel builds only work reliable, if the specific platform gem is requested (instead of just "rake gem").
133
+
134
+ ```ruby
135
+ namespace "gem" do
136
+ exttask.cross_platform.each do |plat|
137
+ desc "Build the native binary gems"
138
+ multitask 'native' => plat
139
+
140
+ task 'prepare' do
141
+ require 'rake_compiler_dock'
142
+ sh "cp ~/.gem/gem-*.pem build/gem/ || true"
143
+ require 'io/console'
144
+ ENV["GEM_PRIVATE_KEY_PASSPHRASE"] = STDIN.getpass("Enter passphrase of gem signature key: ")
145
+ end
146
+
147
+ task plat => 'prepare' do
148
+ RakeCompilerDock.sh <<-EOT, platform: plat
149
+ (cp build/gem/gem-*.pem ~/.gem/ || true) &&
150
+ bundle --local &&
151
+ rake native:#{plat} pkg/#{exttask.gem_spec.full_name}-#{plat}.gem
152
+ EOT
153
+ end
154
+ end
155
+ end
156
+ ```
157
+
158
+ ### Add to your Gemfile
159
+
112
160
  Rake-compiler-dock uses [semantic versioning](http://semver.org/), so you should add it into your Gemfile, to make sure, that future changes will not break your build.
113
161
 
114
- gem 'rake-compiler-dock', '~> 0.7.0'
162
+ gem 'rake-compiler-dock', '~> 1.0'
115
163
 
116
164
  See [the wiki](https://github.com/rake-compiler/rake-compiler-dock/wiki/Projects-using-rake-compiler-dock) for projects which make use of rake-compiler-dock.
117
165
 
@@ -122,14 +170,18 @@ Rake-compiler-dock makes use of several environment variables.
122
170
 
123
171
  The following variables are recognized by rake-compiler-dock:
124
172
 
125
- * `RCD_RUBYVM` - The flavour of docker image to be used.
173
+ * `RCD_RUBYVM` - The ruby VM and toolchain to be used.
126
174
  Must be one of `mri`, `jruby`.
175
+ * `RCD_PLATFORM` - The target rubygems platform.
176
+ Must be a space separated list out of `x86-mingw32`, `x64-mingw32`, `x86-linux` and `x86_64-linux`.
177
+ It is ignored when `rubyvm` is set to `:jruby`.
127
178
  * `RCD_IMAGE` - The docker image that is downloaded and started.
128
179
  Defaults to "larskanis/rake-compiler-dock:IMAGE_VERSION" with an image version that is determined by the gem version.
129
180
 
130
181
  The following variables are passed through to the docker container without modification:
131
182
 
132
183
  * `http_proxy`, `https_proxy`, `ftp_proxy` - See [Frequently asked questions](https://github.com/rake-compiler/rake-compiler-dock/wiki/FAQ) for more details.
184
+ * `GEM_PRIVATE_KEY_PASSPHRASE` - To avoid interactive password prompts in the container.
133
185
 
134
186
  The following variables are provided to the running docker container:
135
187
 
data/Rakefile CHANGED
@@ -1,13 +1,45 @@
1
+ require 'erb'
2
+ require "rake/clean"
1
3
  require "rake_compiler_dock"
2
- require "rake_compiler_dock/gem_helper"
4
+ require_relative "build/gem_helper"
5
+ require_relative "build/parallel_docker_build"
3
6
 
4
7
  RakeCompilerDock::GemHelper.install_tasks
5
8
 
6
- task :build do
7
- sh "docker build -t larskanis/rake-compiler-dock-mri:#{RakeCompilerDock::IMAGE_VERSION} -f Dockerfile.mri ."
8
- sh "docker build -t larskanis/rake-compiler-dock-jruby:#{RakeCompilerDock::IMAGE_VERSION} -f Dockerfile.jruby ."
9
+ namespace :build do
10
+ platforms = [
11
+ ["x86-mingw32", "i686-w64-mingw32"],
12
+ ["x64-mingw32", "x86_64-w64-mingw32"],
13
+ ["x86-linux", "i686-linux-gnu"],
14
+ ["x86_64-linux", "x86_64-linux-gnu"],
15
+ ]
16
+ platforms.each do |platform, target|
17
+ sdf = "Dockerfile.mri.#{platform}"
18
+ desc "Build image for platform #{platform}"
19
+ task platform => sdf
20
+ task sdf do
21
+ sh "docker build -t larskanis/rake-compiler-dock-mri-#{platform}:#{RakeCompilerDock::IMAGE_VERSION} -f Dockerfile.mri.#{platform} ."
22
+ end
23
+
24
+ df = ERB.new(File.read("Dockerfile.mri.erb")).result(binding)
25
+ File.write(sdf, df)
26
+ CLEAN.include(sdf)
27
+ end
28
+
29
+ desc "Build image for JRuby"
30
+ task :jruby => "Dockerfile.jruby"
31
+ task "Dockerfile.jruby" do
32
+ sh "docker build -t larskanis/rake-compiler-dock-jruby:#{RakeCompilerDock::IMAGE_VERSION} -f Dockerfile.jruby ."
33
+ end
34
+
35
+ RakeCompilerDock::ParallelDockerBuild.new(platforms.map{|pl, _| "Dockerfile.mri.#{pl}" } + ["Dockerfile.jruby"], workdir: "tmp/docker")
36
+
37
+ desc "Build images for all platforms in parallel"
38
+ multitask :all => platforms.map(&:first) + ["jruby"]
9
39
  end
10
40
 
41
+ task :build => "build:all"
42
+
11
43
  desc "Run tests"
12
44
  task :test do
13
45
  sh "ruby -w -W2 -I. -Ilib -e \"#{Dir["test/test_*.rb"].map{|f| "require '#{f}';"}.join}\" -- -v"