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

Implement MiniRacer for TruffleRuby #253

Merged
merged 1 commit into from
Jul 21, 2022
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
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@ on:
- push

jobs:
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: Install GraalVM js component
run: if ! gu list | grep '^js '; then gu install js; fi
- name: Bundle
run: bundle install
- name: Compile
run: bundle exec rake compile
- name: Test
run: bundle exec rake test
test-darwin:
strategy:
fail-fast: false
Expand Down
18 changes: 15 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require "bundler/gem_tasks"
require "rake/testtask"
require "rake/extensiontask"

Rake::TestTask.new(:test) do |t|
t.libs << "test"
Expand All @@ -11,8 +10,21 @@ end
task :default => [:compile, :test]

gem = Gem::Specification.load( File.dirname(__FILE__) + '/mini_racer.gemspec' )
Rake::ExtensionTask.new( 'mini_racer_loader', gem )
Rake::ExtensionTask.new( 'mini_racer_extension', gem )

if RUBY_ENGINE == "truffleruby"
task :compile do
# noop
end

task :clean do
# noop
end
else
require 'rake/extensiontask'
Rake::ExtensionTask.new( 'mini_racer_loader', gem )
Rake::ExtensionTask.new( 'mini_racer_extension', gem )
end



# via http://blog.flavorjon.es/2009/06/easily-valgrind-gdb-your-ruby-c.html
Expand Down
6 changes: 6 additions & 0 deletions ext/mini_racer_extension/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
require 'mkmf'

if RUBY_ENGINE == "truffleruby"
File.write("Makefile", dummy_makefile($srcdir).join(""))
return
end

require_relative '../../lib/mini_racer/version'
gem 'libv8-node', MiniRacer::LIBV8_NODE_VERSION
require 'libv8-node'
Expand Down
5 changes: 5 additions & 0 deletions ext/mini_racer_loader/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
require 'mkmf'

if RUBY_ENGINE == "truffleruby"
File.write("Makefile", dummy_makefile($srcdir).join(""))
return
end

extension_name = 'mini_racer_loader'
dir_config extension_name

Expand Down
20 changes: 12 additions & 8 deletions lib/mini_racer.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
require "mini_racer/version"
require "mini_racer_loader"
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? }

raise LoadError, "Could not find #{ext_filename} in #{ext_path.map(&:to_s)}" unless ext_found
MiniRacer::Loader.load(ext_found.to_s)
if RUBY_ENGINE == "truffleruby"
require "mini_racer/truffleruby"
else
require "mini_racer_loader"
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)
end

require "thread"
require "json"
Expand Down
Loading