-
Notifications
You must be signed in to change notification settings - Fork 27
457 lines (456 loc) · 18.6 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
name: Build
on:
- pull_request
- push
jobs:
rubocop:
name: Lint (Rubocop)
runs-on: ubuntu-20.04
container: ruby:3.1
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Bundle
run: bundle install
- name: Rubocop
run: bundle exec rubocop -f simple
shellcheck:
name: Lint (Shellcheck)
runs-on: ubuntu-20.04
container: debian:10
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install shellcheck
run: apt-get update && apt-get install -y shellcheck
- name: Shellcheck
run: shellcheck libexec/*
build-ruby:
name: Build (ruby)
outputs:
GEM_VERSION: ${{ steps.set-metadata.outputs.GEM_VERSION }}
runs-on: ubuntu-20.04
container: ruby:3.1
steps:
- name: Update Rubygems and Bundler
run: |
gem update --system 3.3.26
gem install bundler -v '~> 2.3.26'
- name: Checkout
uses: actions/checkout@v2
- name: Bundle
run: bundle install
- name: Set metadata
id: set-metadata
run: |
./libexec/metadata ruby_platform | tee ruby_platform
echo "::set-output name=RUBY_PLATFORM::$(cat ruby_platform)"
./libexec/metadata gem_platform | tee gem_platform
echo "::set-output name=GEM_PLATFORM::$(cat gem_platform)"
./libexec/metadata gem_version | tee gem_version
echo "::set-output name=GEM_VERSION::$(cat gem_version)"
./libexec/metadata node_version | tee node_version
echo "::set-output name=NODE_VERSION::$(cat node_version)"
./libexec/metadata libv8_version | tee libv8_version
echo "::set-output name=LIBV8_VERSION::$(cat libv8_version)"
- name: Download Node.js
run: |
./libexec/download-node ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Extract Node.js
run: |
./libexec/extract-node ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Validate V8 version
run: |
./libexec/metadata libv8_version_h | tee libv8_version_h
diff libv8_version_h libv8_version
- name: Build gem
run: |
bundle exec rake build
- name: Upload gem
uses: actions/upload-artifact@v3
with:
name: gem-${{ steps.set-metadata.outputs.GEM_VERSION }}-ruby
path: pkg
build-darwin:
strategy:
fail-fast: false
matrix:
platform:
- x86_64
- arm64
name: Build (darwin)
outputs:
GEM_VERSION: ${{ steps.set-metadata.outputs.GEM_VERSION }}
runs-on: macos-12
env:
TARGET_PLATFORM: ${{ matrix.platform }}-darwin
RUBY_TARGET_PLATFORM: ${{ matrix.platform }}-darwin
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Bundle
run: bundle install
- name: Set metadata
id: set-metadata
run: |
./libexec/metadata ruby_platform | tee ruby_platform
echo "RUBY_PLATFORM=$(cat ruby_platform)" >> $GITHUB_OUTPUT
./libexec/metadata gem_platform | tee gem_platform
echo "GEM_PLATFORM=$(cat gem_platform)" >> $GITHUB_OUTPUT
./libexec/metadata gem_version | tee gem_version
echo "GEM_VERSION=$(cat gem_version)" >> $GITHUB_OUTPUT
./libexec/metadata node_version | tee node_version
echo "NODE_VERSION=$(cat node_version)" >> $GITHUB_OUTPUT
./libexec/metadata libv8_version | tee libv8_version
echo "LIBV8_VERSION=$(cat libv8_version)" >> $GITHUB_OUTPUT
- name: Download Node.js
run: |
./libexec/download-node ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Extract Node.js
run: |
./libexec/extract-node ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Validate V8 version
run: |
./libexec/metadata libv8_version_h | tee libv8_version_h
diff libv8_version_h libv8_version
- name: Build V8
run: |
./libexec/build-libv8 ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Build Monolith
run: |
./libexec/build-monolith ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Inject V8
run: |
./libexec/inject-libv8 ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Test V8 in C++
if: matrix.platform != 'arm64'
run: |
cd test/gtest
cmake -S . -B build
cd build
cmake --build .
./c_v8_tests
- name: Build binary gem
run: |
bundle exec rake binary
- name: Upload V8
uses: actions/upload-artifact@v3
with:
name: v8-${{ steps.set-metadata.outputs.LIBV8_VERSION }}-${{ steps.set-metadata.outputs.GEM_PLATFORM }}
path: vendor
- name: Upload gem
uses: actions/upload-artifact@v3
with:
name: gem-${{ steps.set-metadata.outputs.GEM_VERSION }}-${{ steps.set-metadata.outputs.GEM_PLATFORM }}
path: pkg
build-linux:
strategy:
fail-fast: false
matrix:
platform:
- amd64
- arm64
# arm
# ppc64le
# s390x
libc:
- gnu
include:
- platform: amd64
libc: musl
name: Build (linux)
outputs:
GEM_VERSION: ${{ steps.set-metadata.outputs.GEM_VERSION }}
runs-on: ubuntu-20.04
steps:
- name: Set cross-compilation platform
id: platform
run: |
case ${{ matrix.platform }} in
amd64)
case ${{ matrix.libc }} in
gnu)
echo 'x86_64-linux-gnu'
;;
musl)
echo 'x86_64-alpine-linux-musl'
;;
esac
;;
arm64)
echo 'aarch64-linux-gnu'
;;
esac | tee target_platform
case ${{ matrix.platform }} in
amd64)
case ${{ matrix.libc }} in
gnu)
echo 'x86_64-linux'
;;
musl)
echo 'x86_64-linux-musl'
;;
esac
;;
arm64)
echo 'aarch64-linux'
;;
esac | tee ruby_target_platform
echo "::set-output name=target_platform::$(cat target_platform)"
echo "::set-output name=ruby_target_platform::$(cat ruby_target_platform)"
- name: Start container
id: container
run: |
case ${{ matrix.libc }} in
gnu)
echo 'ruby:3.1'
;;
musl)
echo 'ruby:3.1-alpine'
;;
esac | tee container_image
echo "::set-output name=image::$(cat container_image)"
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
docker exec -w "${PWD}" $(cat container_id) uname -a
echo "::set-output name=id::$(cat container_id)"
- name: Install Alpine system dependencies
if: ${{ matrix.libc == 'musl' }}
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base linux-headers bash python3 git curl tar cmake clang ccache
- name: Install Debian system dependencies
if: ${{ matrix.libc == 'gnu' }}
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apt-get update
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apt-get install -y cmake clang ccache
- name: Install Debian cross-compiler
if: ${{ matrix.libc == 'gnu' && matrix.platform != 'amd64' }}
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apt-get install -y binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- name: Update Rubygems and Bundler
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem update --system 3.3.26
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem install bundler -v '~> 2.3.26'
- name: Checkout
uses: actions/checkout@v2
- name: Bundle
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle install
- name: Set metadata
id: set-metadata
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/metadata ruby_platform | tee ruby_platform
echo "::set-output name=RUBY_PLATFORM::$(cat ruby_platform)"
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/metadata gem_platform | tee gem_platform
echo "::set-output name=GEM_PLATFORM::$(cat gem_platform)"
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/metadata gem_version | tee gem_version
echo "::set-output name=GEM_VERSION::$(cat gem_version)"
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/metadata node_version | tee node_version
echo "::set-output name=NODE_VERSION::$(cat node_version)"
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/metadata libv8_version | tee libv8_version
echo "::set-output name=LIBV8_VERSION::$(cat libv8_version)"
- name: Download Node.js
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/download-node ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Extract Node.js
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/extract-node ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Validate V8 version
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/metadata libv8_version_h | tee libv8_version_h
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} diff libv8_version_h libv8_version
- name: Build V8
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/build-libv8 ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Build Monolith
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/build-monolith ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Inject V8
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/inject-libv8 ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Test V8 in C++
if: matrix.platform != 'arm64'
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bash -c "cd test/gtest && cmake -S . -B build && cd build && cmake --build . && ctest"
- name: Build binary gem
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake binary[${{ steps.platform.outputs.ruby_target_platform }}]
- name: Upload V8
uses: actions/upload-artifact@v3
with:
name: v8-${{ steps.set-metadata.outputs.LIBV8_VERSION }}-${{ steps.platform.outputs.ruby_target_platform }}
path: vendor
- name: Upload gem
uses: actions/upload-artifact@v3
with:
name: gem-${{ steps.set-metadata.outputs.GEM_VERSION }}-${{ steps.platform.outputs.ruby_target_platform }}
path: pkg
test-ruby:
strategy:
fail-fast: false
matrix:
platform:
- amd64
# other platforms would need emulation, which is way too slow
container:
- image: ruby:3.1
version: '3.1'
libc: gnu
- image: ruby:3.1-alpine
version: '3.1'
libc: musl
- image: ruby:3.2
version: '3.2'
libc: gnu
- image: ruby:3.2-alpine
version: '3.2'
libc: musl
- image: ruby:3.3
version: '3.3'
libc: gnu
- image: ruby:3.3-alpine
version: '3.3'
libc: musl
name: Test (ruby) (${{ matrix.container.version }}, ${{ matrix.platform }}, ${{ matrix.container.libc }})
needs: build-ruby
runs-on: ubuntu-20.04
container: ${{ matrix.container.image }}
steps:
- name: Install Alpine system dependencies
if: ${{ matrix.container.libc == 'musl' }}
run: apk add --no-cache build-base linux-headers bash python3 git curl tar
- name: Update Rubygems and Bundler
run: |
gem update --system 3.3.26
gem install bundler -v '~> 2.3.26'
- name: Set metadata
id: set-metadata
run: |
ruby -e 'puts Gem.platforms.last.to_s' | tee gem_platform
echo "::set-output name=GEM_PLATFORM::$(cat gem_platform)"
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: gem-${{ needs.build-ruby.outputs.GEM_VERSION }}-ruby
path: pkg
- name: Install gem
run: gem install --verbose pkg/libv8-node-${{ needs.build-ruby.outputs.GEM_VERSION }}.gem
- name: Test with mini_racer
run: |
export BUNDLE_FORCE_RUBY_PLATFORM=y
git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1
cd test/mini_racer
ruby -i -ne '$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"${{ needs.build-ruby.outputs.GEM_VERSION }}\"\n") : print' lib/mini_racer/version.rb
ruby -i -ne '$_ =~ /spec.required_ruby_version/ ? "" : print' mini_racer.gemspec
bundle install
bundle exec rake compile
bundle exec rake test
test-darwin:
strategy:
fail-fast: false
matrix:
platform:
- x86_64
# arm64
name: Test (darwin)
needs: build-darwin
runs-on: macos-12
steps:
- name: Set metadata
id: set-metadata
run: |
ruby -e 'puts Gem.platforms.last.to_s.gsub(/-darwin-?\d+/, "-darwin")' | tee gem_platform
echo "::set-output name=GEM_PLATFORM::$(cat gem_platform)"
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: gem-${{ needs.build-darwin.outputs.GEM_VERSION }}-${{ steps.set-metadata.outputs.GEM_PLATFORM }}
path: pkg
- name: Install gem
run: gem install pkg/libv8-node-${{ needs.build-darwin.outputs.GEM_VERSION }}-${{ steps.set-metadata.outputs.GEM_PLATFORM }}.gem
- name: Test with mini_racer
run: |
git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1
cd test/mini_racer
ruby -i -ne '$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"${{ needs.build-darwin.outputs.GEM_VERSION }}\"\n") : print' lib/mini_racer/version.rb
ruby -i -ne '$_ =~ /spec.required_ruby_version/ ? "" : print' mini_racer.gemspec
bundle install
bundle exec rake compile
bundle exec rake test
test-linux:
strategy:
fail-fast: false
matrix:
version:
- '3.1'
- '3.2'
- '3.3'
platform:
- amd64
# arm64
# arm
# ppc64le
# s390x
libc:
- gnu
- musl
include:
- version: '3.1'
platform: 'arm64'
libc: 'gnu'
- version: '3.2'
platform: 'arm64'
libc: 'gnu'
- version: '3.3'
platform: 'arm64'
libc: 'gnu'
name: Test (linux)
needs: build-linux
runs-on: ubuntu-20.04
steps:
- name: Enable ${{ matrix.platform }} platform
id: qemu
if: ${{ matrix.platform != 'amd64' }}
run: |
docker run --privileged --rm tonistiigi/binfmt:latest --install ${{ matrix.platform }} | tee platforms.json
echo "::set-output name=platforms::$(cat platforms.json)"
- name: Start container
id: container
run: |
case ${{ matrix.libc }} in
gnu)
echo 'ruby:${{ matrix.version }}'
;;
musl)
echo 'ruby:${{ matrix.version }}-alpine'
;;
esac | tee container_image
echo "::set-output name=image::$(cat container_image)"
docker run --rm -d -v "${PWD}":"${PWD}" -w "${PWD}" --platform linux/${{ matrix.platform }} $(cat container_image) /bin/sleep 64d | tee container_id
docker exec -w "${PWD}" $(cat container_id) uname -a
echo "::set-output name=id::$(cat container_id)"
- name: Install Alpine system dependencies
if: ${{ matrix.libc == 'musl' }}
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base git libstdc++
- name: Update Rubygems and Bundler
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem update --system 3.3.26
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem install bundler -v '~> 2.3.26'
- name: Set metadata
id: set-metadata
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ruby -e 'puts Gem::Platform.local.tap { |p| RUBY_PLATFORM =~ /musl/ && p.version.nil? and p.instance_eval { @version = "musl" } }.to_s' | tee gem_platform
echo "::set-output name=GEM_PLATFORM::$(cat gem_platform)"
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: gem-${{ needs.build-linux.outputs.GEM_VERSION }}-${{ steps.set-metadata.outputs.GEM_PLATFORM }}
path: pkg
- name: Install gem
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem install pkg/libv8-node-${{ needs.build-linux.outputs.GEM_VERSION }}-${{ steps.set-metadata.outputs.GEM_PLATFORM }}.gem
- name: Test with mini_racer
run: |
git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1
cd test/mini_racer
ruby -i -ne '$_ =~ /^\s+LIBV8_NODE_VERSION/ ? print(" LIBV8_NODE_VERSION = \"${{ needs.build-linux.outputs.GEM_VERSION }}\"\n") : print' lib/mini_racer/version.rb
ruby -i -ne '$_ =~ /spec.required_ruby_version/ ? "" : print' mini_racer.gemspec
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle install
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake compile
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake test