Skip to content

Features of [target.'cfg(...)'.dependencies] and [target.'cfg(not(...))'.dependencies] are merged when used in a workspace #12387

@oblique

Description

@oblique

Problem

I have project in a workspace that has something like the following Cargo.toml:

[package]
name = "bug"
version = "0.1.0"
edition = "2021"

[dependencies]

[target.'cfg(target_arch = "wasm32")'.dependencies]
tokio = { version = "1", features = ["sync"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["net"] }

When I was running cargo build --target wasm32-unknown-unknown then Tokio's net feature got enabled too and I was getting compilation errors because of mio crate.

This is an issue only if the project is in a workspace.

Steps

  1. git clone https://github.com/oblique/cargo-features-bug
  2. cargo build --target wasm32-unknown-unknown

Possible Solution(s)

No response

Notes

I created a minimal example: https://github.com/oblique/cargo-features-bug

Version

cargo 1.71.0 (cfd3bbd8f 2023-06-08)
release: 1.71.0
commit-hash: cfd3bbd8fe4fd92074dfad04b7eb9a923646839f
commit-date: 2023-06-08
host: x86_64-unknown-linux-gnu
libgit2: 1.6.4 (sys:0.17.1 vendored)
libcurl: 8.0.1-DEV (sys:0.4.61+curl-8.0.1 vendored ssl:OpenSSL/1.1.1t)
ssl: OpenSSL 1.1.1t  7 Feb 2023
os: Arch Linux Rolling Release [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions