Skip to content

Document cargo features#633

Merged
apoelstra merged 1 commit intorust-bitcoin:masterfrom
Kixunil:doc-features
Sep 14, 2021
Merged

Document cargo features#633
apoelstra merged 1 commit intorust-bitcoin:masterfrom
Kixunil:doc-features

Conversation

@Kixunil
Copy link
Copy Markdown
Collaborator

@Kixunil Kixunil commented Jul 28, 2021

This documents cargo features in two ways: explictly in text and in code
using #[doc(cfg(...))] attribute where possible. Notably, this is
impossible for serde derives. The attribute is contitional and only
activated for docs.rs or explicit local builds.

This change also adds package.metadata.docs.rs field to Cargo.toml
which instructs docs.rs to build with relevant features and with
docsrs config activated enabling `#[doc(cfg(...))] attributes.

I also took the opportunity to fix a few missing spaces in nearby code.

Notes for reviewers:

dr-orlovsky
dr-orlovsky previously approved these changes Aug 9, 2021
Copy link
Copy Markdown
Collaborator

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

Thank you for a lot of careful work on this thing!

utACK, even if there are valid Nits in my comments, they can be addressed later in a separate PR, since any improvements to the docs exposing the items behind feature gates are better than nothing.

Two main comments:

  • Seems like we need to re-base onto master to take into account all changes in feature use from no_std 0.27 version (or do a follow-up PR to this one)
  • I will test this locally if all of the existing feature gates are exposed to docs once all of the commits in PR will pass CI and compile: @apoelstra usually puts this as a requirement for merging any PR into the rust-bitcoin. You can see more in PR #587, where I also had included the test script

src/lib.rs Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Seems we are missing alloc feature here, introduced by recent PR.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

You mean no-std which is documented below? I don't see any alloc PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Right, I mixed up with bitcoin_hashes which does have

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Finally somebody started introducing practice of [`Type`] instead of [Type]

src/util/misc.rs Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not sure why we have a feature gate here, when we anyway re-export them into public space above via a feature-gated export

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

TBH, I somewhat blindly added the attribute to each instance of #[cfg] I ripgreped. I could remove it but I'm also thinking keeping it may be good way to avoid accidentally messing up in refactors.

src/util/misc.rs Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ibid

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should't we just feature-gate the mod itself and not specific impls?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure rustdoc is that smart and it will do what we want. I could check later.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ibid

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ibid

@Kixunil
Copy link
Copy Markdown
Collaborator Author

Kixunil commented Aug 10, 2021

Squashed commits.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lol whoops, we definitely should not have feature-gated enum variants. Surprised nobody has complained about this.

Looks like Tamás and I did this in March 2018.

Nothing to do with this PR but we should fix it in another one.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, for normal enums that'd be breaking because some crate could do exhaustive match on it while other crate turns on the feature. I think it'd be fine for #[non_exhaustive] enums.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Opened #645 with a suggested solution.

apoelstra
apoelstra previously approved these changes Sep 8, 2021
Copy link
Copy Markdown
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 1e766d22b4c1bd6f080c7a35274ebd05953e44b6

Thank you for all this work! I would appreciate a fix for the typo but won't hold up merging for it.

dr-orlovsky
dr-orlovsky previously approved these changes Sep 10, 2021
Copy link
Copy Markdown
Collaborator

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

utACK 0670bdaef490ea100ab4dfb2b7ade829f66a67be

@apoelstra
Copy link
Copy Markdown
Member

Needs rebase

This documents cargo features in two ways: explictly in text and in code
using `#[doc(cfg(...))]` attribute where possible. Notably, this is
impossible for `serde` derives. The attribute is contitional and only
activated for docs.rs or explicit local builds.

