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

Workspace dependency features don't resolve correctly with target-dependent features #11779

Closed
zkat opened this issue Feb 28, 2023 · 2 comments
Closed
Labels
C-bug Category: bug

Comments

@zkat
Copy link

zkat commented Feb 28, 2023

Problem

When using [workspace.dependencies] and foo = { workspace = true }, resolver v2 doesn't seem to correctly load only the features for the current target. Everything works fine if the package version is specified directly in the subcrate.

For example, given this Cargo.toml:

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
foo = { workspace = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
foo = { workspace = true, default-features = false }

Then if the crate is built with cargo build --target wasm32-unknown-unknown, foo will fail to build because it tries to compile wasm-incompatible code.

At the same time, the following works as expected:

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
foo = { version = "1.2.3" }

[target.'cfg(target_arch = "wasm32")'.dependencies]
foo = { version = "1.2.3", default-features = false }

Steps

  1. Create a workspace with a [workspace.dependencies] field. I only tested this on a non-virtual workspace (one with a "root" crate). Add async-tar-wasm = "0.4.2-wasm.1".

  2. Create a subcrate in that workspace with the following:

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
async-tar-wasm = { workspace = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
async-tar-wasm = { workspace = true, default-features = false }
  1. Build with cargo build --target wasm32-unknown-unknown

Possible Solution(s)

No response

Notes

No response

Version

❯ cargo version --verbose
cargo 1.67.1 (8ecd4f20a 2023-01-10)
release: 1.67.1
commit-hash: 8ecd4f20a9efb626975ac18a016d480dc7183d9b
commit-date: 2023-01-10
host: x86_64-pc-windows-msvc
libgit2: 1.5.0 (sys:0.16.0 vendored)
libcurl: 7.86.0-DEV (sys:0.4.59+curl-7.86.0 vendored ssl:Schannel)
os: Windows 10.0.22621 (Windows 10 Enterprise) [64-bit]
@zkat zkat added the C-bug Category: bug label Feb 28, 2023
@weihanglo
Copy link
Member

Thank you for the issue report. This is the expected behavior as features are additive. The workspace dependency didn't opt-out default features, so inherited dependencies cannot get it off.

We made an improvement and will ship in the next version . See the changelog of 1.69 . This comment #11409 (comment) also summarize each combination very well.

@zkat
Copy link
Author

zkat commented Feb 28, 2023

Got it! Looks like this is all addressed, then. It was definitely surprising, though!

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