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

Using the same dependency twice but with different features. #674

Closed
sebcrozet opened this issue Oct 6, 2014 · 9 comments · Fixed by #712
Closed

Using the same dependency twice but with different features. #674

sebcrozet opened this issue Oct 6, 2014 · 9 comments · Fixed by #712
Labels
A-features Area: features — conditional compilation

Comments

@sebcrozet
Copy link

It would be useful to be able to depend on the same package twice, but using different features, that is, being able to write something like:

[dependencies.some_library]
git = "fixme"
features = [ "feature1" ]

[dependencies.some_library]
git = "fixme"
features = [ "feature2" ]

However, this will cause some naming problems as the two libraries will have the same name. To prevent this, we could add a name entry to the depencency to rename it:

[dependencies.some_library]
git = "fixme"
name = "some_library_1"
features = [ "feature1" ]

[dependencies.some_library]
git = "fixme"
name = "some_library_2"
features = [ "feature2" ]

Or perhaps we could let the user specify the features when he does an extern crate:

extern crate "some_library" with feature1 as some_library_1
extern crate "some_library" with feature2 as some_library_2

and the dependency on cargo would not specify any feature as they will be inferred by the extern crate:

[dependencies.some_library]
git = "fixme"

My use-case for this is to allow the user to use the 3df32 feature of ncollide (for 3d collision detection) together with the 2df32 feature (for 2d collision detection) in the same application.

@alexcrichton alexcrichton added the A-features Area: features — conditional compilation label Oct 13, 2014
@alexcrichton
Copy link
Member

I talked with @wycats today about features and we came up with a possible solution to this, could you read that over and see if it would solve this problem for you?

alexcrichton added a commit to alexcrichton/cargo that referenced this issue Oct 16, 2014
As pointed in rust-lang#633, it's currently not possible for a package to reexport the
feature of another package due to the limitations of how features are defined.

This commit adds support for this ability by allowing features of the form
`foo/bar` in the `features` section of the manifest. This form indicates that
the dependency `foo` should have its `bar` feature enabled. Additionally, it is
not required that `foo` is an optional dependency.

This does not allow features of the form `foo/bar` in a `[dependencies]`
features section as dependencies shouldn't be enabling features for other
dependencies.

Closes rust-lang#633
Closes rust-lang#674
bors added a commit that referenced this issue Oct 17, 2014
As pointed in #633, it's currently not possible for a package to reexport the
feature of another package due to the limitations of how features are defined.

This commit adds support for this ability by allowing features of the form
`foo/bar` in the `features` section of the manifest. This form indicates that
the dependency `foo` should have its `bar` feature enabled. Additionally, it is
not required that `foo` is an optional dependency.

This does not allow features of the form `foo/bar` in a `[dependencies]`
features section as dependencies shouldn't be enabling features for other
dependencies.

At the same time, this passes through features to build commands to solve a few more issues.

Closes #97
Closes #601 (this is an equivalent solution for that problem)
Closes #633
Closes #674
@bors bors closed this as completed in #712 Oct 17, 2014
@jflatow
Copy link

jflatow commented Aug 23, 2021

I don't think this issue was ever solved -- if you want to re-use the same crate with a different set of features this doesn't seem to be possible. The resolver automatically takes the union of features, and if you try to separate these into distinct dependencies using a different name for each you get 'depends on crate multiple times with different names'. Why shouldn't/couldn't these different names be treated as distinct dependencies?

@PonasKovas
Copy link

I don't see any technical reasons not to let users depend on the same crate twice, if that's what they need. A warning when doing that is logical, but an error is too much.

I know that in theory all crate features should be additive and you shouldn't ever need to depend on the same crate twice with different features, but in the real world that's not always the case, and cargo blocking the only solution to it for no reason doesn't seem logical to me.

@PonasKovas
Copy link

PonasKovas commented Jan 31, 2022

@alexcrichton Could this issue be re-opened? It seems that it was closed by accident because of the linked PR, which did not in fact solve this issue.

@addisoncrump
Copy link

@alexcrichton Bumping this; this would be very useful for differential fuzzing in cases where different features are used (e.g. no-std vs. std environment).

@alexcrichton
Copy link
Member

This is an 8 year old issue, please open a new one with more up-to-date information.

@dzmitry-lahoda
Copy link
Contributor

I have similar question. Current solution people use in my case is macro. But having crate imported 2 times with different features would work. Basically sometimes I want TypeScript in Rust. This could solve it for certain use cases.

@gabemeola
Copy link

gabemeola commented May 24, 2023

parking_lot is a good example of exclusive features. Here is an error when importing dependencies which both use different parking_lot features.

[the `send_guard` and `deadlock_detection` features cannot be used together](error: the `send_guard` and `deadlock_detection` features cannot be used together)

Related: #5954

@epage
Copy link
Contributor

epage commented May 24, 2023

#2980 is the issue to see for mutually exclusive features

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-features Area: features — conditional compilation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants