This WASM way of running Ruby in the browser is really GREAT.
I have Ruby code running in my browser with minimal JS interfacing to make REST calls to a server:
def request_post(url, object)
opts = {
method: "POST",
body: object.to_json,
headers: {
"Content-type": "application/json"
}
}
JS.global.fetch(url, opts).await.text.await.to_s
end
Now I'm ready to add page components using Ruby only, but this requires many custom .rb files.
I am able to build my own .wasm file using rbwasm, with all my app files under site_ruby/, and run my custom code inside the .wasm with wasmtime.
And I can load the .wasm file into the browser, BUT the "js" gem is missing from the .wasm file, and I get an error like this in the browser console:
Failed to instantiate Ruby VM. Please make sure that you have added `gem "js"` to your Gemfile.
I can't figure out what this means exactly. My Gemfile has "js" in it. And when I run various rake tasks inside my clone of the ruby/ruby.wasm repo, I just don't see the "js" gem being compiled to WASM or included anywhere.
I realize that if I "rollup" all my .rb files into a single file, then it's easy to use another <script> tag to add it to the browser, but I feel like including all my .rb files into a main .wasm file is better, leveraging the cool libwasi_vfs.
Is there a doc somewhere I have missed? I have been up all night reading rake task code in this repo. My tired crossed eyes force me to give up.
This WASM way of running Ruby in the browser is really GREAT.
I have Ruby code running in my browser with minimal JS interfacing to make REST calls to a server:
Now I'm ready to add page components using Ruby only, but this requires many custom .rb files.
I am able to build my own .wasm file using
rbwasm, with all my app files undersite_ruby/, and run my custom code inside the .wasm withwasmtime.And I can load the .wasm file into the browser, BUT the "js" gem is missing from the .wasm file, and I get an error like this in the browser console:
I can't figure out what this means exactly. My
Gemfilehas "js" in it. And when I run various rake tasks inside my clone of theruby/ruby.wasmrepo, I just don't see the "js" gem being compiled to WASM or included anywhere.I realize that if I "rollup" all my .rb files into a single file, then it's easy to use another
<script>tag to add it to the browser, but I feel like including all my .rb files into a main .wasm file is better, leveraging the coollibwasi_vfs.Is there a doc somewhere I have missed? I have been up all night reading rake task code in this repo. My tired crossed eyes force me to give up.