Stream: wasm

Topic: Add WASM support to general purpose crate


view this post on Zulip ender (Oct 22 2020 at 03:18):

I still struggle (as someone learning Rust) with being able to add WASM support to general purpose Rust crates. I compiled rs-natural with wasm-pack but realized it was unusable because I couldn't access any of the functions from js.

Besides the tips in this article, is there anything else to look out for when trying to use a general crate to target wasm?

view this post on Zulip fitzgen (he/him) (Oct 22 2020 at 15:48):

in the same way as if you were trying to use a random crate from C you would need to wrap the crate and provide a C API, you will need to do the same thing for providing Wasm exports that make the crate's functionality available to JS

typically, this involves writing a new crate that depends on your target crate and wasm-bindgen, and uses wasm-bindgen to define an interface for working with the underlying crate


Last updated: Dec 23 2024 at 12:05 UTC