Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross compile #24

Merged
merged 19 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 96 additions & 42 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
rubocop:
name: Lint (Rubocop)
runs-on: ubuntu-20.04
container: ruby:2.3
container: ruby:2.6
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -30,7 +30,7 @@ jobs:
outputs:
GEM_VERSION: ${{ steps.set-metadata.outputs.GEM_VERSION }}
runs-on: ubuntu-20.04
container: ruby:2.3
container: ruby:2.6
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -39,15 +39,15 @@ jobs:
- name: Set metadata
id: set-metadata
run: |
bundle exec ruby -e 'puts RUBY_PLATFORM' | tee ruby_platform
./libexec/metadata ruby_platform | tee ruby_platform
echo "::set-output name=RUBY_PLATFORM::$(cat ruby_platform)"
bundle exec ruby -e 'puts Gem.platforms.last.to_s' | tee gem_platform
./libexec/metadata gem_platform | tee gem_platform
echo "::set-output name=GEM_PLATFORM::$(cat gem_platform)"
bundle exec ruby -e 'puts Libv8::Node::VERSION' | tee gem_version
./libexec/metadata gem_version | tee gem_version
echo "::set-output name=GEM_VERSION::$(cat gem_version)"
bundle exec ruby -e 'puts Libv8::Node::NODE_VERSION' | tee node_version
./libexec/metadata node_version | tee node_version
echo "::set-output name=NODE_VERSION::$(cat node_version)"
bundle exec ruby -e 'puts Libv8::Node::LIBV8_VERSION' | tee libv8_version
./libexec/metadata libv8_version | tee libv8_version
echo "::set-output name=LIBV8_VERSION::$(cat libv8_version)"
- name: Download Node.js
run: |
Expand All @@ -57,7 +57,7 @@ jobs:
./libexec/extract-node ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Validate V8 version
run: |
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
./libexec/metadata libv8_version_h | tee libv8_version_h
diff libv8_version_h libv8_version
- name: Build gem
run: |
Expand Down Expand Up @@ -86,15 +86,15 @@ jobs:
- name: Set metadata
id: set-metadata
run: |
bundle exec ruby -e 'puts RUBY_PLATFORM' | tee ruby_platform
./libexec/metadata ruby_platform | tee ruby_platform
echo "::set-output name=RUBY_PLATFORM::$(cat ruby_platform)"
bundle exec ruby -e 'puts Gem.platforms.last.to_s' | tee gem_platform
./libexec/metadata gem_platform | tee gem_platform
echo "::set-output name=GEM_PLATFORM::$(cat gem_platform)"
bundle exec ruby -e 'puts Libv8::Node::VERSION' | tee gem_version
./libexec/metadata gem_version | tee gem_version
echo "::set-output name=GEM_VERSION::$(cat gem_version)"
bundle exec ruby -e 'puts Libv8::Node::NODE_VERSION' | tee node_version
./libexec/metadata node_version | tee node_version
echo "::set-output name=NODE_VERSION::$(cat node_version)"
bundle exec ruby -e 'puts Libv8::Node::LIBV8_VERSION' | tee libv8_version
./libexec/metadata libv8_version | tee libv8_version
echo "::set-output name=LIBV8_VERSION::$(cat libv8_version)"
- name: Download Node.js
run: |
Expand All @@ -104,7 +104,7 @@ jobs:
./libexec/extract-node ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Validate V8 version
run: |
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
./libexec/metadata libv8_version_h | tee libv8_version_h
diff libv8_version_h libv8_version
- name: Build V8
run: |
Expand Down Expand Up @@ -134,58 +134,94 @@ jobs:
matrix:
platform:
- amd64
# arm64
- arm64
# arm
# ppc64le
# s390x
libc:
- gnu
- musl
include:
- platform: amd64
libc: musl
name: Build (linux)
outputs:
GEM_VERSION: ${{ steps.set-metadata.outputs.GEM_VERSION }}
runs-on: ubuntu-20.04
steps:
- name: Enable ${{ matrix.platform }} platform
id: qemu
if: ${{ matrix.platform != 'amd64' }}
- name: Set cross-compilation platform
id: platform
run: |
docker run --privileged --rm tonistiigi/binfmt:latest --install ${{ matrix.platform }} | tee platforms.json
echo "::set-output name=platforms::$(cat platforms.json)"
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:2.3'
echo 'ruby:2.4'
;;
musl)
echo 'ruby:2.4-alpine'
;;
esac > container_image
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 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 python2 python3 git curl tar clang binutils-gold
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base linux-headers bash python2 python3 git curl tar
- name: Install Debian cross-compiler
if: ${{ matrix.libc == 'gnu' && matrix.platform != 'amd64' }}
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apt-get update
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: 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 }} bundle exec ruby -e 'puts RUBY_PLATFORM' | tee ruby_platform
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 }} 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
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 }} bundle exec ruby -e 'puts Libv8::Node::VERSION' | tee gem_version
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 }} bundle exec ruby -e 'puts Libv8::Node::NODE_VERSION' | tee node_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 }} bundle exec ruby -e 'puts Libv8::Node::LIBV8_VERSION' | tee libv8_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: |
Expand All @@ -195,7 +231,7 @@ jobs:
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 }} 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
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: |
Expand All @@ -208,22 +244,22 @@ jobs:
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ./libexec/inject-libv8 ${{ steps.set-metadata.outputs.NODE_VERSION }}
- name: Build binary gem
run: |
docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake binary
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@v1
with:
name: v8-${{ steps.set-metadata.outputs.LIBV8_VERSION }}-${{ steps.set-metadata.outputs.GEM_PLATFORM }}
name: v8-${{ steps.set-metadata.outputs.LIBV8_VERSION }}-${{ steps.platform.outputs.ruby_target_platform }}
path: vendor
- name: Upload gem
uses: actions/upload-artifact@v1
with:
name: gem-${{ steps.set-metadata.outputs.GEM_VERSION }}-${{ steps.set-metadata.outputs.GEM_PLATFORM }}
name: gem-${{ steps.set-metadata.outputs.GEM_VERSION }}-${{ steps.platform.outputs.ruby_target_platform }}
path: pkg
test-ruby:
name: Test (ruby)
needs: build-ruby
runs-on: ubuntu-20.04
container: ruby:2.3
container: ruby:2.5
steps:
- name: Set metadata
id: set-metadata
Expand All @@ -236,12 +272,12 @@ jobs:
name: gem-${{ needs.build-ruby.outputs.GEM_VERSION }}-ruby
path: pkg
- name: Install gem
run: gem install pkg/libv8-node-${{ needs.build-ruby.outputs.GEM_VERSION }}.gem
run: gem install --verbose pkg/libv8-node-${{ needs.build-ruby.outputs.GEM_VERSION }}.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
git fetch origin refs/pull/186/head
git fetch origin refs/pull/210/head
git checkout FETCH_HEAD
git reset --hard
git clean -f -d -x
Expand Down Expand Up @@ -276,7 +312,7 @@ jobs:
run: |
git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1
cd test/mini_racer
git fetch origin refs/pull/186/head
git fetch origin refs/pull/210/head
git checkout FETCH_HEAD
git reset --hard
git clean -f -d -x
Expand All @@ -288,6 +324,11 @@ jobs:
strategy:
fail-fast: false
matrix:
version:
- '2.5'
- '2.6'
- '2.7'
- '3.0'
platform:
- amd64
# arm64
Expand All @@ -297,6 +338,19 @@ jobs:
libc:
- gnu
- musl
include:
- version: '2.5'
platform: 'arm64'
libc: 'gnu'
- version: '2.6'
platform: 'arm64'
libc: 'gnu'
- version: '2.7'
platform: 'arm64'
libc: 'gnu'
- version: '3.0'
platform: 'arm64'
libc: 'gnu'
name: Test (linux)
needs: build-linux
runs-on: ubuntu-20.04
Expand All @@ -312,12 +366,12 @@ jobs:
run: |
case ${{ matrix.libc }} in
gnu)
echo 'ruby:2.3'
echo 'ruby:${{ matrix.version }}'
;;
musl)
echo 'ruby:2.7-alpine'
echo 'ruby:${{ matrix.version }}-alpine'
;;
esac > container_image
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
Expand All @@ -341,7 +395,7 @@ jobs:
run: |
git clone https://github.com/rubyjs/mini_racer.git test/mini_racer --depth 1
cd test/mini_racer
git fetch origin refs/pull/186/head
git fetch origin refs/pull/210/head
git checkout FETCH_HEAD
git reset --hard
git clean -f -d -x
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
Makefile
/ext/libv8-node/.location.yml
/test/mini_racer
*.nix
*.vim
.envrc
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ARG RUBY_VERSION=2.3
ARG RUBY_VERSION=2.4
FROM ruby:${RUBY_VERSION}

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

RUN mkdir -p /code
WORKDIR /code

ARG NODE_VERSION=15.14.0
ARG NODE_VERSION=16.10.0

COPY libexec/download-node /code/libexec/
RUN ./libexec/download-node ${NODE_VERSION}
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ NODE_VERSION := $(shell ./libexec/metadata node_version)
all:

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

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

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

pkg/libv8-node-$(VERSION)-aarch64-linux-musl.gem:
Expand Down
Loading