mongodb / bson-rust

Encoding and decoding support for BSON in Rust
MIT License
389 stars 130 forks source link

`js-sys` should not be used when targeting `wasm32-wasi` #441

Closed tqwewe closed 7 months ago

tqwewe commented 7 months ago

Describe the bug

js-sys brings in wasm-bindgen when targeting wasm32 architechture. However, wasm32-wasi targets should not use js-sys not wasm-bindgen.

The cargo toml should be updated to be something like [target.'cfg(target_arch = "wasm32", target_os = "unknown")'.dependencies] for js-sys.

This causes issues when compiling to wasm components, as when trying to convert a crate which uses wasm-bindgen to a wasm component results in the following error:

error: failed to encode a component from module

Caused by:
    0: module requires an import interface named `__wbindgen_placeholder__`
abr-egn commented 7 months ago

Thanks for bringing this to our attention!

I'm not very familiar with WASI - my understanding is that with your proposed change, when running under WASI the crate should be using the Rust stdlib which will itself do the work of using the WASI-exposed syscalls?

tqwewe commented 7 months ago

Yep exactly right! wasm-bindgen is for web browsers, so it gives some issues when compiling to wasm32-wasi which is meant to be used on the server side only with something like wasmtime.

abr-egn commented 7 months ago

I've submitted the fix for this in https://github.com/mongodb/bson-rust/pull/442.