You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ find
.
./Cargo.toml
./src
./src/lib.rs
$ cat Cargo.toml
[package]
name = "foo"
version = "0.1.0"
edition = "2021"# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
reqwest = { version = "0.11", features = [], default-features = false }
cached = { version = "0.34", features = ["tokio"], default-features = false }
$ cat src/lib.rs
$ cargo tree --target wasm32-unknown-unknown -e features -i socket2
Updating crates.io index
In this case, cargo correctly determines that nothing is now requesting tokio/net, and thus socket2 is not a needed dependency.
However, if you move this package exactly into a workspace...
$ find ..
./foo
./foo/Cargo.toml
./foo/src
./foo/src/lib.rs
./Cargo.toml
$ cat Cargo.toml
[workspace]
members = ["foo"]
$ cargo tree --target wasm32-unknown-unknown -e features -i socket2
Updating crates.io index
socket2 v0.4.4
├── socket2 feature "all"
│ └── tokio v1.19.2
│ ├── tokio feature "default"
│ │ └── cached v0.34.0
│ │ └── cached feature "tokio"
│ │ └── foo v0.1.0 (/tmp/foo/foo)
│ │ └── foo feature "default" (command-line)
│ ├── tokio feature "macros"
│ │ └── cached v0.34.0 (*)
│ ├── tokio feature "num_cpus"
│ │ └── tokio feature "rt-multi-thread"
│ │ └── cached v0.34.0 (*)
│ ├── tokio feature "once_cell"
│ │ └── tokio feature "rt"
│ │ └── tokio feature "rt-multi-thread" (*)
│ ├── tokio feature "rt" (*)
│ ├── tokio feature "rt-multi-thread" (*)
│ ├── tokio feature "sync"
│ │ └── cached v0.34.0 (*)
│ ├── tokio feature "time"
│ │ └── cached v0.34.0 (*)
│ └── tokio feature "tokio-macros"
│ └── tokio feature "macros" (*)
└── socket2 feature "default"
└── tokio v1.19.2 (*)
For some reason, cargo is now convinced socket2 is a dependency.
There are different feature resolver behaviors selected with the resolver setting. With a single package, the 2021 edition implicitly selects version "2". With a virtual workspace, there is no edition to select, so it defaults to the original version "1". You have to set the resolver field in the workspace. More can be found here.
Ah! Thank you, that solves my immediate problem, and I'm willing to close this issue as such, but I wonder if it's worthwhile having a lint in cargo for this case then — where the workspace is using a different resolver than at least one of the crates within it would.
...which is already logged as #10112, with some other mitigations being tracked in #10625 and #10587. Now that I know what the problem is it's much easier to search for :) I'll go ahead and close this, then!
Problem
Consider the following simple
Cargo.toml
:In this case,
cargo
correctly determines that nothing is now requestingtokio/net
, and thussocket2
is not a needed dependency.However, if you move this package exactly into a workspace...
For some reason,
cargo
is now convincedsocket2
is a dependency.Steps
No response
Possible Solution(s)
No response
Notes
No response
Version
The text was updated successfully, but these errors were encountered: