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 feature confusion in workspaces #11459

Closed
dvc94ch opened this issue Dec 6, 2022 · 7 comments
Closed

cargo feature confusion in workspaces #11459

dvc94ch opened this issue Dec 6, 2022 · 7 comments
Labels
C-bug Category: bug

Comments

@dvc94ch
Copy link

dvc94ch commented Dec 6, 2022

Problem

here is a minimal repro case: https://github.com/dvc94ch/cargo-bug

fails to build when in an empty workspace but builds when not in a workspace

Steps

[workspace]
members = ["a"]
[package]
name = "a"
version = "0.1.0"
edition = "2021"

[target.'cfg(not(target_family = "wasm"))'.dependencies]
surf = { version = "2.3.2", default-features = false, features = ["h1-client-rustls"] }

[target.'cfg(target_family = "wasm")'.dependencies]
surf = { version = "2.3.2", default-features = false, features = ["wasm-client"] }

Possible Solution(s)

No response

Notes

No response

Version

cargo version --verbose
cargo 1.65.0 (4bc8f24d3 2022-10-20)
release: 1.65.0
commit-hash: 4bc8f24d3e899462e43621aab981f6383a370365
commit-date: 2022-10-20
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: Arch Linux [64-bit]
@dvc94ch dvc94ch added the C-bug Category: bug label Dec 6, 2022
@epage
Copy link
Contributor

epage commented Dec 6, 2022

Could you fill out more details, for example

  • Steps for seeing what you mean by "empty workspace" and "non empty workspace"
  • Error output

@dvc94ch
Copy link
Author

dvc94ch commented Dec 6, 2022

updated the issue with two Cargo.toml's that cause the issue. the error is that it does not fail to build when the root Cargo.toml is removed, but simply adding the crate to a workspace, even if it's the only crate in the workspace, makes cargo unable to build the crate.

@dvc94ch
Copy link
Author

dvc94ch commented Dec 6, 2022

Seems like adding the crate to the workspace causes both the h1-client-rustls and wasm-client features to be enabled, but only one should be enabled for any given build as they're mutually exclusive.

@epage
Copy link
Contributor

epage commented Dec 6, 2022

So reproduction steps are

  1. Clone the repo
  2. cargo build --manifest-path a/Cargo.toml, see it fail
  3. rm Cargo.toml
  4. cargo build --manifest-path a/Cargo.toml, see it succeed?

Is that correct?

And can you copy/paste the error output message?

@dvc94ch
Copy link
Author

dvc94ch commented Dec 6, 2022

Yes, your steps reproduce the issue.

The error is a generic build error:

cargo check --manifest-path a/Cargo.toml
    Checking surf v2.3.2
error[E0432]: unresolved import `http_client::wasm`
  --> /home/dvc/.cargo/registry/src/github.com-1ecc6299db9ec823/surf-2.3.2/src/client.rs:15:26
   |
15 |         use http_client::wasm::WasmClient as DefaultClient;
   |                          ^^^^ could not find `wasm` in `http_client`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `surf` due to previous error

@epage
Copy link
Contributor

epage commented Dec 6, 2022

Likely, the difference between workspace or not is in which resolver is being used.

When you set edition = "2021", you are opting in to resolver v2.

The resolver is determined at the workspace level but defaults to the package's edition when it is present in the root crate. For a virtual workspace (no package in it), we are stuck defaulting to workspace.resolver = "1" to avoid breaking compatibility. Adding workspace.resolver = "2" to the workspace should make it behave like the non-workspace case.

Work has started on trying to steer people towards this in documentation (#10625) and providing warnings (#10910)

@dvc94ch
Copy link
Author

dvc94ch commented Dec 6, 2022

ah this does fix the problem. the mentioned PR's would have indeed prevented the issue. thanks

@dvc94ch dvc94ch closed this as completed Dec 6, 2022
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