Skip to content

Commit e7488fc

Browse files
authored
Merge pull request #24 from sqreen/cross-compile
Cross compile
2 parents 6bbb084 + 41ffebf commit e7488fc

24 files changed

+350
-138
lines changed

.github/workflows/build.yml

+96-42
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
rubocop:
77
name: Lint (Rubocop)
88
runs-on: ubuntu-20.04
9-
container: ruby:2.3
9+
container: ruby:2.6
1010
steps:
1111
- name: Checkout
1212
uses: actions/checkout@v2
@@ -30,7 +30,7 @@ jobs:
3030
outputs:
3131
GEM_VERSION: ${{ steps.set-metadata.outputs.GEM_VERSION }}
3232
runs-on: ubuntu-20.04
33-
container: ruby:2.3
33+
container: ruby:2.6
3434
steps:
3535
- name: Checkout
3636
uses: actions/checkout@v2
@@ -39,15 +39,15 @@ jobs:
3939
- name: Set metadata
4040
id: set-metadata
4141
run: |
42-
bundle exec ruby -e 'puts RUBY_PLATFORM' | tee ruby_platform
42+
./libexec/metadata ruby_platform | tee ruby_platform
4343
echo "::set-output name=RUBY_PLATFORM::$(cat ruby_platform)"
44-
bundle exec ruby -e 'puts Gem.platforms.last.to_s' | tee gem_platform
44+
./libexec/metadata gem_platform | tee gem_platform
4545
echo "::set-output name=GEM_PLATFORM::$(cat gem_platform)"
46-
bundle exec ruby -e 'puts Libv8::Node::VERSION' | tee gem_version
46+
./libexec/metadata gem_version | tee gem_version
4747
echo "::set-output name=GEM_VERSION::$(cat gem_version)"
48-
bundle exec ruby -e 'puts Libv8::Node::NODE_VERSION' | tee node_version
48+
./libexec/metadata node_version | tee node_version
4949
echo "::set-output name=NODE_VERSION::$(cat node_version)"
50-
bundle exec ruby -e 'puts Libv8::Node::LIBV8_VERSION' | tee libv8_version
50+
./libexec/metadata libv8_version | tee libv8_version
5151
echo "::set-output name=LIBV8_VERSION::$(cat libv8_version)"
5252
- name: Download Node.js
5353
run: |
@@ -57,7 +57,7 @@ jobs:
5757
./libexec/extract-node ${{ steps.set-metadata.outputs.NODE_VERSION }}
5858
- name: Validate V8 version
5959
run: |
60-
ruby -e 'h = File.read("src/node-${{ steps.set-metadata.outputs.NODE_VERSION }}/deps/v8/include/v8-version.h"); eval h.each_line.with_object([]) { |l, e| l =~ /#define (V8_[A-Z_]+)\s(\d+)/ && e << "#{$1} = #{$2}" }.join(";"); puts "#{V8_MAJOR_VERSION}.#{V8_MINOR_VERSION}.#{V8_BUILD_NUMBER}.#{V8_PATCH_LEVEL}"' | tee libv8_version_h
60+
./libexec/metadata libv8_version_h | tee libv8_version_h
6161
diff libv8_version_h libv8_version
6262
- name: Build gem
6363
run: |
@@ -86,15 +86,15 @@ jobs:
8686
- name: Set metadata
8787
id: set-metadata
8888
run: |
89-
bundle exec ruby -e 'puts RUBY_PLATFORM' | tee ruby_platform
89+
./libexec/metadata ruby_platform | tee ruby_platform
9090
echo "::set-output name=RUBY_PLATFORM::$(cat ruby_platform)"
91-
bundle exec ruby -e 'puts Gem.platforms.last.to_s' | tee gem_platform
91+
./libexec/metadata gem_platform | tee gem_platform
9292
echo "::set-output name=GEM_PLATFORM::$(cat gem_platform)"
93-
bundle exec ruby -e 'puts Libv8::Node::VERSION' | tee gem_version
93+
./libexec/metadata gem_version | tee gem_version
9494
echo "::set-output name=GEM_VERSION::$(cat gem_version)"
95-
bundle exec ruby -e 'puts Libv8::Node::NODE_VERSION' | tee node_version
95+
./libexec/metadata node_version | tee node_version
9696
echo "::set-output name=NODE_VERSION::$(cat node_version)"
97-
bundle exec ruby -e 'puts Libv8::Node::LIBV8_VERSION' | tee libv8_version
97+
./libexec/metadata libv8_version | tee libv8_version
9898
echo "::set-output name=LIBV8_VERSION::$(cat libv8_version)"
9999
- name: Download Node.js
100100
run: |
@@ -104,7 +104,7 @@ jobs:
104104
./libexec/extract-node ${{ steps.set-metadata.outputs.NODE_VERSION }}
105105
- name: Validate V8 version
106106
run: |
107-
ruby -e 'h = File.read("src/node-${{ steps.set-metadata.outputs.NODE_VERSION }}/deps/v8/include/v8-version.h"); eval h.each_line.with_object([]) { |l, e| l =~ /#define (V8_[A-Z_]+)\s(\d+)/ && e << "#{$1} = #{$2}" }.join(";"); puts "#{V8_MAJOR_VERSION}.#{V8_MINOR_VERSION}.#{V8_BUILD_NUMBER}.#{V8_PATCH_LEVEL}"' | tee libv8_version_h
107+
./libexec/metadata libv8_version_h | tee libv8_version_h
108108
diff libv8_version_h libv8_version
109109
- name: Build V8
110110
run: |
@@ -134,58 +134,94 @@ jobs:
134134
matrix:
135135
platform:
136136
- amd64
137-
# arm64
137+
- arm64
138138
# arm
139139
# ppc64le
140140
# s390x
141141
libc:
142142
- gnu
143-
- musl
143+
include:
144+
- platform: amd64
145+
libc: musl
144146
name: Build (linux)
145147
outputs:
146148
GEM_VERSION: ${{ steps.set-metadata.outputs.GEM_VERSION }}
147149
runs-on: ubuntu-20.04
148150
steps:
149-
- name: Enable ${{ matrix.platform }} platform
150-
id: qemu
151-
if: ${{ matrix.platform != 'amd64' }}
151+
- name: Set cross-compilation platform
152+
id: platform
152153
run: |
153-
docker run --privileged --rm tonistiigi/binfmt:latest --install ${{ matrix.platform }} | tee platforms.json
154-
echo "::set-output name=platforms::$(cat platforms.json)"
154+
case ${{ matrix.platform }} in
155+
amd64)
156+
case ${{ matrix.libc }} in
157+
gnu)
158+
echo 'x86_64-linux-gnu'
159+
;;
160+
musl)
161+
echo 'x86_64-alpine-linux-musl'
162+
;;
163+
esac
164+
;;
165+
arm64)
166+
echo 'aarch64-linux-gnu'
167+
;;
168+
esac | tee target_platform
169+
case ${{ matrix.platform }} in
170+
amd64)
171+
case ${{ matrix.libc }} in
172+
gnu)
173+
echo 'x86_64-linux'
174+
;;
175+
musl)
176+
echo 'x86_64-linux-musl'
177+
;;
178+
esac
179+
;;
180+
arm64)
181+
echo 'aarch64-linux'
182+
;;
183+
esac | tee ruby_target_platform
184+
echo "::set-output name=target_platform::$(cat target_platform)"
185+
echo "::set-output name=ruby_target_platform::$(cat ruby_target_platform)"
155186
- name: Start container
156187
id: container
157188
run: |
158189
case ${{ matrix.libc }} in
159190
gnu)
160-
echo 'ruby:2.3'
191+
echo 'ruby:2.4'
161192
;;
162193
musl)
163194
echo 'ruby:2.4-alpine'
164195
;;
165-
esac > container_image
196+
esac | tee container_image
166197
echo "::set-output name=image::$(cat container_image)"
167-
docker run --rm -d -v "${PWD}":"${PWD}" -w "${PWD}" --platform linux/${{ matrix.platform }} $(cat container_image) /bin/sleep 64d | tee container_id
198+
docker run --rm -d -v "${PWD}":"${PWD}" -w "${PWD}" --platform linux/amd64 -e RUBY_TARGET_PLATFORM=${{ steps.platform.outputs.ruby_target_platform }} -e TARGET_PLATFORM=${{ steps.platform.outputs.target_platform }} $(cat container_image) /bin/sleep 64d | tee container_id
168199
docker exec -w "${PWD}" $(cat container_id) uname -a
169200
echo "::set-output name=id::$(cat container_id)"
170201
- name: Install Alpine system dependencies
171202
if: ${{ matrix.libc == 'musl' }}
172-
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base linux-headers bash python2 python3 git curl tar clang binutils-gold
203+
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base linux-headers bash python2 python3 git curl tar
204+
- name: Install Debian cross-compiler
205+
if: ${{ matrix.libc == 'gnu' && matrix.platform != 'amd64' }}
206+
run: |
207+
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apt-get update
208+
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apt-get install -y binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
173209
- name: Checkout
174210
uses: actions/checkout@v2
175211
- name: Bundle
176212
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle install
177213
- name: Set metadata
178214
id: set-metadata
179215
run: |
180-
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec ruby -e 'puts RUBY_PLATFORM' | tee ruby_platform
216+
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/metadata ruby_platform | tee ruby_platform
181217
echo "::set-output name=RUBY_PLATFORM::$(cat ruby_platform)"
182-
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec ruby -e 'puts Gem::Platform.local.tap { |p| RUBY_PLATFORM =~ /musl/ && p.version.nil? and p.instance_eval { @version = "musl" } }' | tee gem_platform
218+
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/metadata gem_platform | tee gem_platform
183219
echo "::set-output name=GEM_PLATFORM::$(cat gem_platform)"
184-
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec ruby -e 'puts Libv8::Node::VERSION' | tee gem_version
220+
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/metadata gem_version | tee gem_version
185221
echo "::set-output name=GEM_VERSION::$(cat gem_version)"
186-
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec ruby -e 'puts Libv8::Node::NODE_VERSION' | tee node_version
222+
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/metadata node_version | tee node_version
187223
echo "::set-output name=NODE_VERSION::$(cat node_version)"
188-
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec ruby -e 'puts Libv8::Node::LIBV8_VERSION' | tee libv8_version
224+
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/metadata libv8_version | tee libv8_version
189225
echo "::set-output name=LIBV8_VERSION::$(cat libv8_version)"
190226
- name: Download Node.js
191227
run: |
@@ -195,7 +231,7 @@ jobs:
195231
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/extract-node ${{ steps.set-metadata.outputs.NODE_VERSION }}
196232
- name: Validate V8 version
197233
run: |
198-
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ruby -e 'h = File.read("src/node-${{ steps.set-metadata.outputs.NODE_VERSION }}/deps/v8/include/v8-version.h"); eval h.each_line.with_object([]) { |l, e| l =~ /#define (V8_[A-Z_]+)\s(\d+)/ && e << "#{$1} = #{$2}" }.join(";"); puts "#{V8_MAJOR_VERSION}.#{V8_MINOR_VERSION}.#{V8_BUILD_NUMBER}.#{V8_PATCH_LEVEL}"' | tee libv8_version_h
234+
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/metadata libv8_version_h | tee libv8_version_h
199235
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} diff libv8_version_h libv8_version
200236
- name: Build V8
201237
run: |
@@ -208,22 +244,22 @@ jobs:
208244
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/inject-libv8 ${{ steps.set-metadata.outputs.NODE_VERSION }}
209245
- name: Build binary gem
210246
run: |
211-
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake binary
247+
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake binary[${{ steps.platform.outputs.ruby_target_platform }}]
212248
- name: Upload V8
213249
uses: actions/upload-artifact@v1
214250
with:
215-
name: v8-${{ steps.set-metadata.outputs.LIBV8_VERSION }}-${{ steps.set-metadata.outputs.GEM_PLATFORM }}
251+
name: v8-${{ steps.set-metadata.outputs.LIBV8_VERSION }}-${{ steps.platform.outputs.ruby_target_platform }}
216252
path: vendor
217253
- name: Upload gem
218254
uses: actions/upload-artifact@v1
219255
with:
220-
name: gem-${{ steps.set-metadata.outputs.GEM_VERSION }}-${{ steps.set-metadata.outputs.GEM_PLATFORM }}
256+
name: gem-${{ steps.set-metadata.outputs.GEM_VERSION }}-${{ steps.platform.outputs.ruby_target_platform }}
221257
path: pkg
222258
test-ruby:
223259
name: Test (ruby)
224260
needs: build-ruby
225261
runs-on: ubuntu-20.04
226-
container: ruby:2.3
262+
container: ruby:2.5
227263
steps:
228264
- name: Set metadata
229265
id: set-metadata
@@ -236,12 +272,12 @@ jobs:
236272
name: gem-${{ needs.build-ruby.outputs.GEM_VERSION }}-ruby
237273
path: pkg
238274
- name: Install gem
239-
run: gem install pkg/libv8-node-${{ needs.build-ruby.outputs.GEM_VERSION }}.gem
275+
run: gem install --verbose pkg/libv8-node-${{ needs.build-ruby.outputs.GEM_VERSION }}.gem
240276
- name: Test with mini_racer
241277
run: |
242278
git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1
243279
cd test/mini_racer
244-
git fetch origin refs/pull/186/head
280+
git fetch origin refs/pull/210/head
245281
git checkout FETCH_HEAD
246282
git reset --hard
247283
git clean -f -d -x
@@ -276,7 +312,7 @@ jobs:
276312
run: |
277313
git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1
278314
cd test/mini_racer
279-
git fetch origin refs/pull/186/head
315+
git fetch origin refs/pull/210/head
280316
git checkout FETCH_HEAD
281317
git reset --hard
282318
git clean -f -d -x
@@ -288,6 +324,11 @@ jobs:
288324
strategy:
289325
fail-fast: false
290326
matrix:
327+
version:
328+
- '2.5'
329+
- '2.6'
330+
- '2.7'
331+
- '3.0'
291332
platform:
292333
- amd64
293334
# arm64
@@ -297,6 +338,19 @@ jobs:
297338
libc:
298339
- gnu
299340
- musl
341+
include:
342+
- version: '2.5'
343+
platform: 'arm64'
344+
libc: 'gnu'
345+
- version: '2.6'
346+
platform: 'arm64'
347+
libc: 'gnu'
348+
- version: '2.7'
349+
platform: 'arm64'
350+
libc: 'gnu'
351+
- version: '3.0'
352+
platform: 'arm64'
353+
libc: 'gnu'
300354
name: Test (linux)
301355
needs: build-linux
302356
runs-on: ubuntu-20.04
@@ -312,12 +366,12 @@ jobs:
312366
run: |
313367
case ${{ matrix.libc }} in
314368
gnu)
315-
echo 'ruby:2.3'
369+
echo 'ruby:${{ matrix.version }}'
316370
;;
317371
musl)
318-
echo 'ruby:2.7-alpine'
372+
echo 'ruby:${{ matrix.version }}-alpine'
319373
;;
320-
esac > container_image
374+
esac | tee container_image
321375
echo "::set-output name=image::$(cat container_image)"
322376
docker run --rm -d -v "${PWD}":"${PWD}" -w "${PWD}" --platform linux/${{ matrix.platform }} $(cat container_image) /bin/sleep 64d | tee container_id
323377
docker exec -w "${PWD}" $(cat container_id) uname -a
@@ -341,7 +395,7 @@ jobs:
341395
run: |
342396
git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1
343397
cd test/mini_racer
344-
git fetch origin refs/pull/186/head
398+
git fetch origin refs/pull/210/head
345399
git checkout FETCH_HEAD
346400
git reset --hard
347401
git clean -f -d -x

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
Makefile
77
/ext/libv8-node/.location.yml
88
/test/mini_racer
9+
*.nix
10+
*.vim
11+
.envrc

Dockerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
ARG RUBY_VERSION=2.3
1+
ARG RUBY_VERSION=2.4
22
FROM ruby:${RUBY_VERSION}
33

4-
RUN test ! -f /etc/alpine-release || apk add --no-cache build-base bash python2 python3 git curl tar clang binutils-gold
4+
RUN test ! -f /etc/alpine-release || apk add --no-cache build-base bash python2 python3 git curl tar
55

66
RUN mkdir -p /code
77
WORKDIR /code
88

9-
ARG NODE_VERSION=15.14.0
9+
ARG NODE_VERSION=16.10.0
1010

1111
COPY libexec/download-node /code/libexec/
1212
RUN ./libexec/download-node ${NODE_VERSION}

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ NODE_VERSION := $(shell ./libexec/metadata node_version)
55
all:
66

77
pkg/libv8-node-$(VERSION)-x86_64-linux.gem:
8-
docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.3 --progress plain -t libv8-node:gnu .
8+
docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.4 --progress plain -t libv8-node:gnu .
99
docker run --platform linux/amd64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:gnu cp $@ /pkg/
1010

1111
pkg/libv8-node-$(VERSION)-x86_64-linux-musl.gem:
1212
docker build --platform linux/amd64 --build-arg RUBY_VERSION=2.4-alpine --progress plain -t libv8-node:musl .
1313
docker run --platform linux/amd64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:musl cp $@ /pkg/
1414

1515
pkg/libv8-node-$(VERSION)-aarch64-linux.gem:
16-
docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.3 --progress plain -t libv8-node:gnu .
16+
docker build --platform linux/arm64 --build-arg RUBY_VERSION=2.4 --progress plain -t libv8-node:gnu .
1717
docker run --platform linux/arm64 --rm -it -v "$(PWD)/pkg":/pkg libv8-node:gnu cp $@ /pkg/
1818

1919
pkg/libv8-node-$(VERSION)-aarch64-linux-musl.gem:

0 commit comments

Comments
 (0)