-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Comments
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? |
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
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
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? |
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. |
@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. |
@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). |
This is an 8 year old issue, please open a new one with more up-to-date information. |
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. |
Related: #5954 |
#2980 is the issue to see for mutually exclusive features |
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:
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:Or perhaps we could let the user specify the features when he does an
extern crate
:and the dependency on cargo would not specify any feature as they will be inferred by the
extern crate
:My use-case for this is to allow the user to use the
3df32
feature ofncollide
(for 3d collision detection) together with the2df32
feature (for 2d collision detection) in the same application.The text was updated successfully, but these errors were encountered: