-
Notifications
You must be signed in to change notification settings - Fork 964
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
swarm-derive: Add prelude
configuration option to NetworkBehaviour
macro
#3055
Conversation
The fact that `libp2p-swarm-derive` is a separate crate is an implementation detail and only required because `cargo` needs to compile this crate separately. It semantically belongs to `libp2p-swarm` so this is where the tests should be.
This allows us to depend on the macro without depending on the entire `libp2p` crate which causes circular dependencies in our tests.
This pull request has merge conflicts. Could you please resolve them @thomaseizinger? 🙏 |
This pull request has merge conflicts. Could you please resolve them @thomaseizinger? 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thomas!
Note that this also turns out to be a requirement for libp2p/test-plans#72. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny nit pick. Otherwise this looks good to me.
/// Parses the `value` of a key=value pair in the `#[behaviour]` attribute into the requested type. | ||
/// | ||
/// Only `String` values are supported, e.g. `#[behaviour(foo="bar")]`. | ||
fn parse_attribute_value_by_key<T>(ast: &DeriveInput, key: &str) -> Option<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏
Co-authored-by: Max Inden <mail@max-inden.de>
libp2p-kad = { path = "../protocols/kad" } | ||
libp2p-ping = { path = "../protocols/ping" } | ||
libp2p-plaintext = { path = "../transports/plaintext" } | ||
libp2p-swarm-derive = { version = "0.30.2", path = "../swarm-derive" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thomaseizinger why define libp2p-swarm-derive
with a version here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy-paste error :)
…` macro (libp2p#3055) Currently, our `NetworkBehaviour` derive macro depends on the `libp2p` crate to be in scope. This prevents standalone usage which forces us to depend on `libp2p` in all our tests where we want to derive a `NetworkBehaviour`. This PR introduces a `prelude` option that - by default - points to `libp2p::swarm::derive_prelude`, a new module added to `libp2p_swarm`. With this config option, users of `libp2p_swarm` can now refer to the macro without depending on `libp2p`, breaking the circular dependency in our workspace. For consistency with the ecosystem, the macro is now also re-exported by `libp2p_swarm` instead of `libp2p` at the same position as the trait that it implements. Lastly, we introduce an off-by-default `macros` feature flag that shrinks the dependency tree for users that don't need the derive macro.
Description
I recommend patch-by-patch review.
Links to any relevant issues
libp2p_swarm
. I'd rather ship the newprelude
feature first and later use it across the workspace as the latter might create a lot of merge conflicts because basically all tests and manifests need to be touched. The tests are also an implementation detail whereas some of the changes to the macro are user-facing.crate
parameter to configurelibp2p
crate name #3006$crate
) rust-lang/rust#54363: This PR is basically a workaround for a missing feature in cargo/rust.Depends-On: #3081
Open Questions
Change checklist
Commit message body
Currently, our
NetworkBehaviour
derive macro depends on thelibp2p
crate to be in scope. This prevents standalone usage which forces us to depend onlibp2p
in all our tests where we want to derive aNetworkBehaviour
.This PR introduces a
prelude
option that - by default - points tolibp2p::swarm::derive_prelude
, a new module added tolibp2p_swarm
. With this config option, users oflibp2p_swarm
can now refer to the macro without depending onlibp2p
, breaking the circular dependency in our workspace. For consistency with the ecosystem, the macro is now also re-exported bylibp2p_swarm
instead oflibp2p
at the same position as the trait that it implements.Lastly, we introduce an off-by-default
macros
feature flag that shrinks the dependency tree for users that don't need the derive macro.