diff --git a/Cargo.toml b/Cargo.toml index df56e542d67..7a585dbcb54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -123,10 +123,12 @@ env_logger = "0.11" futures = "0.3.30" futures-bounded = { version = "0.3", features = ["tokio"] } futures-rustls = { version = "0.26.0", default-features = false } -getrandom = "0.2" -if-watch = "3.2.2" +futures-timer = { version = "3" } +getrandom = { version = "0.2", features = ["js"] } +hashlink = "0.11.0" hickory-proto = { version = "0.25.2", default-features = false } hickory-resolver = { version = "0.25.2", default-features = false } +if-watch = "3.2.2" multiaddr = "0.18.1" multihash = "0.19.1" multistream-select = { version = "0.14.0", path = "misc/multistream-select" } @@ -141,8 +143,8 @@ tokio = { version = "1.50", default-features = false } tracing = "0.1.44" tracing-subscriber = "0.3.23" unsigned-varint = { version = "0.8.0" } +wasm-bindgen-futures = "0.4" web-time = "1.1.0" -hashlink = "0.11.0" [patch.crates-io] diff --git a/examples/browser-webrtc/Cargo.toml b/examples/browser-webrtc/Cargo.toml index 03008615077..1f88d0e4009 100644 --- a/examples/browser-webrtc/Cargo.toml +++ b/examples/browser-webrtc/Cargo.toml @@ -35,11 +35,11 @@ mime_guess = "2.0.4" [target.'cfg(target_arch = "wasm32")'.dependencies] js-sys = "0.3.69" -libp2p = { path = "../../libp2p", features = [ "ed25519", "macros", "ping", "wasm-bindgen"] } +libp2p = { path = "../../libp2p", features = [ "ed25519", "macros", "ping"] } libp2p-webrtc-websys = { workspace = true } tracing-wasm = "0.2.1" wasm-bindgen = "0.2.90" -wasm-bindgen-futures = "0.4.42" +wasm-bindgen-futures = { workspace = true} web-sys = { version = "0.3", features = ['Document', 'Element', 'HtmlElement', 'Node', 'Response', 'Window'] } [lints] diff --git a/interop-tests/Cargo.toml b/interop-tests/Cargo.toml index cd230ec521f..84a390b5354 100644 --- a/interop-tests/Cargo.toml +++ b/interop-tests/Cargo.toml @@ -39,11 +39,11 @@ tracing = { workspace = true } tracing-subscriber = { workspace = true, features = ["env-filter"] } [target.'cfg(target_arch = "wasm32")'.dependencies] -libp2p = { path = "../libp2p", features = [ "ping", "macros", "webtransport-websys", "wasm-bindgen", "identify", "websocket-websys", "yamux", "noise"] } +libp2p = { path = "../libp2p", features = [ "ping", "macros", "webtransport-websys", "identify", "websocket-websys", "yamux", "noise"] } libp2p-mplex = { path = "../muxers/mplex" } libp2p-webrtc-websys = { workspace = true } wasm-bindgen = { version = "0.2" } -wasm-bindgen-futures = { version = "0.4" } +wasm-bindgen-futures = { workspace = true} wasm-logger = { version = "0.2.0" } web-time = { workspace = true } reqwest = { version = "0.12", features = ["json"] } diff --git a/libp2p/CHANGELOG.md b/libp2p/CHANGELOG.md index 1a676732036..6a9310fe6a4 100644 --- a/libp2p/CHANGELOG.md +++ b/libp2p/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.57.0 +- Remove `wasm-bindgen` feature and make `wasm` support implicit. + See [PR 6102](https://github.com/libp2p/rust-libp2p/pull/6102) - Raise MSRV to 1.88.0. See [PR 6273](https://github.com/libp2p/rust-libp2p/pull/6273). - Fix `metrics` delegation to gossipsub protocol. diff --git a/libp2p/Cargo.toml b/libp2p/Cargo.toml index bc1542fed5e..a42e5631565 100644 --- a/libp2p/Cargo.toml +++ b/libp2p/Cargo.toml @@ -42,7 +42,6 @@ full = [ "tls", "tokio", "uds", - "wasm-bindgen", "webrtc-websys", "websocket-websys", "websocket", @@ -81,7 +80,6 @@ tcp = ["dep:libp2p-tcp"] tls = ["dep:libp2p-tls"] tokio = ["libp2p-swarm/tokio", "libp2p-mdns?/tokio", "libp2p-tcp?/tokio", "libp2p-dns?/tokio", "libp2p-quic?/tokio", "libp2p-upnp?/tokio"] uds = ["dep:libp2p-uds"] -wasm-bindgen = ["futures-timer/wasm-bindgen", "getrandom/js", "libp2p-swarm/wasm-bindgen", "libp2p-gossipsub?/wasm-bindgen"] webrtc-websys = ['dep:libp2p-webrtc-websys'] websocket-websys = ["dep:libp2p-websocket-websys"] websocket = ["dep:libp2p-websocket"] @@ -93,8 +91,6 @@ upnp = ["dep:libp2p-upnp"] bytes = "1" either = "1.9.0" futures = { workspace = true } -futures-timer = "3.0.2" # Explicit dependency to be used in `wasm-bindgen` feature -getrandom = { workspace = true } # Explicit dependency to be used in `wasm-bindgen` feature # TODO feature flag? rw-stream-sink = { workspace = true } libp2p-allow-block-list = { workspace = true } @@ -144,6 +140,10 @@ libp2p-mplex = { workspace = true } libp2p-tcp = { workspace = true, features = ["tokio"] } tracing-subscriber = { workspace = true, features = ["env-filter"] } +[target.'cfg(target_family="wasm")'.dependencies] +futures-timer = { workspace = true, features = ["wasm-bindgen"] } +getrandom = { workspace = true} + # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling [package.metadata.docs.rs] diff --git a/libp2p/src/builder/phase/provider.rs b/libp2p/src/builder/phase/provider.rs index aa99d5518ce..60dce1501b0 100644 --- a/libp2p/src/builder/phase/provider.rs +++ b/libp2p/src/builder/phase/provider.rs @@ -15,7 +15,7 @@ pub enum NoProviderSpecified {} /// Represents the Tokio runtime environment. pub enum Tokio {} -#[cfg(feature = "wasm-bindgen")] +#[cfg(target_arch = "wasm32")] /// Represents the WasmBindgen environment for WebAssembly. pub enum WasmBindgen {} @@ -37,7 +37,7 @@ impl SwarmBuilder { /// Configures the SwarmBuilder for WebAssembly using WasmBindgen. /// This method is available when the `wasm-bindgen` feature is enabled. - #[cfg(feature = "wasm-bindgen")] + #[cfg(target_arch = "wasm32")] pub fn with_wasm_bindgen(self) -> SwarmBuilder { SwarmBuilder { keypair: self.keypair, diff --git a/libp2p/src/builder/phase/swarm.rs b/libp2p/src/builder/phase/swarm.rs index 79b512a38af..ca8ba38a12d 100644 --- a/libp2p/src/builder/phase/swarm.rs +++ b/libp2p/src/builder/phase/swarm.rs @@ -10,9 +10,9 @@ pub struct SwarmPhase { pub(crate) transport: T, } +#[cfg(any(target_arch = "wasm32", feature = "tokio"))] macro_rules! impl_with_swarm_config { - ($providerKebabCase:literal, $providerPascalCase:ty, $config:expr) => { - #[cfg(feature = $providerKebabCase)] + ($providerPascalCase:ty, $config:expr) => { impl SwarmBuilder<$providerPascalCase, SwarmPhase> { pub fn with_swarm_config( self, @@ -42,16 +42,14 @@ macro_rules! impl_with_swarm_config { }; } -#[cfg(not(target_arch = "wasm32"))] +#[cfg(all(not(target_arch = "wasm32"), feature = "tokio"))] impl_with_swarm_config!( - "tokio", super::provider::Tokio, libp2p_swarm::Config::with_tokio_executor() ); #[cfg(target_arch = "wasm32")] impl_with_swarm_config!( - "wasm-bindgen", super::provider::WasmBindgen, libp2p_swarm::Config::with_wasm_executor() ); diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index e3f24272bcd..8c4bb4ae4bf 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -54,6 +54,9 @@ - Refactor gossipsub with in-place negative-score peer removal. See [PR 6209](https://github.com/libp2p/rust-libp2p/pull/6209). +- Remove `wasm-bindgen` feature and make `wasm` support implicit. + See [PR 6102](https://github.com/libp2p/rust-libp2p/pull/6102) + - Avoid direct casting from u128 to u64. See [PR 6211](https://github.com/libp2p/rust-libp2p/pull/6211). diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 74d3266334e..c0c50732408 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -11,7 +11,6 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [features] -wasm-bindgen = ["getrandom/js", "futures-timer/wasm-bindgen"] metrics = ["prometheus-client"] partial_messages = [] @@ -24,8 +23,7 @@ bytes = "1.11" either = "1.11" fnv = "1.0.7" futures = { workspace = true } -futures-timer = "3.0.2" -getrandom = { workspace = true } +futures-timer = { workspace = true} hashlink = { workspace = true } hex_fmt = "0.3.0" web-time = { workspace = true } @@ -50,6 +48,10 @@ quickcheck = { workspace = true } tracing-subscriber = { workspace = true, features = ["env-filter"] } tokio = { workspace = true, features = ["rt", "rt-multi-thread", "time", "macros"] } +[target.'cfg(target_family="wasm")'.dependencies] +futures-timer = { workspace = true, features = ["wasm-bindgen"] } +getrandom = { workspace = true } + # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling [package.metadata.docs.rs] diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index f9e600f1c7c..b5578f90a38 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,5 +1,8 @@ ## 0.48.0 +- Remove `wasm-bindgen` feature and make `wasm` support implicit. + See [PR 6102](https://github.com/libp2p/rust-libp2p/pull/6102) + - Raise MSRV to 1.88.0. See [PR 6273](https://github.com/libp2p/rust-libp2p/pull/6273). diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 19d70f01547..22c39aeb64b 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -15,7 +15,6 @@ either = "1.11.0" fnv = "1.0" futures = { workspace = true } futures-timer = "3.0.3" -getrandom = { workspace = true, features = ["js"], optional = true } # Explicit dependency to be used in `wasm-bindgen` feature web-time = { workspace = true } hashlink = { workspace = true } libp2p-core = { workspace = true } @@ -25,15 +24,17 @@ multistream-select = { workspace = true } rand = "0.8" smallvec = "1.15.1" tracing = { workspace = true } -wasm-bindgen-futures = { version = "0.4.42", optional = true } [target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies] tokio = { workspace = true, features = ["rt"], optional = true } +[target.'cfg(target_family="wasm")'.dependencies] +getrandom = { workspace = true} +wasm-bindgen-futures = { workspace = true} + [features] macros = ["dep:libp2p-swarm-derive"] tokio = ["dep:tokio"] -wasm-bindgen = ["dep:wasm-bindgen-futures", "dep:getrandom"] [dev-dependencies] either = "1.11.0" diff --git a/swarm/src/executor.rs b/swarm/src/executor.rs index 41fb37aaf15..b8181a5d0ce 100644 --- a/swarm/src/executor.rs +++ b/swarm/src/executor.rs @@ -44,10 +44,10 @@ impl Executor for TokioExecutor { } } -#[cfg(feature = "wasm-bindgen")] +#[cfg(target_arch = "wasm32")] #[derive(Default, Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] pub(crate) struct WasmBindgenExecutor; -#[cfg(feature = "wasm-bindgen")] +#[cfg(target_arch = "wasm32")] impl Executor for WasmBindgenExecutor { fn exec(&self, future: Pin + Send>>) { wasm_bindgen_futures::spawn_local(future) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 06d632630cb..34c63944571 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1402,7 +1402,7 @@ impl Config { /// task() /// } /// ``` - #[cfg(feature = "wasm-bindgen")] + #[cfg(target_arch = "wasm32")] pub fn with_wasm_executor() -> Self { Self::with_executor(crate::executor::WasmBindgenExecutor) } diff --git a/transports/webrtc-websys/CHANGELOG.md b/transports/webrtc-websys/CHANGELOG.md index 262e7f89c56..4e9f05ae892 100644 --- a/transports/webrtc-websys/CHANGELOG.md +++ b/transports/webrtc-websys/CHANGELOG.md @@ -1,5 +1,8 @@ ## 0.5.0 +- Require `getrandom/js` feature only under `wasm` target. + See [PR 6102](https://github.com/libp2p/rust-libp2p/pull/6102) + - Raise MSRV to 1.88.0. See [PR 6273](https://github.com/libp2p/rust-libp2p/pull/6273). diff --git a/transports/webrtc-websys/Cargo.toml b/transports/webrtc-websys/Cargo.toml index b2763e06544..d92efec0d89 100644 --- a/transports/webrtc-websys/Cargo.toml +++ b/transports/webrtc-websys/Cargo.toml @@ -14,7 +14,6 @@ publish = true [dependencies] bytes = "1" futures = { workspace = true } -getrandom = { workspace = true, features = ["js"] } hex = "0.4.3" js-sys = { version = "0.3" } libp2p-core = { workspace = true } @@ -24,8 +23,11 @@ send_wrapper = { version = "0.6.0", features = ["futures"] } thiserror = { workspace = true } tracing = { workspace = true } wasm-bindgen = { version = "0.2.90" } -wasm-bindgen-futures = { version = "0.4.42" } +wasm-bindgen-futures = { workspace = true} web-sys = { version = "0.3.70", features = ["Document", "Location", "MessageEvent", "Navigator", "RtcCertificate", "RtcConfiguration", "RtcDataChannel", "RtcDataChannelEvent", "RtcDataChannelInit", "RtcDataChannelState", "RtcDataChannelType", "RtcPeerConnection", "RtcSdpType", "RtcSessionDescription", "RtcSessionDescriptionInit", "Window"] } +[target.'cfg(target_family="wasm")'.dependencies] +getrandom = { workspace = true} + [lints] workspace = true diff --git a/wasm-tests/webtransport-tests/Cargo.toml b/wasm-tests/webtransport-tests/Cargo.toml index cd103b46d05..320b3c89e2c 100644 --- a/wasm-tests/webtransport-tests/Cargo.toml +++ b/wasm-tests/webtransport-tests/Cargo.toml @@ -18,7 +18,7 @@ libp2p-webtransport-websys = { workspace = true } multiaddr = { workspace = true } multihash = { workspace = true } wasm-bindgen = "0.2.93" -wasm-bindgen-futures = "0.4.43" +wasm-bindgen-futures = { workspace = true} wasm-bindgen-test = "0.3.43" web-sys = { version = "0.3.70", features = ["Response", "Window"] }