run.rb icon indicating copy to clipboard operation
run.rb copied to clipboard

native gems via webassembly

Open ngsankha opened this issue 4 years ago • 2 comments

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?

ngsankha avatar Mar 27 '20 03:03 ngsankha

🤔

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.

willglynn avatar Mar 27 '20 04:03 willglynn

Thanks for the response! The first approach seems like the way to go here. I'll try it out soon.

ngsankha avatar Mar 27 '20 13:03 ngsankha