Can I activate a dependency's feature only for debug profile?

Viewed 886

I have just started looking into the Bevy game engine for Rust. It has a feature called dynamic, which enables dynamic linking, to speed up compilation time during development. We are, however, advised to disable this when building for release.

Is there a way to tell Cargo to enable the dynamic feature for a debug build, but disable it for a release build? Or do I have to personally remember to change bevy = { version = "0.5.0", features = ["dynamic"] } to bevy = "0.5.0" in Cargo.toml before running cargo build --release?

1 Answers

Along the lines of Rodrigo's comment, can confirm the following seems to work well:

[dependencies]
bevy = { version = "0.5.0" }

[features]
default = ["fast-compile"]
fast-compile = ["bevy/dynamic"]

Then for development, simply: cargo build

And for release: cargo build --release --no-default-features

Related