-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add lint to explicitly set resolver in a virtual workspace #10112
Comments
There is an issue of people who are not using |
Crates != workspace though, that's why the issue is here to begin with. It's not sufficient to set resolver =2 in the crates cargo.toml, it has to be done in the workspace Cargo.toml I'm advocating for a lint that suggests explicitly setting the resolver (even if resolver = 1) in the workspace Cargo.toml |
As a minimum, I think it would make sense to warn (or generate a error) if a crate explicitly sets |
Having the default workspace resolver as v1 creates confusion in workspaces with all crates using |
Part of workspace inheritance is the ability for a member to inherit the |
To extract some discussion from #10910: The lint I propose is to emit a warning any time one of the members of a workspace has a different resolver to the workspace itself. This is necessary for binaries because developers will expect that when they Generally fixing this lint is just adding The biggest downside I see is that this will be instantaneously very noisy. I'm certain that 99% of virtual workspaces are currently setup incorrectly since I have never seen |
@Nemo157 do you have a reproduction case for this local and published resolution being different? When we clean up the manifest for publish, we overwrite the |
|
@ehuss looks like you added all of this in #8129. Happen to remember if its intentional that If its not intentional for local and registry packages to build differently, thoughts on if changing this is breaking or not? To me, it doesn't seem breaking as it only affects newly published packages, it would make newly published packages avoid known failure cases, and I can't imagine anyone is relying on this behavior (consistently installing the same package and would be negatively impacted by the change in dependencies chosen). |
No, I don't think that behavior was intentional. I think it would be good to fix it. There is some risk that it might impact someone, but I think the risk is low enough that it shouldn't be too much of an issue. |
I haven't looked too closely, but I think #10910 is perhaps a bit too aggressive. I might suggest a warning that triggers if: it is a virtual workspace AND it does not specify the It's really unfortunate to force people to put boilerplate in the
I do not think that is too unusual. |
Great, that should fix all the actual build failures I can see coming from this.
That's the scenario currently, but if we get a future edition 2030 which implies resolver 3 we'll have the same issue again, people upgrade their crates to edition 2030 and don't realise their workspace is still set to resolver 2. Though that may be mitigated by #10587 if people move to specifying |
While normally I don't like punting on problems as people are likely to forget about them, in this case I think the landscape could change significantly enough between now and then that a solution that negatively affects the now isn't worth it. For example, we've talked about adding lint control to cargo, giving users control over lints which opens the door to us being noisier in the future. |
Override to resolver=1 in published package As discussed in #10112 this avoids inconsistent dependency resolution in development and packaged builds when an edition 2021 crate is published from a workspace using the default resolver=1.
...just do this to get rid of a new nightly compiler warning. This change shouldn't impact Holo in any meaningful way. References: * rust-lang/cargo#10112 * https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2 Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
warning: some crates are on edition 2021 which defaults to `resolver = "2"`, but virtual workspaces default to `resolver = "1"` note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest As a library, this isn't important as end-user application decides the resolver finally. Just remove the warning. ref: - rust-lang/cargo#10112 - https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions
warning: some crates are on edition 2021 which defaults to `resolver = "2"`, but virtual workspaces default to `resolver = "1"` note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest As a library, this isn't important as end-user application decides the resolver finally. Just remove the warning. ref: - rust-lang/cargo#10112 - https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions
We cannot set the rust edition inside the virtual workspace, so we need to set the resolver field. For the 2021 edition, resolver version 2 is recommended. See: https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions rust-lang/cargo#10112 Signed-off-by: Ariel Miculas <amiculas@cisco.com>
This gets rid of a warning that comes with rust 1.72.0. This does not impact any of our existing crates since they're all on edition 2021. See rust-lang/cargo#10112
This gets rid of a warning that comes with rust 1.72.0. This does not impact any of our workspaces since we've always been defaulted to using resolver version 1. We can't use resolver v2 yet since that breaks the 'cargo make build-package' task. See rust-lang/cargo#10112 for more details.
This gets rid of a warning that comes with rust 1.72.0. This does not impact any of our existing crates since they're all on edition 2021. See rust-lang/cargo#10112
This gets rid of a warning that comes with rust 1.72.0. This does not impact any of our workspaces since we've always been defaulted to using resolver version 1. We can't use resolver v2 yet since that breaks the 'cargo make build-package' task. See rust-lang/cargo#10112 for more details.
``` warning: some crates are on edition 2021 which defaults to `resolver = "2"`, but virtual workspaces default to `resolver = "1"` note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest ``` Context: rust-lang/cargo#10112
``` warning: some crates are on edition 2021 which defaults to `resolver = "2"`, but virtual workspaces default to `resolver = "1"` note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest ``` Context: rust-lang/cargo#10112
Resolver need to be set on workspace level. See rust-lang/cargo#10112
Resolver need to be set on workspace level. See rust-lang/cargo#10112
...just do this to get rid of a new nightly compiler warning. This change shouldn't impact Holo in any meaningful way. References: * rust-lang/cargo#10112 * https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2 Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Problem
Because the resolver is a global setting in workspaces, and workspaces don't have edition settings, I believe that it is very easy to accidentally use the old resolver in workspaces where you intended on using the new resolver. Because I didn't know about the resolver being global, I just assumed I was using the new one since my crate's edition said "2021" and it caused me to spend the last 4 days trying to fix my builds.
Proposed Solution
I think that having a lint in cargo that says "hey you should explicity set your resolver" would be merited. Because otherwise everyone is going to be using the old resolver all the time, perhaps even without realizing.
Notes
See also rust-lang/rust#90148 and #9996
The text was updated successfully, but these errors were encountered: