15

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?

kmdreko
  • 42,554
  • 6
  • 57
  • 106
Arthur
  • 653
  • 2
  • 6
  • 21
  • 1
    What I did once was to create a feature in the exe itself, that adds the required release features: `[features] release = ["bevy/dynamic"]`, and then instead of `cargo build --release` I have a deployment script, or recently a [`xtask`](https://github.com/matklad/cargo-xtask). – rodrigo Oct 03 '21 at 20:21
  • I found a similar problem [here](https://stackoverflow.com/questions/31403430/how-to-switch-dependencies-based-on-build-profile). I'd just do anything mentioned there and have a `Makefile` to `make release` and `make debug` respectively. – Julius Kreutz Oct 03 '21 at 22:38

1 Answers1

6

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

James Beilby
  • 1,362
  • 10
  • 9
  • That is, at the very least, loads better than manually changing `Cargo.toml`. It's not optimal, as I still have to remember the flag in the first place. But it very much seems like the most ergonomic solution. – Arthur Oct 30 '21 at 07:20