Enable features only on debug/release

is it possible to enable certain Cargo.toml features only in debug or release mode?

Well, you could do something like this I guess:

#[cfg(and(debug_assertions, feature = "my-release-feature"))]
const FEATURE_CHECK_1: () = {
    compile_error!(r#"The "my-release-feature" feature is only supported in release mode."#);

#[cfg(and(not(debug_assertions), feature = "my-debug-feature"))]
const FEATURE_CHECK_2: () = {
    compile_error!(r#"The "my-debug-feature" feature is only supported in debug mode."#);

But that sounds like an unusual requirement. There’s plenty of advantages to keeping features and optimizations orthogonal, especially when it comes to isolating the effect of some feature while debugging.

1 Like

didn’t work for me as-is… got errors…

I agree that keeping features and optimizations separate is a good idea and that I really want to just be checking for features here…

might be running into something specific with wasm-pack, filed here: https://github.com/wasm-tool/wasm-pack-plugin/issues/61