Skip to content

Add an alternative to Result<T, JsValue> for the wasm32-wasi target #2414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tonyhb opened this issue Jan 6, 2021 · 3 comments
Closed

Add an alternative to Result<T, JsValue> for the wasm32-wasi target #2414

tonyhb opened this issue Jan 6, 2021 · 3 comments

Comments

@tonyhb
Copy link

tonyhb commented Jan 6, 2021

When returning Result type we must use JsValue as the type to hold error cases. JsValue isn't supported on the wasm32-wasi target, if attempting to build for cranelift (eg. for use with wasmtime).

It would be nice to have use a supported interface type for the error value that works in both wasm32-unknown-unknown and wasm32-wasi targets.

@alexcrichton
Copy link
Contributor

In general wasm-bindgen was never designed for anything other than the web. Bits and pieces of it happen to work on wasm32-wasi but at a fundamental level it's not really going to work well there. I think wasm-bindgen probably isn't the right tool for the job for wasi and native wasm interop with a host at this point. Systems like interface types show much more promise in this regard.

It's likely that Rust will gain tooling for interface types in the future and wasm-bindgen will be reimplemented on top of that. Until then though I wouldn't recommend using wasm-bindgen for an out-of-browser runtime like Wasmtime.

@tonyhb
Copy link
Author

tonyhb commented Jan 6, 2021

Yep yep, aware of the interface types too and was wondering whether wasm-bindgen would be implemented on top of that and then be compatible for other runtimes such as wasm32-wasi. Thanks for informing me that it's not currently intended, and we have to wait for interface types. Appreciate it!

@happybeing
Copy link

FYI as this issue is recent, I'm just learning and wanted to use WASI in the browser with WasmerJS, and have managed to make use of wasm-bindgen to simplify handling of bindings.

Reading the above I wonder what will and won't work with this approach. I've been collecting examples using wasm-bindgen to probe the limits but there aren't many out there. The ones I found in the wasm-bindgen book are incomplete and I'm not sure if my failure to get them working is my lack of understanding or because the issues mentioned above (e.g. see this issue).

Pointers to more examples welcome, and if you are interested in using WasmerJS with wasm-bindgen, or have comments that will help me understand the usefulness of this approach let me know. The demo project is: https://github.com/happybeing/svelte-wasi-with-rust

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants