rubyjs / mini_racer

Minimal embedded v8
MIT License
594 stars 93 forks source link

Implement MiniRacer for TruffleRuby #253

Closed bjfish closed 2 years ago

bjfish commented 2 years ago

This PR implements mini_racer for TruffleRuby using the GraalVM's JavaScript implementation.

It can be run locally using:

% rbenv install truffleruby+graalvm-dev
% rbenv shell truffleruby+graalvm-dev
% gu install js
% export TRUFFLERUBYOPT='--jvm --polyglot'
% bundle install 
% bundle exec rake compile
% bundle exec rake test

A previous PR with some code review is here: https://github.com/bjfish/mini_racer/pull/1

cc: @eregon

eregon commented 2 years ago

Some extra details: this is a pure-Ruby implementation of the gem using the GraalVM Polyglot API and inner contexts for isolation. It uses the same interface as the C extension and reuses all the Ruby code in lib/. It does not use libv8-node or C/C++ code.

This fixes https://github.com/oracle/truffleruby/issues/1827.

SamSaffron commented 2 years ago

Wow, Amazing, thank you so much

SamSaffron commented 2 years ago

I hope to get this reviewed early next week, @gschlager is super interested in fully testing this and he is back next week.

SamSaffron commented 2 years ago

Amazing work, thanks heaps.

@lloeki plans to update our v8 version, when we do that I think we can announce a new release of mini_racer!

eregon commented 2 years ago

Could you write here when the new release is done? Then I can close https://github.com/oracle/truffleruby/issues/1827. (I subscribed to this repo's releases but I think it doesn't notify for tags)

SamSaffron commented 2 years ago

Just cut a new release @eregon , is it working on truffle?

eregon commented 2 years ago

Thanks! Yes it works:

$ TRUFFLERUBYOPT="--jvm --polyglot" ruby -rmini_racer -ve 'ctx = MiniRacer::Context.new; p ctx.eval "1 + []"'
truffleruby 22.3.0-dev-4054469b, like ruby 3.0.3, GraalVM CE JVM [x86_64-linux]
"1"

The warnings when --jvm --polyglot are not passed aren't working correctly though, I'll look at that. EDIT: that's fixed.