Repository: mongodb/bson-rust (language: rust)

Issue:
`js-sys` should not be used when targeting `wasm32-wasi`
<!--
  Make sure you have read CONTRIBUTING.md completely before you file a new
  issue! 
-->

## 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__`
```



Discussion / hints:
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?
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.

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index acdca236..14dc32c6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -70,7 +70,7 @@ serde_with-3 = { package = "serde_with", version = "3.1.0", optional = true }
 time = { version = "0.3.9", features = ["formatting", "parsing", "macros", "large-dates"] }
 bitvec = "1.0.1"
 
-[target.'cfg(target_arch = "wasm32")'.dependencies]
+[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
 js-sys = "0.3"
 [dev-dependencies]
 assert_matches = "1.2"
diff --git a/src/oid.rs b/src/oid.rs
index 47dc3907..a8cc3448 100644
--- a/src/oid.rs
+++ b/src/oid.rs
@@ -239,9 +239,9 @@ impl ObjectId {
     /// Generates a new timestamp representing the current seconds since epoch.
     /// Represented in Big Endian.
     fn gen_timestamp() -> [u8; 4] {
-        #[cfg(target_arch = "wasm32")]
+        #[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
         let timestamp: u32 = (js_sys::Date::now() / 1000.0) as u32;
-        #[cfg(not(target_arch = "wasm32"))]
+        #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
         let timestamp: u32 = SystemTime::now()
             .duration_since(SystemTime::UNIX_EPOCH)
             .expect("system clock is before 1970")


Test patch: