5

I have the crates A and B. A depends on B and B has a feature named some_feature.

I can build B using cargo by running cargo build --features=some_feature, but how can I set the same features for A that I can choose to enable or disable some_feature for underlying crate B when compiling A?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Allen Lee
  • 411
  • 5
  • 11

2 Answers2

7

You can simply forward the feature specified in A:

# A/Cargo.toml

[features]
some-feature = ["B/some-feature"]

[dependencies]
B = "*"

This will compile B with --features=some_feature if you pass --features=some_feature to A.

Tim Diekmann
  • 7,755
  • 11
  • 41
  • 69
0

You just need to configure the manifest, it's as simple as the doc say:

[dependencies.awesome]
version = "1.3.5"
default-features = false # do not include the default features, and optionally
                         # cherry-pick individual features
features = ["secure-password", "civet"]
Stargateur
  • 24,473
  • 8
  • 65
  • 91