Conditional feature activation on other dep based on my feature

Suppose I use a dependency, which has a feature called nightly which is supposed to be used just when the nightly compiler is activated.

my_dep={path="...", default-features=false, features=["some_feature1"]}

I also want to create a nightly feature on my branch, to be activated only when compiling with nightly. How can I make it such that it does

my_dep={path="...", default-features=false, features=["some_feature1", "nightly"]}

only when nightly is activated on my Cargo, but

my_dep={path="...", default-features=false, features=["some_feature1"]}

when it's not?

If I understand your question correctly, this should help

Features - The Cargo Book

Features of dependencies can also be enabled in the [features] table. The syntax is "package-name/feature-name" . For example:

jpeg-decoder = { version = "0.1.20", default-features = false }

# Enables parallel processing support by enabling the "rayon" feature of jpeg-decoder.
parallel = ["jpeg-decoder/rayon"]

Note : The "package-name/feature-name" syntax will also enable package-name if it is an optional dependency. Experimental support for disabling that behavior is available on the nightly channel via weak dependency features.

I.e. in your case, use

my_dep={path="...", default-features=false, features=["some_feature1"]}

but also add "my_dep/nightly" to the entry in [features], e.g.

nightly = ["my_dep/nightly"]
#         ^^^--- this list might have more entries, e.g.
# if your nightly feature also implies other dependencies

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.