workers-rs icon indicating copy to clipboard operation
workers-rs copied to clipboard

Enable WebAssembly reference types

Open Electroid opened this issue 3 years ago • 3 comments

The Workers runtime recently updated to V8 9.6, which has support for WebAssembly reference types. wasm-bindgen also has support with an optional flag: https://rustwasm.github.io/wasm-bindgen/reference/reference-types.html

Electroid avatar Nov 05 '21 20:11 Electroid

We use wasm-bindgen through wasm-pack which has had this related PR open for a while: https://github.com/rustwasm/wasm-pack/pull/888

I may take a look at it in the next week or so. Definitely would be nice to take advantage of this now that we have it supported!

EDIT: it's also maybe time to consider dropping wasm-pack as the intermediary, and just call wasm-bindgen directly. Will investigate.

nilslice avatar Nov 05 '21 21:11 nilslice

it's also maybe time to consider dropping wasm-pack as the intermediary, and just call wasm-bindgen directly. Will investigate.

Any news on this front? My two cents would be that wasm-pack and also this repository's worker-build include too much and try to hide too much from the developer. I would much rather have clear documentation about how to transform the output of wasm-bindgen to something that can be consumed by wrangler.

For example, in my case, I already use WebAssembly on my front-end and would like to build all my crates with a single innovation of cargo build and to use webpack for bundling instead of swc (since webpack is already used for the front-end), but wasm-pack/worker-build makes this very awkward.

allsey87 avatar Jun 14 '22 16:06 allsey87

Just in case, this issue can be closed, you can use --reference-types now via modifying wrangler.toml's build command (I believe it should be the default behavior, it's a big advantage and performance boost in many cases):

[build]
command = "cargo install -q worker-build --version 0.0.7 && worker-build --release --reference-types"

P.S. It's possible due to wasm-pack ability to pass those arguments to wasm-bindgen, and worker-build passes os-level arguments to wasm-pack (looks like it was the original design, which is great).

nxmaintainer avatar Apr 08 '23 10:04 nxmaintainer