Skip to content

Optional dependencies with links cause failure even when not used #10066

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

Closed
korken89 opened this issue Nov 10, 2021 · 2 comments
Closed

Optional dependencies with links cause failure even when not used #10066

korken89 opened this issue Nov 10, 2021 · 2 comments
Labels
C-bug Category: bug

Comments

@korken89
Copy link

Problem

As a dependency I want 2 versions of a crate, but the crate uses the links attribute as only one is allowed.
If I rename the 2 versions of a crate and use the package and set optional = true the links check still fails, even though none of the optional dependencies are enabled.

I'd expect this to work with only one of the 2 enabled, but fail with a links error if both were enabled.
And it seems from here that this should be allowed: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml
With the line Depend on multiple versions of a crate.

Steps

Use the following Cargo.toml in an empty project and run cargo build to show the issue:

[package]
name = "dual-defmt"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[dependencies.defmt02]
package = "defmt"
version = "0.2"
optional = true

[dependencies.defmt03]
package = "defmt"
version = "0.3"
optional = true

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.56.0 (4ed5d137b 2021-10-04)
release: 1.56.0
commit-hash: 4ed5d137baff5eccf1bae5a7b2ae4b57efad4a7d
commit-date: 2021-10-04
@Eh2406
Copy link
Contributor

Eh2406 commented Nov 10, 2021

The root of your problem is that a lockfile is generated with all features enabled. Features are supposed to be additive.
In this case, if you have a different project in a different workspace that depends on your example it will work.

@ehuss
Copy link
Contributor

ehuss commented Nov 10, 2021

Closing as a duplicate of #5969, which contains a deeper discussion of this situation.

@ehuss ehuss closed this as completed Nov 10, 2021
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

3 participants