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

The same crate with different features #10489

Closed
uuhan opened this issue Mar 20, 2022 · 3 comments
Closed

The same crate with different features #10489

uuhan opened this issue Mar 20, 2022 · 3 comments
Labels
A-dependency-resolution Area: dependency resolution and the resolver A-features Area: features — conditional compilation C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@uuhan
Copy link

uuhan commented Mar 20, 2022

Problem

[package]
name = "test-features"
version = "0.1.0"
edition = "2021"

[dependencies]
casbin = "2.0.9"
rhai = "1.5.0"

casbin has rhai as it's dependency with features:

rhai = { version = "1.5.0", features = [
  "sync",
  "only_i32",
  "no_function",
  "no_float",
  "no_optimize",
  "no_module",
  "serde",
  "unchecked",
] }

So I can not use rhai without the feature no_module

Proposed Solution

[dependencies.rhai]
version = "1.5.0"
isolated = true # maybe have this flag to use the dependency as an isolated one, so it's features does not include `no_module`

[dependencies.casbin]
version = "2.0.9" # this crate have the dependency `rhai==1.5.0` with feature `no_module` enabled.

Notes

No response

@uuhan uuhan added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Mar 20, 2022
@weihanglo
Copy link
Member

I believe it's the behaviour of feature unification, unfortunately. Cargo will use the union of features of a dependency if it appears multiple times in the dependency graph. A rule of thumb is that define features as additive as possible. However, rhai also had a hard time transiting features to additive and here is the discussion.

The proposed solution seems straight-forward but the devil is in the details. Does isolated mean they are two separate dependency graph? Should cargo stop unifying their transitive dependencies as well? Personally I cannot foresee any reasonable design at the moment 🥲

As a workaround, maybe you can try to fork rhai and make it a different package or split the dependent into different crates, so that cargo probably won't merge them.

@weihanglo weihanglo added A-features Area: features — conditional compilation A-dependency-resolution Area: dependency resolution and the resolver labels Mar 21, 2022
@uuhan
Copy link
Author

uuhan commented Mar 22, 2022

I believe it's the behaviour of feature unification, unfortunately. Cargo will use the union of features of a dependency if it appears multiple times in the dependency graph. A rule of thumb is that define features as additive as possible. However, rhai also had a hard time transiting features to additive and here is the discussion.

The proposed solution seems straight-forward but the devil is in the details. Does isolated mean they are two separate dependency graph? Should cargo stop unifying their transitive dependencies as well? Personally I cannot foresee any reasonable design at the moment 🥲

As a workaround, maybe you can try to fork rhai and make it a different package or split the dependent into different crates, so that cargo probably won't merge them.

Currently, I just fork the rhai package and rename it to other name. It works, but, emmm, very unconfortable for the further update.

I wonder if the package feature could be extended to satisify this need, like this:

[dependency.my-rhai]
package = "rhai"
version = "1.5.0"
features = ["sync"]

If all the package info of rhai is bound to the new package name my-rhai, and can not be affected by casbin's dependency. But it seems currently the usage of package = "rhai" just alias the crate name, not keeps the features isolated.

@ehuss
Copy link
Contributor

ehuss commented Apr 8, 2022

I'm going to close as this is expected behavior with how features are unified. Features should be additive, and it looks like there was some discussion in the linked issue about possibly fixing rhai's use of features. I think it is unlikely that cargo will gain the ability to build multiple copies with different features, or support "negative" features. I recommend working with the casbin or rhai maintainers to find a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dependency-resolution Area: dependency resolution and the resolver A-features Area: features — conditional compilation C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

3 participants