-
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
Automatically activate a dependency if its used elsewhere in dependency graph #1555
Comments
Are you familiar with inline table syntax for TOML? I think this is much more ergonomic than a new section: [dependencies]
quickcheck = { optional = true } |
I didn't know about that syntax, but it sounds good to me. I care much more about the "magic, just-works" behavior than the syntax. :) |
Ok, in that case I'm going to close this as the inline table syntax should be much more ergonomic than a whole new section. |
Wait, this feature exists already? How do I express "I want to depend on this package iff whoever depends on me is already depending on that package." ? |
Ah I believe I have misread. |
While this doesn't happen automatically, I believe this can currently be expressed with: crate foo: [dependencies]
quickcheck = { version = "*", optional = true } crate bar:
Then for the downstream, if they're using quickcheck, they can opt into [features]
with-quickcheck = ["quickcheck", "bar/with-quickcheck"]
[dependencies]
bar = "*"
quickcheck = { version = "*", optional = true } |
I think this would be very useful. When writing a library that defines a new type, it often makes sense to impl traits from other popular libraries for interoperability. But I don't want to pull in all those extra dependencies if the user isn't using them. |
This would be awesome. 💯 [dependencies]
diesel = { version = "0.10.0", features = ["postgres", "uuid"] }
diesel_codegen = { version = "0.10.0", features = ["postgres", "dotenv"] }
uuid = { version = "0.4.0", features = ["serde"] }
serde = "0.9"
dotenv = "*" Wouldn't it be simply beautiful if the above could instead be: [dependencies]
diesel = { version = "0.10.0", features = ["postgres"] }
diesel_codegen = { version = "0.10.0", features = ["postgres"] }
uuid = "0.4.0"
serde = "0.9"
dotenv = "*" Automatic use of features (the optional crate kind) that I have as explicit dependencies would be a very ergonomic addition. |
I believe this feature has an associated RFC now: rust-lang/rfcs#1787 |
I've created a Pre-RFC for mutually-exclusive, global features which might be pertinent to the discussion. |
Cargo should be able to express the idea of: "I want to depend on this package iff whoever depends on me is already depending on that package." This is especially useful because rust doesn't have orphan instances.
Specifically, I want to add a quickcheck
Arbitrary
instance toIobuf
. However, I don't want to add the dependency on Quickcheck for people not using it (non-test executables, for most people). It would be nice if it "just worked", perhaps in a new section:And then anyone that depends on iobuf can have the quickcheck instances built for tests by including quickcheck in their dev-dependencies.
The text was updated successfully, but these errors were encountered: