简体   繁体   中英

Loading WebAssembly Binaries on Rails

I'm trying to load a wasm binary on rails, but I'm only having success if the ".js" glue code and the .wasm binary are on the public folder... If I try to access them trough my views, the .js glue code is not able to find the wasm binary. (failed to load wasm binary file at 'wget.wasm')

Do I need to create a specific route to the wasm binary? I've tried changing the .wasm location on the .js glue code that is generated after my C code is compiled with emscripten, but without success...

Or do I need to add methods to send the binary file in the controller? I tried use the send_file method, but the .wasm file was being download instead of being loaded to the page...

Using firefox page inspector, I observed that when the request is made through my views, the GET results in a status 500 "Internal Server Error", but when I access through the public folder, it results in a status 200 "OK".

The only info about Ruby on Rails and WebAssembly integration that I found was a github repositor specifically in this commit , of a presentation in RubyKaigi 2017 conference "Ruby, Opal and WebAssembly", but I'm not having any progress using it. It seems that a js code is executed in this .rb file to load the wasm binary, but as I said before, I have not obtained any success using it.

If you base64-encode the .wasm file then you can put it directly in the JavaScript like this:

Module.wasmBinaryFile = "data:application/wasm;base64,AGFzbQEAAAAByQ/AAWACf38Bf2A...";

which solved a similar problem I was having

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM