Skip to content
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

*: Use auto_doc_cfg instead of doc(cfg) attributes #2983

Merged
merged 19 commits into from
Oct 24, 2022

Conversation

umgefahren
Copy link
Contributor

Description

In developing #2975 we discovered that doc_cfg_auto is ready for use by our crate. Therefore we are using it to document items behind feature flags.

Links to any relevant issues

This closes #2950.

Open Questions

  • Should we add the doc_cfg_auto to every crate?

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

@umgefahren
Copy link
Contributor Author

Could you add the hacktoberfest-accepted label? @thomaseizinger

@umgefahren
Copy link
Contributor Author

I'm quite unsure about the changelogs here. We probably have to add an entry to every crate.

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need changelog entries for this.

Can you please:

  • Investigate, whether we can now remove the existing doc(cfg(...) uses
  • Post some screenshots of what the docs now look like compared to before

In reading about doc_auto_cfg, I've seen multiple uses of doc_cfg_hide feature as well which I think is used to fine-tune the output. Can you please spot-check some of our more complex cfg uses (e.g. in the root libp2p crate) and verify that it doesn't look horrendous or try to fix it if it does?

Thanks for working on this 😊

@umgefahren
Copy link
Contributor Author

"Looking horrendous" is a quite difficult standard. If we remove all custom doc(cfg( we get more complicated flags, but they are also more representative of the truth. So I think it's hard to judge here. I would be in favor of just abolishing doc(cfg( at the cost of maybe more complicated flags.

You requested some screenshots, so here we go:

Just doc_auto_cfg

Modules

image

Development transports

image

As it was before (just with doc_cfg)

Modules

image

Development transports

image

With doc_auto_cfg and doc_cfg_hide

This didn't really work or maybe I didn't understand something. If we want that effect I would go with the existing manual written doc_cfg on the main crate and everywhere we have them.

My Recommendation

If we really want simple flags (just for the features) we should just use the doc_cfg where they exist. Everywhere else doc_auto_cfg is probably fine. I can't see any reason to use doc_auto_cfg apart from hiding some cfgs from the library user (which i think is misleading).

On a little side note: For some reason there is no incremental compilation on this, so every reiteration takes some time.

Another note: We seem to be using #[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))] all the time which results in a massive flag. I might be mistaken, but it probably would just be easier to use: #[cfg(not(any(target_os = "unknown", target_family = "wasm")))] if that's really what we want. This results in this:

Modules

image

Development transports

image

@thomaseizinger
Copy link
Contributor

Okay, thanks a lot for this work!

Given the screenshots, I am in favor of removing all doc(cfg) attributes for just letting auto_cfg_doc do its job. We can fine-tune later if people complain that something doesn't make sense :)

@umgefahren
Copy link
Contributor Author

Anything to do for me?

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, just two more comments 😊

misc/keygen/Cargo.toml Outdated Show resolved Hide resolved
misc/quickcheck-ext/Cargo.toml Outdated Show resolved Hide resolved
@umgefahren
Copy link
Contributor Author

Done 🙂

@thomaseizinger thomaseizinger changed the title Adding doc_cfg_auto support to crate and all subcrates. *: Use auto_doc_cfg instead of doc(cfg) attributes Oct 10, 2022
Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me!

@mxinden Any objections in merging this?

misc/keygen/Cargo.toml Outdated Show resolved Hide resolved
misc/quickcheck-ext/Cargo.toml Outdated Show resolved Hide resolved
transports/plaintext/Cargo.toml Show resolved Hide resolved
Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, minus the one comment from @jxs.

@melekes and @elenaf9 can you do the corresponding changes in the new crates you are introducing?

@thomaseizinger
Copy link
Contributor

Looks good to me, minus the one comment from @jxs.

@melekes and @elenaf9 can you do the corresponding changes in the new crates you are introducing?

WebRTC doesn't have any feature-flags at this point. We could gate it all behind the tokio one though as no other implementation exists.

@melekes
Copy link
Contributor

melekes commented Oct 16, 2022

Looks good to me, minus the one comment from @jxs.
@melekes and @elenaf9 can you do the corresponding changes in the new crates you are introducing?

WebRTC doesn't have any feature-flags at this point. We could gate it all behind the tokio one though as no other implementation exists.

Soo do I need to make any changes or not? 😐

src/lib.rs Outdated
@@ -182,20 +169,16 @@ pub mod tcp {
pub use libp2p_tcp::*;
Copy link
Contributor

@elenaf9 elenaf9 Oct 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if that was already discussed, but could you explain again why the #[cfg_attr(docsrs, doc(cfg(feature = "..")))] flag is not removed for the crates that have extra features (like tcp/ dns / ..)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It hasn't been discussed, well spotted!

I think those should be removed too, yes! Line 166 here for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other words, every manually added #[cfg_attr(docsrs, doc(cfg(feature = "..")))] should be removed? I'm assuming yes, sorry that I missed that.

I did most of this task with Ripgrep, fd and neovim search and replace, so that might be the reason why i missed that. Thanks for the manual review :)

elenaf9 added a commit to kpp/rust-libp2p that referenced this pull request Oct 16, 2022
@thomaseizinger
Copy link
Contributor

Looks good to me, minus the one comment from @jxs.
@melekes and @elenaf9 can you do the corresponding changes in the new crates you are introducing?

WebRTC doesn't have any feature-flags at this point. We could gate it all behind the tokio one though as no other implementation exists.

Soo do I need to make any changes or not? neutral_face

I would be in favor. Especially with tokio, it is important that the socket is polled on a thread with an active reactor. Can you add put the transport into a libp2p_webrtc::tokio module and feature gate that on tokio?

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more comments but otherwise ready I believe!

Thank you!

protocols/dcutr/Cargo.toml Outdated Show resolved Hide resolved
protocols/relay/Cargo.toml Outdated Show resolved Hide resolved
src/lib.rs Outdated
@@ -182,20 +169,16 @@ pub mod tcp {
pub use libp2p_tcp::*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It hasn't been discussed, well spotted!

I think those should be removed too, yes! Line 166 here for example.

@melekes
Copy link
Contributor

melekes commented Oct 17, 2022

Looks good to me, minus the one comment from @jxs.
@melekes and @elenaf9 can you do the corresponding changes in the new crates you are introducing?

WebRTC doesn't have any feature-flags at this point. We could gate it all behind the tokio one though as no other implementation exists.

Soo do I need to make any changes or not? neutral_face

I would be in favor. Especially with tokio, it is important that the socket is polled on a thread with an active reactor. Can you add put the transport into a libp2p_webrtc::tokio module and feature gate that on tokio?

done in f7c8ab5

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two minor comments, otherwise LGTM!

muxers/yamux/Cargo.toml Outdated Show resolved Hide resolved
transports/uds/src/lib.rs Outdated Show resolved Hide resolved
umgefahren and others added 2 commits October 19, 2022 11:52
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks @umgefahren and @thomaseizinger for the work.

I suggest we tackle libp2p/test-plans#59 before merging here. Otherwise good to go from my end.

@thomaseizinger thomaseizinger merged commit fcadc83 into libp2p:master Oct 24, 2022
@umgefahren umgefahren deleted the use-rustdoc-auto-cfg branch October 24, 2022 07:56
@umgefahren umgefahren restored the use-rustdoc-auto-cfg branch October 24, 2022 07:56
@umgefahren umgefahren deleted the use-rustdoc-auto-cfg branch October 24, 2022 07:56
@umgefahren umgefahren restored the use-rustdoc-auto-cfg branch October 24, 2022 07:56
mergify bot pushed a commit that referenced this pull request Oct 9, 2023
Includes necessary package metadata to improve documentation on docs.rs (shows which items are behind a cfg).
Read more on: #2983

Pull-Request: #4599.
monoid pushed a commit to fluencelabs/rust-libp2p that referenced this pull request Oct 9, 2023
Includes necessary package metadata to improve documentation on docs.rs (shows which items are behind a cfg).
Read more on: libp2p#2983

Pull-Request: libp2p#4599.
umgefahren added a commit to umgefahren/rust-libp2p that referenced this pull request Mar 8, 2024
Co-authored-by: João Oliveira <hello@jxs.pt>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Properly set rustdoc attributes for docs.rs
6 participants