Skip to content
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

cargo sometimes, in a workspace, incorrectly enables dependency features #10745

Closed
SohumB opened this issue Jun 10, 2022 · 3 comments
Closed
Labels
C-bug Category: bug

Comments

@SohumB
Copy link

SohumB commented Jun 10, 2022

Problem

Consider the following simple Cargo.toml:

$ 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.

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.63.0-nightly (38472bc19 2022-05-31)
release: 1.63.0-nightly
commit-hash: 38472bc19f2f76e245eba54a6e97ee6821b3c1db
commit-date: 2022-05-31
host: x86_64-unknown-linux-gnu
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.83.1-DEV (sys:0.4.55+curl-7.83.1 vendored ssl:OpenSSL/1.1.1n)
os: Debian unstable (sid) [64-bit]
@SohumB SohumB added the C-bug Category: bug label Jun 10, 2022
@ehuss
Copy link
Contributor

ehuss commented Jun 10, 2022

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.

@SohumB
Copy link
Author

SohumB commented Jun 10, 2022

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.

@SohumB
Copy link
Author

SohumB commented Jun 10, 2022

...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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants