Pre-RFC: [cargo] Profile-specific rustflags. Or alternatively, profile-specific enabling of `cfg` targets


#1

It is currently not possible to specify rustflags on a per-profile basis in Cargo.toml.

The rustflags property is, however, support under [build] and [target...] sections in .cargo/config, but those apply to all profiles. Profiles also cannot selectively enable features, so rigging it with a [target.'cfg(feature="feat")'] also doesn’t work.

My use case for this feature is that I want to aggressively optimise release builds for size, which means I want to set rustflags = ['-C', 'link-arg=-s'] to strip symbols from the builds. However, these rustflags are not desirable for debug builds, hence my desire to only apply them for release builds.


#2

This issue has some overlap: https://github.com/rust-lang/cargo/issues/3483

Also this one: https://github.com/rust-lang/cargo/issues/4122