Lift dependencies to the workspace (Part 1)#2070
Conversation
bkchr
left a comment
There was a problem hiding this comment.
We should not disable the default features in the workspace. IMO this "feels" weird.
And BTW, the wasm-builder currently not supports workspace deps.
Cargo.toml
Outdated
| license = "GPL-3.0-only" | ||
|
|
||
| [workspace.dependencies] | ||
| log = { version = "^0.4.20", default-features = false } |
There was a problem hiding this comment.
| log = { version = "^0.4.20", default-features = false } | |
| log = "0.4.20" |
There was a problem hiding this comment.
I saw that if the default-features are not disabled in the workspace, then they cannot be disabled lateron in the crates, since features are additive.
So AFAIK it is best practice to disable them at the workspace and then re-enable at the crate level - if desired. It is explained here rust-lang/cargo#11329
| dyn-clone = "1.0.12" | ||
| futures = "0.3.28" | ||
| log = "0.4.20" | ||
| log = { workspace = true, default-features = true } |
There was a problem hiding this comment.
| log = { workspace = true, default-features = true } | |
| log = { workspace = true } |
This and all the other places you have done this "feel weird"
There was a problem hiding this comment.
Yea I think the default-features = true should be implicit in this case, so we should be able to omit it.
There was a problem hiding this comment.
👍
I think it makes sense to do default-features = false in the workspace Cargo.toml on a case-by-case basis if we actually don't want to always enable all of the features for a given dependency, but this probably shouldn't be done by default (at least not blindly), and if you're adding a default-features = true all over the place then it's most likely the wrong thing to do. (If a crate needs a specific feature it should explicitly say which one, instead of doing default-features = true.)
There was a problem hiding this comment.
And in case of the log it looks like it doesn't even have any default features.
There was a problem hiding this comment.
And in case of the log it looks like it doesn't even have any default features.
Hm. Then we would need to check on every version update whether some default features were added? I guess that could work since the WASM build should fail when it tries to pull in std.
and if you're adding a
default-features = trueall over the place then it's most likely the wrong thing to do.
Yes I agree if this is the case in 100% of the occurences (and under the assumption that this would not change in the future). But for a dependency where we sometimes want default-features and sometimes not, then we need to set it to false in the workspace i think.
If a crate needs a specific feature it should explicitly say which one, instead of doing
default-features = true
If this is the goal, then i dont think that it is automatable.
There was a problem hiding this comment.
I ran into a similar thing when I tried this; you need to specify default-features = false in the worksapce in order to be able to use default-features on that dependency in the crate's Cargo.toml, else you get a warning like:
warning: ..polkadot-sdk/polkadot/xcm/Cargo.toml: `default-features` is ignored for scale-info,
since `default-features` was not specified for `workspace.dependencies.scale-info`, this could
become a hard error in the future
There was a problem hiding this comment.
So can we go ahead with this:
default-features = falsein the root workspace for all crates that have a default feature- nothing in the crates if the default-features should be true
default-features = falsein each crate like before when they should be disabled.
This should make the diff here a bit shorter.
What does this mean? That we cannot use it for the no-std runtime dependencies? |
Anything crate that is using wasm builder will not work right now with a workspace dependency. We just need to add support for this. |
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
How to do this? I see that all CI checks are green. It should catch that or not @bkchr? |
Thinking again about this, my comment wasn't that correct. As we include the real runtime crate as dependency, it is fetching its deps from its original workspace. So yeah, just continue to merge this pr! |
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
|
@koute i guess you are quite busy, but i settled on this idiomatic pattern now:
I think this pattern is applicable to every dependency, so we dont have to think much and just use some tool to replace it. |
koute
left a comment
There was a problem hiding this comment.
Looks mostly good to me, although in this specific case of log all of the default-features are pretty much useless since the crate doesn't actually have any default features in the first place, so it's just noise that will confuse people.
So I would suggest that we just use a bare log = { workspace = true } everywhere.
Yes this could be done for now. But if we ever update |
I don't see a problem with this, considering any changes to the default features will have to be semver-compatible anyway. And the "lost the information in which crates we would like to enable them" is, well, complete nonsense considering we're talking about features which don't exist yet. (: How do you know we want to enable a feature if we don't know what that feature is? Just because a given crate might enable some kind of a feature by default has nothing to do with whether we want to enable or disable it. And there is also no rule that in the client we should enable all of the features by default and in the runtime disable them. A given feature's value lies in what exactly that feature does, and not in whether it's enabled by default or not. |
Oh right. So it should not make a difference anyway until there is a major bump 🙃
Yea true. I only thought about our convention of treating default-features like |
|
I changed the default logic now to not write |
Changes (partial paritytech#994): - Set log to `0.4.20` everywhere - Lift `log` to the workspace Starting with a simpler one after seeing paritytech#2065 from @jsdw. This sets the `default-features` to `false` in the root and then overwrites that in each create to its original value. This is necessary since otherwise the `default` features are additive and its impossible to disable them in the crate again once they are enabled in the workspace. I am using a tool to do this, so its mostly a test to see that it works as expected. --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Changes (partial #994):
0.4.20everywherelogto the workspaceStarting with a simpler one after seeing #2065 from @jsdw.
This sets the
default-featurestofalsein the root and then overwrites that in each create to its original value. This is necessary since otherwise thedefaultfeatures are additive and its impossible to disable them in the crate again once they are enabled in the workspace.I am using a tool to do this, so its mostly a test to see that it works as expected.