wasmerio / wasmer-js

Monorepo for Javascript WebAssembly packages by Wasmer

Home Page:https://wasmerio.github.io/wasmer-js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using "wasmer_wasi_js_bg.wasm" from another wasm module in the browser

Jack-Edwards opened this issue · comments

Libsodium has a wasm32-wasi package that requires a wasi implementation in order to work. I would like to use this package in my Blazor wasm browser application. I can link the libsodium wasm32-wasi module to my code as if it were a native library, but Blazor wasm falls short in that it doesn't offer any wasi functionality.

My understanding of wasmer-js is it offers a JS language binding around the "wasmer_wasi_js_bg.wasm" module. Is that accurate?

Would it be possible to refer to "wasmer_wasi_js_bg.wasm" directly from my Blazor wasm application, bypassing the JS language binding?

I hope I'm asking the right questions. I do have the example from the README working in the browser, but my goal is to be able use the libsodium package directly without having to perform JS interop for every single call.

It might be possible, but I currently lack the knowledge on how to do it from blazor/.NET apps directly without going through the JS layer.

It might be a good idea to ask to the blazor devs directly

Is it correct that I would not be able to interact with the libsodium module directly? Rather, I would need to provide libsodium to the wasi module in order to do anything with it.

@syrusakbary Currently the Blazor devs are pointing me towards providing the libsodium.wasm module to the wasmer/wasi runtime in the browser. Is there a way I can get the "wasmer_wasi_js_bg.wasm" as just a regular file? I'm not a JS expert, but it appears the wasm file is somehow baked into the JS bundle.

Making a little bit of progress. I am wanting to link the wasmer/wasi .wasm module directly to my Blazor app (bypassing JS), but am receiving an error when linking with emcc. "wasmer_wasi_js_bg.wasm: not a relocatable wasm file".

However, I'm not sure that what you want to do is to link [wasmer_wasi_js_bg.wasm](https://github.com/wasmerio/wasmer-js/blob/main/pkg/wasmer_wasi_js_bg.wasm) with Emscripten.

I think the way to go is to call js from Blazor in a wah that the JS code will call the Wasmer WASI code under the hood, and the libsodium.wasm afterwards

I tend to agree that linking is not the way to go, now that I've tried, failed, and looked into why it failed.

If I'm having to go through a layer of JS to interact with libsodium either way, I'm starting to think the libsodium-js repo probably the better path forward. Unless WASI offers a significant performance boost over an app compiled from Emscripten.

I think we can close this discussion out though.