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:

[target.'cfg(feature="versionX")'.dependencies]
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?

1 Like
[features]
versionX = ["dep1/versionX"]
2 Likes

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

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.