How to disable crate's feature when release?

Hi, Im using bevy to create my game, and using dynamic_linking features for fast compilation in development.

but, when I want to build my game in release mode. I want to disable this dynamic_linking feature.

How can I achieve that via cargo.toml configuration?

You can't do that.

Here's something you can do instead. Define a feature in your Cargo.toml for dynamic linking:

[features]
dynamic_linking = ["bevy/dynamic_linking"]

Then you build with these commands:

cargo build --features dynamic_linking
cargo build --release

Alternatively, you can also list the feature as default:

[features]
default = ["dynamic_linking"]
dynamic_linking = ["bevy/dynamic_linking"]

Then the commands become:

cargo build
cargo build --release --no-default-features
1 Like

Thank you so much!

So, do I still need to add dynamic_linking feature to bevy? like this:

[dependencies]
bevy = { version = "0.14.0", features = ["dynamic_linking"] }

[features]
dynamic_linking = ["bevy/dynamic_linking"]

Or, just simply like this:

[dependencies]
bevy = "0.14.0"

[features]
dynamic_linking = ["bevy/dynamic_linking"]

This is correct:

[dependencies]
bevy = "0.14.0"

[features]
dynamic_linking = ["bevy/dynamic_linking"]
1 Like

Note that you don't have to call your feature dynamic_linking. This would also work:

[dependencies]
bevy = "0.14.0"

[features]
fast_build = ["bevy/dynamic_linking"]
cargo build --features fast_build
cargo build --release
2 Likes

For anyone's information:

You could add cargo config file to set some aliases, like this:
create .cargo/config.toml in your working directory.
add following content in that file:

[alias]
b = "build --features fast_build"
r = "run --features fast_build"
br = "build --release"
rr = "run --release"

then you can run cargo b for cargo build --features fast_build, and etc.

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.