Skip to content

fix: make wasm features implicit #6102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ rust-version = "1.83.0"
edition = "2021"

[workspace.dependencies]
libp2p = { version = "0.56.0", path = "libp2p" }
libp2p = { version = "0.57.0", path = "libp2p" }
libp2p-allow-block-list = { version = "0.6.0", path = "misc/allow-block-list" }
libp2p-autonat = { version = "0.15.0", path = "protocols/autonat" }
libp2p-connection-limits = { version = "0.6.0", path = "misc/connection-limits" }
Expand Down Expand Up @@ -102,7 +102,7 @@ libp2p-rendezvous = { version = "0.17.0", path = "protocols/rendezvous" }
libp2p-request-response = { version = "0.29.0", path = "protocols/request-response" }
libp2p-server = { version = "0.12.7", path = "misc/server" }
libp2p-stream = { version = "0.4.0-alpha", path = "protocols/stream" }
libp2p-swarm = { version = "0.47.0", path = "swarm" }
libp2p-swarm = { version = "0.48.0", path = "swarm" }
libp2p-swarm-derive = { version = "=0.35.1", path = "swarm-derive" } # `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required.
libp2p-swarm-test = { version = "0.6.0", path = "swarm-test" }
libp2p-tcp = { version = "0.44.0", path = "transports/tcp" }
Expand All @@ -111,7 +111,7 @@ libp2p-uds = { version = "0.43.0", path = "transports/uds" }
libp2p-upnp = { version = "0.5.0", path = "protocols/upnp" }
libp2p-webrtc = { version = "0.9.0-alpha.1", path = "transports/webrtc" }
libp2p-webrtc-utils = { version = "0.4.0", path = "misc/webrtc-utils" }
libp2p-webrtc-websys = { version = "0.4.0", path = "transports/webrtc-websys" }
libp2p-webrtc-websys = { version = "0.4.1", path = "transports/webrtc-websys" }
libp2p-websocket = { version = "0.45.2", path = "transports/websocket" }
libp2p-websocket-websys = { version = "0.5.0", path = "transports/websocket-websys" }
libp2p-webtransport-websys = { version = "0.5.1", path = "transports/webtransport-websys" }
Expand All @@ -123,10 +123,12 @@ env_logger = "0.11"
futures = "0.3.30"
futures-bounded = { version = "0.2.4" }
futures-rustls = { version = "0.26.0", default-features = false }
getrandom = "0.2"
if-watch = "3.2.1"
futures-timer = { version = "3" }
getrandom = { version = "0.2", features = ["js"] }
hashlink = "0.10.0"
hickory-proto = { version = "0.25.2", default-features = false }
hickory-resolver = { version = "0.25.2", default-features = false }
if-watch = "3.2.1"
multiaddr = "0.18.1"
multihash = "0.19.1"
multistream-select = { version = "0.13.0", path = "misc/multistream-select" }
Expand All @@ -141,8 +143,8 @@ tokio = { version = "1.38", default-features = false }
tracing = "0.1.41"
tracing-subscriber = "0.3.19"
unsigned-varint = { version = "0.8.0" }
wasm-bindgen-futures = "0.4"
web-time = "1.1.0"
hashlink = "0.10.0"

[patch.crates-io]

Expand Down
4 changes: 2 additions & 2 deletions examples/browser-webrtc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions interop-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
5 changes: 5 additions & 0 deletions libp2p/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.57.0

- Remove `wasm-bindgen` feature and make `wasm` support implicit.
See [PR 6102](https://github.com/libp2p/rust-libp2p/pull/6102)

## 0.56.0

- Remove `async-std` support.
Expand Down
10 changes: 5 additions & 5 deletions libp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p"
edition.workspace = true
rust-version = { workspace = true }
description = "Peer-to-peer networking library"
version = "0.56.0"
version = "0.57.0"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down Expand Up @@ -42,7 +42,6 @@ full = [
"tls",
"tokio",
"uds",
"wasm-bindgen",
"webrtc-websys",
"websocket-websys",
"websocket",
Expand Down Expand Up @@ -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"]
Expand All @@ -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 }
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions libp2p/src/builder/phase/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand All @@ -37,7 +37,7 @@ impl SwarmBuilder<NoProviderSpecified, ProviderPhase> {

/// 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<WasmBindgen, TcpPhase> {
SwarmBuilder {
keypair: self.keypair,
Expand Down
8 changes: 3 additions & 5 deletions libp2p/src/builder/phase/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ pub struct SwarmPhase<T, B> {
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<T, B> SwarmBuilder<$providerPascalCase, SwarmPhase<T, B>> {
pub fn with_swarm_config(
self,
Expand Down Expand Up @@ -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()
);
3 changes: 3 additions & 0 deletions protocols/gossipsub/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
- Fix mesh not being constructed even when not adding any peer.
See [PR 6100](https://github.com/libp2p/rust-libp2p/pull/6100)

- Remove `wasm-bindgen` feature and make `wasm` support implicit.
See [PR 6102](https://github.com/libp2p/rust-libp2p/pull/6102)

## 0.49.0

- Feature gate metrics related code. This changes some `Behaviour` constructor methods.
Expand Down
8 changes: 5 additions & 3 deletions protocols/gossipsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

[dependencies]
Expand All @@ -23,8 +22,7 @@ bytes = "1.6"
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 }
Expand All @@ -49,6 +47,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]
Expand Down
5 changes: 5 additions & 0 deletions swarm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +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)

## 0.47.0

- Remove `async-std` support.
Expand Down
9 changes: 5 additions & 4 deletions swarm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-swarm"
edition.workspace = true
rust-version = { workspace = true }
description = "The libp2p swarm"
version = "0.47.0"
version = "0.48.0"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -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 }
libp2p-core = { workspace = true }
libp2p-identity = { workspace = true }
Expand All @@ -25,15 +24,17 @@ multistream-select = { workspace = true }
rand = "0.8"
smallvec = "1.13.2"
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"
Expand Down
4 changes: 2 additions & 2 deletions swarm/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<dyn Future<Output = ()> + Send>>) {
wasm_bindgen_futures::spawn_local(future)
Expand Down
2 changes: 1 addition & 1 deletion swarm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ impl Config {
/// task()
/// }
/// ```
#[cfg(feature = "wasm-bindgen")]
#[cfg(target_arch = "wasm32")]
pub fn with_wasm_executor() -> Self {
Self::with_executor(crate::executor::WasmBindgenExecutor)
}
Expand Down
5 changes: 5 additions & 0 deletions transports/webrtc-websys/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.4.1

- Require `getrandom/js` feature only under `wasm` target.
See [PR 6102](https://github.com/libp2p/rust-libp2p/pull/6102)

## 0.4.0

- Cut stable release.
Expand Down
8 changes: 5 additions & 3 deletions transports/webrtc-websys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ license = "MIT"
name = "libp2p-webrtc-websys"
repository = "https://github.com/libp2p/rust-libp2p"
rust-version = { workspace = true }
version = "0.4.0"
version = "0.4.1"
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 }
Expand All @@ -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
2 changes: 1 addition & 1 deletion wasm-tests/webtransport-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down
Loading