run.rb
run.rb copied to clipboard
native gems via webassembly
Hey! Amazing project and it got me thinking about how to build playgrounds for Ruby projects online without a server side Ruby process.
#9 mentions that we can use Emscripten's filesystem API to ship the standard library and other gems that we need. But what if some gem has C extensions, how would we compile that to webassembly and load them via Ruby?
🤔
I'm pretty sure the approach requiring the least surgery would be to compile and link the gem's C sources into the Ruby executable and to merge the gem's Ruby sources into the filesystem. At this point it's not so much a gem as it is a distribution of Ruby which incorporates the gem.
Emscripten supports dlopen()
so in principle gems could be loaded from external .wasm
modules at runtime, but I strongly suspect getting gem
to produce output which a WebAssembly ruby
can dynamically link would be more difficult than incorporating extra native code into the existing build.
Thanks for the response! The first approach seems like the way to go here. I'll try it out soon.