Conditional rustflags?

I know that there is a [build] section in .cargo/config file that accepts rustflags, but the problem is, it is effective all the time.

I would like to use some rustflags ONLY under RELEASE builds. For example, is there something equivalent to:

[build.dev]
rustflags = [
    "-C",
    "target-cpu=native"
]

Note that I only want those flags under RELEASE builds, and they shall have no effect under DEV builds.

Thx in advance.

"Debug" and "Release" are called profiles, so what you want is profile-specific RUSTFLAGS. A quick Google search for those terms brings up this Cargo issue, so it looks like this is being worked on.

1 Like

Thx! So do we have a workaround for this issue right now? Is there a profile-specific pre-build task available that can change env variables?