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

Platform specific dependency enables features for dependencies in a different target #11338

Closed
fee1-dead opened this issue Nov 5, 2022 · 1 comment
Labels
C-bug Category: bug

Comments

@fee1-dead
Copy link
Member

fee1-dead commented Nov 5, 2022

Problem

When a crate specifies a platform specific dependency, like so:

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1.0", default-features = false, features = ["net", "time"] }

This would enable the features net and time for tokio, if another crate depends on tokio in the same workspace, compilation with --target wasm32-unknown-unknown would fail, as the features net and time are erroneously enabled for the target.

Steps

Create a workspace with two crates, mylib1 and mylib2.

$ cat mylib1/Cargo.toml
[package]
name = "mylib1"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = { version = "1.0", default-features = false, features = [ "sync" ] }
# mylib2 = { path = "../mylib2" } <- doesn't seem to matter
$ cat mylib2/Cargo.toml
[package]
name = "mylib2"
version = "0.1.0"
edition = "2021"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1.0", default-features = false, features = ["net", "time"] }

Then run cargo check --target wasm32-unknown-unknown, it would fail to compile mio, which is enabled by tokio/net.

Possible Solution(s)

do not enable features for dependencies that are platform dependent

Notes

Related: #9863

This occurs when using reqwest and tokio in a workspace.

Version

cargo 1.66.0-nightly (3ff044334 2022-10-17)
release: 1.66.0-nightly
commit-hash: 3ff044334f0567ce1481c78603aeee7211b91623
commit-date: 2022-10-17
host: x86_64-unknown-linux-gnu
libgit2: 1.5.0 (sys:0.15.0 vendored)
libcurl: 7.83.1-DEV (sys:0.4.55+curl-7.83.1 vendored ssl:OpenSSL/1.1.1q)
os: NixOS 22.11.0 [64-bit]
@fee1-dead fee1-dead added the C-bug Category: bug label Nov 5, 2022
@fee1-dead
Copy link
Member Author

seems to be fixed by the v2 resolver.

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

1 participant