4
votes

This is the Cargo.toml for a library crate. It supports two different embedded boards by having optional dependencies on board support crates board-a and board-b, and only one of these is selected by running cargo build --features target-a.

There is also a common third-party module, which optionally uses the const-fn feature. This option is exposed in the library crate:

[dependencies]
common = {...}
board-a = {optional=true, ...}
board-b = {optional=true, ...}

[features]
const-fn = ["common/const-fn"]
target-a = ["board-a"]
target-b = ["board-b"]

So far so good, but what if the board-a and board-b crates also have optional const-fn features, and I want to expose those options to users of the library crate? Can I do this without creating target-a-const-fn and target-b-const-fn features? That would obviously get very messy the more optional features I expose, or the more boards that we support.

I don't want to make the const-fn feature pull in both board crates -- only the selected one should be used, otherwise it would needlessly increase the download and compile times. Ideally I want something equivalent to the following, but as far as I can see nothing remotely like it exists:

[features]
const-fn = ["common/const-fn", "board-a/const-fn" if target-a, "board-b/const-fn" if target-b]
target-a = ...
1
increase the download [,,,] times — I thought that all the dependencies, optional or not, would be downloaded anyway...Shepmaster

1 Answers

0
votes

No, this is not supported currently by Cargo, although there is a tracking issue for this feature.