Cargo feature-specific dependencies


I need to have two slightly different versions of the same rust application on the same target platform.

The application consists of several crates.
The two versions have some differences in data types among various crates which should be considered at compile-time.

Inside each crate, I can use #[cfg(feature="versionX")] to manage the compiler.
However, I can not find a clean way to pass this between crates (e.g. from the main crate to dependencies).

I tried this:

dep1 = { path="path-to-dep1", features=["versionX"] }

to pass the versionX feature to dep1, but it is ignored without any warnings or errors.

Am I missing anything here?
Is there any non-hacky way to do have multiple versions as above?


versionX = ["dep1/versionX"]
1 Like


Added the above lines to the parent crate’s Cargo.toml and the problem is solved.