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

Difficult to use the presence of an optional dependency to use an optional dependency in a non-optional dependency #4548

Closed
Xaeroxe opened this issue Sep 28, 2017 · 6 comments
Labels
A-features Area: features — conditional compilation A-optional-dependencies Area: dependencies with optional=true C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@Xaeroxe
Copy link
Contributor

Xaeroxe commented Sep 28, 2017

Phew! That issue title was a mouthful. So for context see this PR: rustgd/collision-rs#38

We want to export a feature called "serde" and only turn on the "serde" feature in cgmath if our "serde" feature is enabled. We were able to accomplish this with a few workarounds, but it was fairly non-obvious how to do what might become a common task.

In addition to this it was also discovered that proc-macro crate dependencies are silently ignored if placed under a dependency section using target.'cfg(...)'.dependencies I imagine this is due to needing the macro system to evaluate the cfg statement, but it's still annoying and behaves unexpectedly.

@Xaeroxe
Copy link
Contributor Author

Xaeroxe commented Sep 28, 2017

$ cargo --version
cargo 0.21.0 (5b4b8b2ae 2017-08-12)

@Xaeroxe
Copy link
Contributor Author

Xaeroxe commented Sep 28, 2017

Something that might help this situation would be having the ability to specify additional feature lists like ["serde_derive", "cgmath/serde"] with an optional dependency, much like you can with features that aren't dependencies.

Alternatively: Permit a feature named serde to exist alongside an optional dependency called serde if and only if that feature also has "serde" in its feature list so that the optional serde crate is used. (That's kind of a complicated ruleset so I'm not sure if I like this idea)

@Xaeroxe
Copy link
Contributor Author

Xaeroxe commented Sep 28, 2017

proc-macro crate dependencies are silently ignored

I wanted to provide a few more details on this. So with this project structure
collision-rs.zip. The following commands give the following output (rust stable as default with rust nighty installed as well)

$ cargo check
error: failed to learn about crate-type `proc-macro` early on

$ cargo +nightly check
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs

$ cargo +nightly check --features="serde"
   Compiling collision v0.11.0 (file:///C:/Users/JKiesel.CISDEV/collision-rs)
error[E0463]: can't find crate for `serde_derive`
  --> src\lib.rs:46:1
   |
46 | extern crate serde_derive;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

error: Could not compile `collision`.

To learn more, run the command again with --verbose.

@carols10cents carols10cents added A-features Area: features — conditional compilation A-optional-dependencies Area: dependencies with optional=true C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` labels Oct 3, 2017
@alexcrichton
Copy link
Member

Thanks for the report! @Xaeroxe would this perhaps be solved by #1286?

@Xaeroxe
Copy link
Contributor Author

Xaeroxe commented Oct 5, 2017

@alexcrichton Yes, that RFC sounds great, but doesn't it break backwards compatibility?

@alexcrichton
Copy link
Member

@Xaeroxe ok! In that case I'm going to close this in favor of that issue.

Strictly interpreted it does indeed break backwards compatibility, but there's a number of possible solutions we could employ to avoid the breaking change.

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 A-optional-dependencies Area: dependencies with optional=true 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