0

I've got a crate that can be compiled with or without a feature, let's say feat_crate.

I use that crate from a program that can also be compiled with or without a feature feat_app.

I'd like to enable feat_crate for the dependency whenever feat_app is enabled; feat_app being enabled when building the app (like in cargo run -- --feat_app ⚠ EDIT, like in cargo run --features feat_app).

I cannot find a simple way to do so without modifying the Cargo.toml file each time I want to change the enabled feature. I tried looking at build scripts but the script for the app is executed after the dependencies are compiled, so it doesn't seem to help.

I probably can use an environment variable fetched from the crate build script, meaning I would have to set that environment variable accordingly... but I was hoping for a better solution.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
  • _"feat_app being enabled when building the app (like in `cargo run -- --feat_app`)."_ Is it part of the requirement to compile the program differently based on that `--feat_app` option? This one is never really passed into the compiler. – E_net4 Nov 16 '20 at 11:03
  • 1
    They probably mean `--features feat_app`? The text description doesn't really make sense otherwise. – Masklinn Nov 16 '20 at 11:07
  • You are right, I edited the question. – Cyril Fougeray Nov 16 '20 at 13:31

1 Answers1

2

From the features documentation:

Features can be used to reexport features of other packages. The session feature of package awesome (nb: that's the "current" package) will ensure that the session feature of the package cookie is also enabled.

session = ["cookie/session"]
Masklinn
  • 34,759
  • 3
  • 38
  • 57