-
Notifications
You must be signed in to change notification settings - Fork 265
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
Bitcoin hashes no default features #410
Bitcoin hashes no default features #410
Conversation
Mirror the whitespacing in `rust-bitcoin` by doing: - Only use single line of whitespace between sections - Separate optional dependencies from non-optional ones
Currently we use default features for the `bitcoin_hashes` dependency, doing so breaks the `no-std` feature in `rust-bitcoin` because `std` is part of `bitcoin_hashes` default feature set. Disable `bitcoin_hashes` default features, no changes to `rust-bitcoin` are require after this change since we manually turn on `std` and `alloc` as part of the `std`/`no-std` features of `rust-bitcoin`. For other users of `rust-secp256k1` this is a breaking change but is unlikely to cause too much bother because `std` is so commonly used.
Looks good but watch out for compatibility hazards. We should at least test the crate with features |
IIUC there is now no way of turning on We do all combinations in |
I believe so.
Each external crate with optional Now that I had to explained it it occurred to me |
If this PR compiles without problems, does that mean we don't use any std functionality of |
@thomaseizinger yes, I'm curious, so will check why. Update: checked and it's all very sensible. We're not missing anything. :) |
I've added an additional patch that adds features |
Cargo.toml
Outdated
rand-std = ["rand/std"] | ||
serde-std = ["serde/std"] |
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.
I don't think proactively adding these feature is very valuable because forward-compatibility is not affected. They are only helpful for convenience. If you took inspiration from ln-types
then I'm sorry, I only did proper analysis now and I'll probably remove unused features from ln-types
.
Analysis:
- If
secp256k1
will add new stuff in the future depending onbitcoin_hashes/std
the feature can be added at that time. There's no backcompat-related harm in adding default-off feature later. - If
bitcoin_hashes
changes existing APIs to start requiringstd
it's a breaking change and it'll have to bump major version (or minor when major is 0). - Bumping major version of a publicly-visible dependency is a breaking change - in our case 100% every time because we reexport it.
Conclusion: adding the feature later is backwards compatible, adding it sooner is only a helper. YAGNI? Annoyance around adding can be solved by better tooling and the solution will be better. I will open an issue at cargo add
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.
I mentioned this in cargo add
feedback since it probably should be the default: https://internals.rust-lang.org/t/feedback-on-cargo-add-before-its-merged/16024/58?u=kixunil
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.
Thanks for the explanation. I've removed the serde-std
feature as suggested and left just what is needed to solve the problem we have (bitcoin-hashes-std
).
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.
YAGNI comment was particularly interesting. I've found myself recently not exactly sure where to draw the line on what we should include and what we shouldn't. Please keep reminding me of this if I lean to much towards adding YAGNI code. Thanks.
contrib/test.sh
Outdated
# Test features that will likely only be enabled along with `std`. | ||
cargo test --all --features="rand-std" | ||
cargo test --all --features="bitcoin-hashes-std" | ||
cargo test --all --features="serde-std" |
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.
These are correct but a bit confusing. How about having another variable with these and a comment explaining why they are separate?
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.
Good idea, done as suggested.
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.
Currently we use 'no default features' for the `bitcoin_hashes` dependency. Doing so means that if users want the `std` feature they need to explicitly add a `bitcoin_hashes` dependency even though we re-export `bitcoin_hashes` as `hashes`. This means that in the common case the re-export is pointless. As an example, `rust-bitcoin` unnecessarily requires an explicit dependency on `bitcoin_hashes`. Add `bitcoin-hashes-std` feature so that users do not need an explicit dependency in the common use case. Change the test matrix to only test '*-std' features when 'std' is enabled since enabling one without the other is illogical. Please note, this replaces the test run of feature 'std'+'rand'+'rand-std' with just 'std'+'rand-std' because enabling 'rand-std' enables 'rand' so the explicit additional feature is redundant.
3697003
to
6bcf3ea
Compare
Force push includes changes only to the final patch to remove the |
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.
ACK 6bcf3ea
Currently we use default features for the
bitcoin_hashes
dependency, doing so breaks theno-std
feature inrust-bitcoin
becausestd
is part ofbitcoin_hashes
default feature set.Disable
bitcoin_hashes
default features, no changes torust-bitcoin
are require after this change since we manually turn onstd
andalloc
as part of thestd
/no-std
features ofrust-bitcoin
.For other users of
rust-secp256k1
this is a breaking change but is unlikely to cause too much bother becausestd
is so commonly used.This PR resolves an open issue in
rust-bitcoin
, see issue for discussion.