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

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.

1 Like

This issue has some overlap:

Also this one:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.