Skip to content

Commit

Permalink
Implement MiniRacer for TruffleRuby
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish committed Jan 28, 2022
1 parent 746bfdd commit d5820d3
Show file tree
Hide file tree
Showing 7 changed files with 431 additions and 80 deletions.
152 changes: 85 additions & 67 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,95 @@ on:
- push

jobs:
test-darwin:
strategy:
fail-fast: false
matrix:
os:
- '10.15'
- '11.0'
platform:
- x86_64
# arm64
name: Test (darwin)
runs-on: macos-${{ matrix.os }}
test-truffleruby:
name: Test TruffleRuby
runs-on: ubuntu-20.04
env:
TRUFFLERUBYOPT: "--jvm --polyglot"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: truffleruby+graalvm-head
- name: Bundle
run: bundle install
- name: Compile
run: bundle exec rake compile
# - name: Compile
# run: bundle exec rake compile
- name: Test
run: bundle exec rake test
test-linux:
strategy:
fail-fast: false
matrix:
ruby:
- '2.6'
- '2.7'
- '3.0'
- '3.1'
platform:
- amd64
- arm64
# arm
# ppc64le
# s390x
libc:
- gnu
- musl
name: Test (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.ruby }}'
;;
musl)
echo 'ruby:${{ matrix.ruby }}-alpine'
;;
esac > 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 linux-headers bash python2 python3 git curl tar clang binutils-gold
- name: Checkout
uses: actions/checkout@v2
- name: Bundle
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle install
- name: Compile
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake compile
- name: Test
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake test
# test-darwin:
# strategy:
# fail-fast: false
# matrix:
# os:
# - '10.15'
# - '11.0'
# platform:
# - x86_64
# # arm64
# name: Test (darwin)
# runs-on: macos-${{ matrix.os }}
# steps:
# - name: Checkout
# uses: actions/checkout@v2
# - name: Bundle
# run: bundle install
# - name: Compile
# run: bundle exec rake compile
# - name: Test
# run: bundle exec rake test
# test-linux:
# strategy:
# fail-fast: false
# matrix:
# ruby:
# - '2.6'
# - '2.7'
# - '3.0'
# - '3.1'
# platform:
# - amd64
# - arm64
# # arm
# # ppc64le
# # s390x
# libc:
# - gnu
# - musl
# name: Test (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.ruby }}'
# ;;
# musl)
# echo 'ruby:${{ matrix.ruby }}-alpine'
# ;;
# esac > 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 linux-headers bash python2 python3 git curl tar clang binutils-gold
# - name: Checkout
# uses: actions/checkout@v2
# - name: Bundle
# run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle install
# - name: Compile
# run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake compile
# - name: Test
# run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake test
8 changes: 8 additions & 0 deletions ext/mini_racer_extension/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
if defined?(TruffleRuby)
File.open("Makefile", "w") do |mf|
mf.puts "# Dummy makefile for TruffleRuby"
mf.puts "all install::\n"
end
return
end

require 'mkmf'
require_relative '../../lib/mini_racer/version'
gem 'libv8-node', MiniRacer::LIBV8_NODE_VERSION
Expand Down
8 changes: 8 additions & 0 deletions ext/mini_racer_loader/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
if defined?(TruffleRuby)
File.open("Makefile", "w") do |mf|
mf.puts "# Dummy makefile for TruffleRuby"
mf.puts "all install::\n"
end
return
end

require 'mkmf'

extension_name = 'mini_racer_loader'
Expand Down
18 changes: 11 additions & 7 deletions lib/mini_racer.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
require "mini_racer/version"
require "mini_racer_loader"
require "mini_racer_loader" unless defined?(TruffleRuby)
require "pathname"

ext_filename = "mini_racer_extension.#{RbConfig::CONFIG['DLEXT']}"
ext_path = Gem.loaded_specs['mini_racer'].require_paths
.map { |p| (p = Pathname.new(p)).absolute? ? p : Pathname.new(__dir__).parent + p }
ext_found = ext_path.map { |p| p + ext_filename }.find { |p| p.file? }
unless defined?(TruffleRuby)
ext_filename = "mini_racer_extension.#{RbConfig::CONFIG['DLEXT']}"
ext_path = Gem.loaded_specs['mini_racer'].require_paths
.map { |p| (p = Pathname.new(p)).absolute? ? p : Pathname.new(__dir__).parent + p }
ext_found = ext_path.map { |p| p + ext_filename }.find { |p| p.file? }

raise LoadError, "Could not find #{ext_filename} in #{ext_path.map(&:to_s)}" unless ext_found
MiniRacer::Loader.load(ext_found.to_s)
raise LoadError, "Could not find #{ext_filename} in #{ext_path.map(&:to_s)}" unless ext_found
MiniRacer::Loader.load(ext_found.to_s)
end

require "thread"
require "json"
Expand Down Expand Up @@ -451,3 +453,5 @@ def warmup!(src)
end
end
end

require "mini_racer/truffleruby" if defined?(TruffleRuby)
Loading

0 comments on commit d5820d3

Please sign in to comment.