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
Replace feature serde with use-serde #373
Conversation
Codecov Report
@@ Coverage Diff @@
## master #373 +/- ##
=========================================
Coverage ? 81.93%
=========================================
Files ? 39
Lines ? 7185
Branches ? 0
=========================================
Hits ? 5887
Misses ? 1298
Partials ? 0
Continue to review full report at Codecov.
|
I don't like this. The feature-can't-collide-with-dep issue is clearly a Cargo issue, and we shouldn't be adapting our code for that. Also this doesn't really solve anything. People accidentally using the A better mitigation could be a list of existing features in the README. |
well the code is still flawed. it checks for a feature |
Sure, but that is because the only way to check of a dependency is present is through Probably too late to change that.. |
We do have a feature The existing approach tries to require the minimum amount of features for each part of the code. |
So do you think we should replace the current includes to this?
|
Good explanation on how to avoid this issue: rust-lang/api-guidelines#180 @Kixunil proposed a good solution which we use in LNP/BP library. It works the following way: [dependencies]
serde_crate = { package = "serde", version = "~1.0.106", features = ["derive"], optional = true }
[features]
serde = ["serde_crate", "bitcoin/use-serde", "miniscript/serde"] #[cfg(feature = "serde")]
#[macro_use]
extern crate serde_crate as serde;
serde = { version = "~1.0.111", features = ["derive"] } |
Needs rebase, and probably should also be replaced wholesale with @dr-orlovsky's solution. |
Renaming packages is only possible with 1.31+ |
What is the actual problem with the current approach? That some users don't read the docs and don't know about the |
@stevenroose naming features the same as crates is considered idiomatic Rust. It's mostly consistent across ecosystem (although not everyone follows it, people are slowly moving towards that style). @dtolnay do you have any tip for solving this in older versions of Rust, please? |
I wonder if we should have a Rust 2018 tracking issue and start tagging things that are blocked on it. (We should open issues for code cleanup/architecture stuff as well.) Would be good to have a clear picture of what we're missing by being on 1.29. |
needs rebase |
Is there a point? it sounded like this is Concept NACK from almost everyone? We could instead just throw this at the top of lib.rs: #[cfg(all(feature = "serde", not(feature = "use-serde")))]
compile_error!("To use serde you must enable the use-serde feature"); which will throw an error for anyone enabling I personally still prefer being consistent and if we'll change this in the future then we will go over all the cfg's and change them, on the other hand I don't want someone enabling |
@apoelstra: done #510 |
Thanks! Closing as I think this is blocked on Rust 2018. I wouldn't be opposed to a nice complier error as Elichai suggests. But it should probably happen in another PR. |
I also like @elichai compiler error idea |
Implement dr-orlovsky and Kixunil's suggestion in GitHub PR rust-bitcoin#373. Use package renaming so that we can have a feature `serde` instead of having `use-serde`.
I tried to get the idea above about package renaming but I cannot get it to build. Build fails for all the serde derives. (Even with edition 2018 enabled.) |
@tcharding the PR looks incomplete. There needs to be a change in |
I read this comment again this morning with fresh eyes but I still don't understand sorry. My comment was just a note for future readers that I had tried to implement the suggestion using package rename but was unable to get it working. (A note to myself as much as anyone else because I tried twice at different times.) |
I guess I'll just do it then. :) |
Done #1006 |
Legend! |
2e7effc Feature `use-serde` renamed to `serde` (Martin Habovstiak) Pull request description: Features activating external crates are supposed to have same name as those crates. However we depend on same feature in other crates so we need a separate feature. After MSRV bump it is possible to rename the crates and features so we can now fix this inconsistency. Sadly, derive can't see that the crate was renamed so all derives must be told to use the other one. Replaces #373 ACKs for top commit: apoelstra: ACK 2e7effc Tree-SHA512: b20364b9e8f30c2269bef915e821b2b2ec929e71dd0e88af2bc3a021821f87011d35e095cb8efe99add77a23dde940a17537eb387fb4582b05c57c8679969eb0
This will fix problems like #372
Basically the problem is that cargo doesn't allow colliding package names with feature names, so we had to use the feature
use-serde
instead ofserde
(common practice)But now some users can get confuse and pass
serde
by mistake which will make it miscompile.I replaced all usages of
feature = "serde"
withfeature = "use-serde"
. we could also add to the CI to test the "features" serde and hex such that it will still compile.another option is to add a build.rs file that will test if
serde
is set withoutuse-serde
and will produce a meaningful error for the user.Introduced in: #215