rules_rust icon indicating copy to clipboard operation
rules_rust copied to clipboard

Specifying extra rustc flags based on `--compilation_mode`

Open martingms opened this issue 1 year ago • 1 comments

Hi!

Currently, the rustc flags -Copt-level (and -Cdebug-info) is set based on the --compilation_mode. However, I want to also set some additional flags that should change based on --compilation_mode, such as -Clto=true and -Ccodegen-units=1 on opt (with some other default values on dbg or fastbuild), for example.

Is there some way of achieving this with rules_rust at the moment without wrapper macros with select(..), or is that the preferred approach? I'm using rules_rust through bzlmod if that matters, but I could switch back to WORKSPACE if that makes it easier.

martingms avatar Sep 04 '24 16:09 martingms

Wrapper macros with select is the preferred approach, as shown in the example.

https://github.com/bazelbuild/rules_rust/tree/main/examples/bzlmod/compile_opt

It is not perfect, but allows per binary opt settings. I am unaware of a better solution atm.

marvin-hansen avatar Sep 12 '24 06:09 marvin-hansen