Skip to content

Commit

Permalink
Only use wasm_bindgen::__rt in proc-macros (#4305)
Browse files Browse the repository at this point in the history
This caused breakage in `js-sys` and `wasm-bindgen-futures` when not enabling the `std` crate feature of `wasm-bindgen` but disabling their own.
  • Loading branch information
daxpedda authored Nov 30, 2024
1 parent 32db0f4 commit 9fab9ce
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 11 additions & 3 deletions crates/futures/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,19 @@ impl Queue {

#[cfg(not(feature = "std"))]
pub(crate) fn with<R>(f: impl FnOnce(&Self) -> R) -> R {
use wasm_bindgen::__rt::LazyCell;
use once_cell::unsync::Lazy;

struct Wrapper<T>(Lazy<T>);

#[cfg(not(target_feature = "atomics"))]
unsafe impl<T> Sync for Wrapper<T> {}

#[cfg(not(target_feature = "atomics"))]
unsafe impl<T> Send for Wrapper<T> {}

#[cfg_attr(target_feature = "atomics", thread_local)]
static QUEUE: LazyCell<Queue> = LazyCell::new(Queue::new);
static QUEUE: Wrapper<Queue> = Wrapper(Lazy::new(Queue::new));

f(&QUEUE)
f(&QUEUE.0)
}
}
1 change: 1 addition & 0 deletions crates/js-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 11 additions & 3 deletions crates/js-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6038,12 +6038,20 @@ pub fn global() -> Object {
}
#[cfg(not(feature = "std"))]
{
use wasm_bindgen::__rt::LazyCell;
use once_cell::unsync::Lazy;

struct Wrapper<T>(Lazy<T>);

#[cfg(not(target_feature = "atomics"))]
unsafe impl<T> Sync for Wrapper<T> {}

#[cfg(not(target_feature = "atomics"))]
unsafe impl<T> Send for Wrapper<T> {}

#[cfg_attr(target_feature = "atomics", thread_local)]
static GLOBAL: LazyCell<Object> = LazyCell::new(get_global_object);
static GLOBAL: Wrapper<Object> = Wrapper(Lazy::new(get_global_object));

return GLOBAL.clone();
return GLOBAL.0.clone();
}

fn get_global_object() -> Object {
Expand Down
2 changes: 1 addition & 1 deletion crates/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 9fab9ce

Please sign in to comment.