From 9fab9ce882fa71a80b996534540b9f95c6583d1e Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sat, 30 Nov 2024 08:08:01 +0100 Subject: [PATCH] Only use `wasm_bindgen::__rt` in proc-macros (#4305) This caused breakage in `js-sys` and `wasm-bindgen-futures` when not enabling the `std` crate feature of `wasm-bindgen` but disabling their own. --- CHANGELOG.md | 9 +++++++++ crates/futures/src/queue.rs | 14 +++++++++++--- crates/js-sys/Cargo.toml | 1 + crates/js-sys/src/lib.rs | 14 +++++++++++--- crates/test/Cargo.toml | 2 +- 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbadd8d921a..eabbddcf402 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ # `wasm-bindgen` Change Log -------------------------------------------------------------------------------- +## Unreleased + +### Fixed + +* Fixed `js-sys` and `wasm-bindgen-futures` relying on internal paths of `wasm-bindgen` that are not crate feature additive. + [#4305](https://github.com/rustwasm/wasm-bindgen/pull/4305) + +-------------------------------------------------------------------------------- + ## [0.2.96](https://github.com/rustwasm/wasm-bindgen/compare/0.2.95...0.2.96) Released 2024-11-29 diff --git a/crates/futures/src/queue.rs b/crates/futures/src/queue.rs index fe438cb1929..e0eb9e0de8f 100644 --- a/crates/futures/src/queue.rs +++ b/crates/futures/src/queue.rs @@ -118,11 +118,19 @@ impl Queue { #[cfg(not(feature = "std"))] pub(crate) fn with(f: impl FnOnce(&Self) -> R) -> R { - use wasm_bindgen::__rt::LazyCell; + use once_cell::unsync::Lazy; + + struct Wrapper(Lazy); + + #[cfg(not(target_feature = "atomics"))] + unsafe impl Sync for Wrapper {} + + #[cfg(not(target_feature = "atomics"))] + unsafe impl Send for Wrapper {} #[cfg_attr(target_feature = "atomics", thread_local)] - static QUEUE: LazyCell = LazyCell::new(Queue::new); + static QUEUE: Wrapper = Wrapper(Lazy::new(Queue::new)); - f(&QUEUE) + f(&QUEUE.0) } } diff --git a/crates/js-sys/Cargo.toml b/crates/js-sys/Cargo.toml index 62159e87a38..4109ef2ee47 100644 --- a/crates/js-sys/Cargo.toml +++ b/crates/js-sys/Cargo.toml @@ -25,6 +25,7 @@ default = ["std"] std = ["wasm-bindgen/std"] [dependencies] +once_cell = { version = "1.12", default-features = false } wasm-bindgen = { path = "../..", version = "=0.2.96", default-features = false } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 167e1876262..57b01303cd4 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -6038,12 +6038,20 @@ pub fn global() -> Object { } #[cfg(not(feature = "std"))] { - use wasm_bindgen::__rt::LazyCell; + use once_cell::unsync::Lazy; + + struct Wrapper(Lazy); + + #[cfg(not(target_feature = "atomics"))] + unsafe impl Sync for Wrapper {} + + #[cfg(not(target_feature = "atomics"))] + unsafe impl Send for Wrapper {} #[cfg_attr(target_feature = "atomics", thread_local)] - static GLOBAL: LazyCell = LazyCell::new(get_global_object); + static GLOBAL: Wrapper = Wrapper(Lazy::new(get_global_object)); - return GLOBAL.clone(); + return GLOBAL.0.clone(); } fn get_global_object() -> Object { diff --git a/crates/test/Cargo.toml b/crates/test/Cargo.toml index 6140a3d51c1..7a417b5d5fe 100644 --- a/crates/test/Cargo.toml +++ b/crates/test/Cargo.toml @@ -11,7 +11,7 @@ version = "0.3.46" [features] default = ["std"] -std = ["wasm-bindgen/std", "js-sys/std", "wasm-bindgen-futures/std", "once_cell/std", "scoped-tls"] +std = ["wasm-bindgen/std", "js-sys/std", "wasm-bindgen-futures/std", "scoped-tls"] [dependencies] gg-alloc = { version = "1.0", optional = true }