Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 521
Arthur Avatar asked Oct 03 '21 19:10

Arthur


People also ask

How many release profiles does rust Optimisation level have?

The rustc compiler has 4 optimization level, just like gcc.

Where is cargo TOML located?

toml which defaults to: Windows: %USERPROFILE%\. cargo\config. toml.


Video Answer


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

like image 86
James Beilby Avatar answered Oct 19 '22 03:10

James Beilby