Forcing set of features for shared dependencies across targets in workspace


Is there any way to force same set of features for all the dependencies shared across targets in workspace?

Cargo will use minimal set of features for each target ( & related). This causes problems for us due to all the recompilation that happens across different targets.

For example, we have two chains of dependencies:

  1. A => huge_crate => some_derive => syn
  2. B => huge_crate => some_derive => syn

When compiling “A”, “syn” is compiled with default features. However, when compiling “B”, “syn” is compiled with feature [“extra-traits”] enabled (because of some other dependency only used for “B”, but not for “A”).

This triggers chain of discrepancies and in the end, when both “A” and “B” are compiled independently (for example, “cargo run --package A”, then separately “cargo run --package B”), causes some of our pretty big crates (“huge_crate”) to be compiled twice.

What I would prefer is some way to unify features across the whole workspace, maybe something like a superset of features? Like a workspace setting saying “when depending on ‘syn’, turn on [“extra-traits”] feature”.

Is anything like this possible?

Currently I’m using a pretty crude workaround, a crate used as dev-dependency both for “A” and “B” and which depends on all of the crates where we have discrepancy in features, with a superset of features turned on.



I think, what I’m asking for is the reverse of and I want to unify features across different targets as much as possible (perhaps, manually, by providing some extra configuration in my workspace Cargo.toml), to reduce (re-)compilation times.