Skip to content

Commit b633599

Browse files
committed
Enable cross-compilation in CI
1 parent 2034b2e commit b633599

File tree

3 files changed

+76
-27
lines changed

3 files changed

+76
-27
lines changed

.github/workflows/build.yml

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,42 +134,78 @@ 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.4'
191+
echo 'ruby:3.0'
161192
;;
162193
musl)
163-
echo 'ruby:2.4-alpine'
194+
echo 'ruby:3.0-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
203+
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base linux-headers bash python2 python3 git curl tar clang
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
@@ -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.4
262+
container: ruby:2.5
227263
steps:
228264
- name: Set metadata
229265
id: set-metadata
@@ -241,7 +277,7 @@ jobs:
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
@@ -289,7 +325,6 @@ jobs:
289325
fail-fast: false
290326
matrix:
291327
version:
292-
- '2.4'
293328
- '2.5'
294329
- '2.6'
295330
- '2.7'
@@ -303,6 +338,19 @@ jobs:
303338
libc:
304339
- gnu
305340
- 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'
306354
name: Test (linux)
307355
needs: build-linux
308356
runs-on: ubuntu-20.04
@@ -323,7 +371,7 @@ jobs:
323371
musl)
324372
echo 'ruby:${{ matrix.version }}-alpine'
325373
;;
326-
esac > container_image
374+
esac | tee container_image
327375
echo "::set-output name=image::$(cat container_image)"
328376
docker run --rm -d -v "${PWD}":"${PWD}" -w "${PWD}" --platform linux/${{ matrix.platform }} $(cat container_image) /bin/sleep 64d | tee container_id
329377
docker exec -w "${PWD}" $(cat container_id) uname -a
@@ -347,7 +395,7 @@ jobs:
347395
run: |
348396
git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1
349397
cd test/mini_racer
350-
git fetch origin refs/pull/186/head
398+
git fetch origin refs/pull/210/head
351399
git checkout FETCH_HEAD
352400
git reset --hard
353401
git clean -f -d -x

Rakefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Helpers
66
module_function
77

88
def binary_gemspec(platform: Gem::Platform.local, str: RUBY_PLATFORM)
9+
# TODO: old rubygems and cross compile
910
platform.instance_eval { @version = 'musl' } if str =~ /-musl/ && platform.version.nil?
1011

1112
gemspec = eval(File.read('libv8-node.gemspec')) # rubocop:disable Security/Eval
@@ -20,12 +21,12 @@ end
2021

2122
task :compile, [:platform] => [] do |_, args|
2223
local_platform = Gem::Platform.local.to_s
23-
target_platform = ENV['GEM_TARGET_PLATFORM'] || args.to_h[:platform] || Gem::Platform.local.to_s
24+
target_platform = ENV['RUBY_TARGET_PLATFORM'] || args.to_h[:platform] || Gem::Platform.local.to_s
2425

2526
puts "local platform: #{local_platform}"
2627
puts "target platform: #{target_platform}"
2728

28-
ENV['GEM_TARGET_PLATFORM'] = target_platform
29+
ENV['RUBY_TARGET_PLATFORM'] = target_platform
2930

3031
if (libs = Dir["vendor/v8/#{target_platform}/**/*.a"]).any?
3132
puts "found: #{libs.inspect}"
@@ -38,8 +39,8 @@ task :compile, [:platform] => [] do |_, args|
3839
end
3940

4041
task :binary, [:platform] => [:compile] do |_, args|
41-
local_platform = Gem::Platform.local.to_s
42-
target_platform = ENV['GEM_TARGET_PLATFORM'] || args.to_h[:platform] || Gem::Platform.local.to_s
42+
local_platform = Gem::Platform.local
43+
target_platform = Gem::Platform.new(ENV['RUBY_TARGET_PLATFORM']) || Gem::Platform.new(args.to_h[:platform]) || Gem::Platform.local
4344

4445
puts "local platform: #{local_platform}"
4546
puts "target platform: #{target_platform}"

libexec/platform

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ case "${host_platform}" in
6363
esac
6464

6565
if [ "${host_platform}" != "${target_platform}" ]; then
66-
echo "cross compiling host: ${host_platform} target: ${target_platform}"
66+
echo "# cross compiling host: ${host_platform} target: ${target_platform}"
6767
case "${target_platform}" in
6868
aarch64-*linux*)
6969
CC='aarch64-linux-gnu-gcc'
@@ -121,6 +121,6 @@ if [ -n "${RUBY_TARGET_PLATFORM:-}" ]; then cat <<EOF; fi
121121
RUBY_TARGET_PLATFORM='${RUBY_TARGET_PLATFORM}'
122122
EOF
123123

124-
if [ -n "${CC_host:-}" ]; then cat <<EOF; fi
124+
if [ -n "${configure_flags:-}" ]; then cat <<EOF; fi
125125
configure_flags="\${configure_flags:-} ${configure_flags}"
126126
EOF

0 commit comments

Comments
 (0)