-
Notifications
You must be signed in to change notification settings - Fork 745
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
Lift dependencies to the workspace (Part 1) #2070
Conversation
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.
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
@@ -4,6 +4,9 @@ edition = "2021" | |||
repository = "https://github.com/paritytech/polkadot-sdk.git" | |||
license = "GPL-3.0-only" | |||
|
|||
[workspace.dependencies] | |||
log = { version = "^0.4.20", default-features = false } |
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.
log = { version = "^0.4.20", default-features = false } | |
log = "0.4.20" |
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 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
@@ -10,7 +10,7 @@ async-trait = "0.1.73" | |||
codec = { package = "parity-scale-codec", version = "3.0.0", features = [ "derive" ] } | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in case of the log
it looks like it doesn't even have any default features.
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.
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 = true
all 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What a fun ❤️
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is what @ggwpez linked above.
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.
So can we go ahead with this:
default-features = false
in the root workspace for all crates that have a default feature- nothing in the crates if the default-features should be true
default-features = false
in each crate like before when they should be disabled.
This should make the diff here a bit shorter.
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.
If that works, lets do this.
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. |
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.
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.20
everywherelog
to the workspaceStarting with a simpler one after seeing #2065 from @jsdw.
This sets the
default-features
tofalse
in the root and then overwrites that in each create to its original value. This is necessary since otherwise thedefault
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.