From d26237b1c2f02ab33e2564c545cc66b5867b5e38 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 30 Sep 2022 15:16:24 +1000 Subject: [PATCH 1/6] Deprecate executor specific features for sub-crates --- Cargo.toml | 18 +++++++++----- src/lib.rs | 73 ++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 74 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 38afecb9372..45fab963021 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,18 +12,17 @@ categories = ["network-programming", "asynchronous"] [features] full = [ + "async-std", "autonat", "dcutr", "deflate", - "dns-async-std", - "dns-tokio", + "dns", "ecdsa", "floodsub", "gossipsub", "identify", "kad", - "mdns-async-io", - "mdns-tokio", + "mdns", "metrics", "mplex", "noise", @@ -36,8 +35,10 @@ full = [ "rsa", "secp256k1", "serde", + "tcp", "tcp-async-io", "tcp-tokio", + "tokio", "uds", "wasm-bindgen", "wasm-ext", @@ -48,6 +49,7 @@ full = [ autonat = ["dep:libp2p-autonat"] dcutr = ["dep:libp2p-dcutr", "libp2p-metrics?/dcutr"] deflate = ["dep:libp2p-deflate"] +dns = ["dep:libp2p-dns"] dns-async-std = ["dep:libp2p-dns", "libp2p-dns?/async-std"] dns-tokio = ["dep:libp2p-dns", "libp2p-dns?/tokio"] floodsub = ["dep:libp2p-floodsub"] @@ -55,6 +57,7 @@ identify = ["dep:libp2p-identify", "libp2p-metrics?/identify"] kad = ["dep:libp2p-kad", "libp2p-metrics?/kad"] gossipsub = ["dep:libp2p-gossipsub", "libp2p-metrics?/gossipsub"] metrics = ["dep:libp2p-metrics"] +mdns = ["dep:libp2p-mdns"] mdns-async-io = ["dep:libp2p-mdns", "libp2p-mdns?/async-io"] mdns-tokio = ["dep:libp2p-mdns", "libp2p-mdns?/tokio"] mplex = ["dep:libp2p-mplex"] @@ -65,6 +68,7 @@ pnet = ["dep:libp2p-pnet"] relay = ["dep:libp2p-relay", "libp2p-metrics?/relay"] request-response = ["dep:libp2p-request-response"] rendezvous = ["dep:libp2p-rendezvous"] +tcp = ["dep:libp2p-tcp"] tcp-async-io = ["dep:libp2p-tcp", "libp2p-tcp?/async-io"] tcp-tokio = ["dep:libp2p-tcp", "libp2p-tcp?/tokio"] uds = ["dep:libp2p-uds"] @@ -77,6 +81,8 @@ secp256k1 = ["libp2p-core/secp256k1"] rsa = ["libp2p-core/rsa"] ecdsa = ["libp2p-core/ecdsa"] serde = ["libp2p-core/serde", "libp2p-kad?/serde", "libp2p-gossipsub?/serde"] +tokio = ["libp2p-mdns?/tokio", "libp2p-tcp?/tokio", "libp2p-dns?/tokio"] +async-std = ["libp2p-mdns?/async-io", "libp2p-tcp?/async-io", "libp2p-dns?/async-std"] [package.metadata.docs.rs] all-features = true @@ -91,7 +97,7 @@ lazy_static = "1.2" libp2p-autonat = { version = "0.8.0", path = "protocols/autonat", optional = true } libp2p-core = { version = "0.37.1", path = "core" } -libp2p-dcutr = { version = "0.7.0", path = "protocols/dcutr", optional = true } +libp2p-dcutr = { version = "0.7.0", path = "protocols/dcutr", optional = true } libp2p-floodsub = { version = "0.40.1", path = "protocols/floodsub", optional = true } libp2p-identify = { version = "0.40.1", path = "protocols/identify", optional = true } libp2p-kad = { version = "0.41.0", path = "protocols/kad", optional = true } @@ -128,7 +134,7 @@ libp2p-gossipsub = { version = "0.42.1", path = "protocols/gossipsub", optional async-std = { version = "1.6.2", features = ["attributes"] } async-trait = "0.1" env_logger = "0.9.0" -clap = {version = "3.1.6", features = ["derive"]} +clap = { version = "3.1.6", features = ["derive"] } tokio = { version = "1.15", features = ["io-util", "io-std", "macros", "rt", "rt-multi-thread"] } [workspace] diff --git a/src/lib.rs b/src/lib.rs index 96a197cf516..2c8b2a71c3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,14 +54,31 @@ pub use libp2p_dcutr as dcutr; #[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))] #[doc(inline)] pub use libp2p_deflate as deflate; -#[cfg(any(feature = "dns-async-std", feature = "dns-tokio"))] +#[deprecated( + since = "0.49.0", + note = "The `dns-tokio` and `dns-async-std` features are deprecated. Use the new `dns` feature together with the `tokio` or `async-std` features." +)] +#[cfg(all( + any(feature = "dns-tokio", feature = "dns-async-std"), + not(feature = "dns") +))] +#[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))] #[cfg_attr( docsrs, - doc(cfg(any(feature = "dns-async-std", feature = "dns-tokio"))) + doc(cfg(any(feature = "dns-tokio", feature = "dns-async-std"))) )] +pub mod dns { + #[doc(inline)] + pub use libp2p_dns::*; +} + +#[cfg(feature = "dns")] #[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))] -#[doc(inline)] -pub use libp2p_dns as dns; +#[cfg_attr(docsrs, doc(cfg(feature = "dns")))] +pub mod dns { + #[doc(inline)] + pub use libp2p_dns::*; +} #[cfg(feature = "floodsub")] #[cfg_attr(docsrs, doc(cfg(feature = "floodsub")))] #[doc(inline)] @@ -79,14 +96,31 @@ pub use libp2p_identify as identify; #[cfg_attr(docsrs, doc(cfg(feature = "kad")))] #[doc(inline)] pub use libp2p_kad as kad; -#[cfg(any(feature = "mdns-async-io", feature = "mdns-tokio"))] +#[deprecated( + since = "0.49.0", + note = "The `mdns-tokio` and `mdns-async-io` features are deprecated. Use the new `mdns` feature together with the `tokio` or `async-std` features." +)] +#[cfg(all( + any(feature = "mdns-async-io", feature = "mdns-tokio"), + not(feature = "mdns") +))] +#[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))] #[cfg_attr( docsrs, doc(cfg(any(feature = "mdns-tokio", feature = "mdns-async-io"))) )] +pub mod mdns { + #[doc(inline)] + pub use libp2p_mdns::*; +} + +#[cfg(feature = "mdns")] #[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))] -#[doc(inline)] -pub use libp2p_mdns as mdns; +#[cfg_attr(docsrs, doc(cfg(feature = "mdns")))] +pub mod mdns { + #[doc(inline)] + pub use libp2p_mdns::*; +} #[cfg(feature = "metrics")] #[cfg_attr(docsrs, doc(cfg(feature = "metrics")))] #[doc(inline)] @@ -125,11 +159,28 @@ pub use libp2p_rendezvous as rendezvous; pub use libp2p_request_response as request_response; #[doc(inline)] pub use libp2p_swarm as swarm; -#[cfg(any(feature = "tcp-async-io", feature = "tcp-tokio"))] -#[cfg_attr(docsrs, doc(cfg(any(feature = "tcp-async-io", feature = "tcp-tokio"))))] +#[deprecated( + since = "0.49.0", + note = "The `tcp-tokio` and `tcp-async-io` features are deprecated. Use the new `tcp` feature together with the `tokio` or `async-std` features." +)] +#[cfg(all( + any(feature = "tcp-tokio", feature = "tcp-async-io"), + not(feature = "tcp") +))] #[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))] -#[doc(inline)] -pub use libp2p_tcp as tcp; +#[cfg_attr(docsrs, doc(cfg(any(feature = "tcp-tokio", feature = "tcp-async-io"))))] +pub mod tcp { + #[doc(inline)] + pub use libp2p_tcp::*; +} + +#[cfg(feature = "tcp")] +#[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))] +#[cfg_attr(docsrs, doc(cfg(feature = "tcp")))] +pub mod tcp { + #[doc(inline)] + pub use libp2p_tcp::*; +} #[cfg(feature = "uds")] #[cfg_attr(docsrs, doc(cfg(feature = "uds")))] #[doc(inline)] From 2dcbe30f93e7ce672759b381dd255fc0fd39f70b Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 30 Sep 2022 15:19:04 +1000 Subject: [PATCH 2/6] Add changelog entry --- CHANGELOG.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1cf6eed30c..662bdb4d94d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,16 @@ - Remove default features. You need to enable required features explicitly now. As a quick workaround, you may want to use the new `full` feature which activates all features. See [PR 2918]. +- Introduce `tokio` and `async-std` features and deprecate the following ones: + - `tcp-tokio` in favor of `tcp` + `tokio` + - `mdns-tokio` in favor of `mdns` + `tokio` + - `dns-tokio` in favor of `dns` + `tokio` + - `tcp-async-io` in favor of `tcp` + `async-std` + - `mdns-async-io` in favor of `mdns` + `async-std` + - `dns-async-std` in favor of `dns` + `async-std` + + See [PR XXXX]. + - Update individual crates. - Update to [`libp2p-autonat` `v0.8.0`](protocols/autonat/CHANGELOG.md#0080). - Update to [`libp2p-core` `v0.37.0`](core/CHANGELOG.md#0370). @@ -75,7 +85,8 @@ - Update to [`libp2p-websocket` `v0.39.0`](transports/websocket/CHANGELOG.md#0390). - Update to [`libp2p-yamux` `v0.41.0`](muxers/mplex/CHANGELOG.md#0410). -- [PR 2918]: https://github.com/libp2p/rust-libp2p/pull/2918 +[PR 2918]: https://github.com/libp2p/rust-libp2p/pull/2918 +[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX # 0.48.0 From 54c65992113eaadfd97843930e873429257b163f Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 30 Sep 2022 15:28:11 +1000 Subject: [PATCH 3/6] Apply suggestions from code review --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 662bdb4d94d..03b343314ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,7 +56,7 @@ - `mdns-async-io` in favor of `mdns` + `async-std` - `dns-async-std` in favor of `dns` + `async-std` - See [PR XXXX]. + See [PR 2962]. - Update individual crates. - Update to [`libp2p-autonat` `v0.8.0`](protocols/autonat/CHANGELOG.md#0080). @@ -86,7 +86,7 @@ - Update to [`libp2p-yamux` `v0.41.0`](muxers/mplex/CHANGELOG.md#0410). [PR 2918]: https://github.com/libp2p/rust-libp2p/pull/2918 -[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX +[PR 2962]: https://github.com/libp2p/rust-libp2p/pull/2962 # 0.48.0 From 830acc1404326cde06fddc6cd27408f0fb37090d Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 30 Sep 2022 16:23:27 +1000 Subject: [PATCH 4/6] Feature-gate `development_transport` correctly We only want to emit the deprecation warning in case a user uses the old features and _not_ the new ones. This assumes that a user upgrades properly, i.e. adds the new `tokio` or `async-std` feature AND removes the old `tcp-tokio` feature from the list. We need to use this rather complex cfg expression because otherwise, our CI won't pass. We run clippy with `--all-features`, thus just detecting for presence of the `tcp-async-io` feature for example will always flag our examples as using deprecated code. --- src/lib.rs | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2c8b2a71c3b..a345a64deab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -232,8 +232,10 @@ pub use libp2p_swarm_derive::NetworkBehaviour; /// > reserves the right to support additional protocols or remove deprecated protocols. #[cfg(all( not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), - feature = "tcp-async-io", - feature = "dns-async-std", + any( + all(feature = "tcp-async-io", feature = "dns-async-std"), + all(feature = "tcp", feature = "dns", feature = "async-std") + ), feature = "websocket", feature = "noise", feature = "mplex", @@ -243,14 +245,26 @@ pub use libp2p_swarm_derive::NetworkBehaviour; docsrs, doc(cfg(all( not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), - feature = "tcp-async-io", - feature = "dns-async-std", + any( + all(feature = "tcp-async-io", feature = "dns-async-std"), + all(feature = "tcp", feature = "dns", feature = "async-std") + ), feature = "websocket", feature = "noise", feature = "mplex", feature = "yamux" ))) )] +#[cfg_attr( + all( + any(feature = "tcp-async-io", feature = "dns-async-std"), + not(feature = "async-std") + ), + deprecated( + since = "0.49.0", + note = "The `tcp-async-io` and `dns-async-std` features are deprecated. Use the new `tcp` and `dns` features together with the `async-std` feature." + ) +)] pub async fn development_transport( keypair: identity::Keypair, ) -> std::io::Result> { @@ -292,8 +306,10 @@ pub async fn development_transport( /// > reserves the right to support additional protocols or remove deprecated protocols. #[cfg(all( not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), - feature = "tcp-tokio", - feature = "dns-tokio", + any( + all(feature = "tcp-tokio", feature = "dns-tokio"), + all(feature = "tcp", feature = "dns", feature = "tokio") + ), feature = "websocket", feature = "noise", feature = "mplex", @@ -303,14 +319,26 @@ pub async fn development_transport( docsrs, doc(cfg(all( not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")), - feature = "tcp-tokio", - feature = "dns-tokio", + any( + all(feature = "tcp-tokio", feature = "dns-tokio"), + all(feature = "tcp", feature = "dns", feature = "tokio") + ), feature = "websocket", feature = "noise", feature = "mplex", feature = "yamux" ))) )] +#[cfg_attr( + all( + any(feature = "tcp-tokio", feature = "dns-tokio"), + not(feature = "tokio") + ), + deprecated( + since = "0.49.0", + note = "The `tcp-tokio` and `dns-tokio` features are deprecated. Use the new `tcp` and `dns` feature together with the `tokio` feature." + ) +)] pub fn tokio_development_transport( keypair: identity::Keypair, ) -> std::io::Result> { From 09a301f9b4d4e3738c7904369e97b0d45cafa0b3 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 30 Sep 2022 16:26:05 +1000 Subject: [PATCH 5/6] Don't include old features in `full` feature --- Cargo.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 45fab963021..a2859f36533 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,8 +36,6 @@ full = [ "secp256k1", "serde", "tcp", - "tcp-async-io", - "tcp-tokio", "tokio", "uds", "wasm-bindgen", From 44b58cc8f8097b31f810420f97332826454ff77a Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 30 Sep 2022 16:35:51 +1000 Subject: [PATCH 6/6] Include deprecated features in full Otherwise CI will not pass once https://github.com/libp2p/rust-libp2p/pull/2963 actually checks it properly. --- Cargo.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index a2859f36533..1a720ec01de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,12 +17,16 @@ full = [ "dcutr", "deflate", "dns", + "dns-async-std", + "dns-tokio", "ecdsa", "floodsub", "gossipsub", "identify", "kad", "mdns", + "mdns-async-io", + "mdns-tokio", "metrics", "mplex", "noise", @@ -36,6 +40,8 @@ full = [ "secp256k1", "serde", "tcp", + "tcp-async-io", + "tcp-tokio", "tokio", "uds", "wasm-bindgen",