Stream: general

Topic: Advanced cargo features

Paul Faria (Jan 04 2020 at 05:08, on Zulip):

In Cargo.toml, is it possible to say that a dependency has a feature only if a feature of my own crate is enabled? Root issue: I have a case where I have a proc-macro crate, and I only want it to emit certain code if a feature in my main crate is turned on/off.

Paul Faria (Jan 04 2020 at 05:08, on Zulip):

My code is in a workspace, and the main crate depends on the proc-macro crate, then re-exports it.

Paul Faria (Jan 04 2020 at 05:09, on Zulip):

Or, would my only option be to not have the main crate depend on the proc-macro crate, and enforce that my users set the features on both crates

Lokathor (Jan 04 2020 at 06:53, on Zulip):

yes, make a feature in your crate, and then make it have a required "dependency/feature" instead of just a required "feature".

my_crate_feature = ["dep_name/dep_feature"]
Paul Faria (Jan 04 2020 at 19:13, on Zulip):

That worked. Thank you!

Last update: Jan 21 2020 at 08:45UTC