This change also adds `package.metadata.docs.rs` field to `Cargo.toml`
which instructs docs.rs to build with relevant features and with
`docsrs` config activated enabling `#[doc(cfg(...))] attributes.

I also took the opportunity to fix a few missing spaces in nearby code.
@Kixunil
Copy link
Copy Markdown
Collaborator Author

Kixunil commented Sep 14, 2021

Done.

Copy link
Copy Markdown
Collaborator

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

ACK 95fb4e0

@Kixunil
Copy link
Copy Markdown
Collaborator Author

Kixunil commented Sep 14, 2021

Hmm, GH notified me that there was a fail but I don't see it here. The failure is a fluke (failed to download Rust).

Copy link
Copy Markdown
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 95fb4e0

@apoelstra apoelstra merged commit 65d8bda into rust-bitcoin:master Sep 14, 2021
@Kixunil Kixunil deleted the doc-features branch September 14, 2021 17:31
apoelstra added a commit to rust-bitcoin/rust-secp256k1 that referenced this pull request Jan 6, 2022
18f74d5 Clarify what does "less security" mean (Martin Habovstiak)
94c55b4 Fixed typos/grammar mistakes (Martin Habovštiak)
1bf0552 Documented features (Martin Habovstiak)

Pull request description:

  This documents the Cargo features making sure docs.rs shows warning for
  feature-gated items. They are also explicitly spelled out in the crate
  documentation.

  The PR is similar in spirit to rust-bitcoin/rust-bitcoin#633

ACKs for top commit:
  apoelstra:
    ACK 18f74d5

Tree-SHA512: 8aac3fc5fd8ee887d6b13606d66b3d11ce44662afb92228c4f8da6169e3f70ac6a005b328f427a91d307f8d36d091dcf24bfe4d17dfc034d02b578258719a90a
yancyribbens pushed a commit to yancyribbens/rust-bitcoin that referenced this pull request Mar 23, 2024
…error

50db03c cargo fmt (Andrew Poelstra)
220f101 ci: screw up imports for rust-lang/rust#121684 (Andrew Poelstra)
df069af ci: remove unnecessary imports of `bitcoin` (Andrew Poelstra)
3725549 ci: tighten import of `Vec` (Andrew Poelstra)
d441ccd ci: remove imports that are redundant with super::* (Andrew Poelstra)
b87b4fb remove sketchy `LikelyFalse` error (Andrew Poelstra)

Pull request description:

  This error would trigger on `l:0` on the basis that this is equivalent to `u:0` but always less efficient. There are no other "linting" errors like this in this library, and the C++ implementation doesn't have it, so we should drop it.

  Fixes rust-bitcoin#633

ACKs for top commit:
  tcharding:
    ACK 50db03c
  sanket1729:
    ACK 50db03c

Tree-SHA512: 30681e6abe7957b9fbe059e808d8057fd174ea156d1853960370d2fd63b032a500f85965a5c7424764df76ed804c62d9a781ae38cdc2b123e9b4b53308dd89f5
chain-forgexcr45 added a commit to chain-forgexcr45/rust-secp256k1 that referenced this pull request Sep 28, 2025
18f74d52422fc18f0e4c866203d7aa12c8faa3f9 Clarify what does "less security" mean (Martin Habovstiak)
94c55b4d09727433c606301d27173748c8ff36df Fixed typos/grammar mistakes (Martin Habovštiak)
1bf05523f072f833f388a1fe5e5d538fd00119c8 Documented features (Martin Habovstiak)

Pull request description:

  This documents the Cargo features making sure docs.rs shows warning for
  feature-gated items. They are also explicitly spelled out in the crate
  documentation.

  The PR is similar in spirit to rust-bitcoin/rust-bitcoin#633

ACKs for top commit:
  apoelstra:
    ACK 18f74d52422fc18f0e4c866203d7aa12c8faa3f9

Tree-SHA512: 8aac3fc5fd8ee887d6b13606d66b3d11ce44662afb92228c4f8da6169e3f70ac6a005b328f427a91d307f8d36d091dcf24bfe4d17dfc034d02b578258719a90a
william2332-limf added a commit to william2332-limf/rust-secp256k1 that referenced this pull request Oct 2, 2025
18f74d52422fc18f0e4c866203d7aa12c8faa3f9 Clarify what does "less security" mean (Martin Habovstiak)
94c55b4d09727433c606301d27173748c8ff36df Fixed typos/grammar mistakes (Martin Habovštiak)
1bf05523f072f833f388a1fe5e5d538fd00119c8 Documented features (Martin Habovstiak)

Pull request description:

  This documents the Cargo features making sure docs.rs shows warning for
  feature-gated items. They are also explicitly spelled out in the crate
  documentation.

  The PR is similar in spirit to rust-bitcoin/rust-bitcoin#633

ACKs for top commit:
  apoelstra:
    ACK 18f74d52422fc18f0e4c866203d7aa12c8faa3f9

Tree-SHA512: 8aac3fc5fd8ee887d6b13606d66b3d11ce44662afb92228c4f8da6169e3f70ac6a005b328f427a91d307f8d36d091dcf24bfe4d17dfc034d02b578258719a90a
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.

5 participants