Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create and use custom build flags in Bazel?

Tags:

bazel

I've a rule with a conditional attribute:

some_rule(
  name = "my_rule",
  some_attr = select({
    ":ts_diagnostics_mode_extended": ["--extendedDiagnostics"]
  }),
)

and with the config setting:

config_setting(
   name = "ts_diagnostics_mode_extended",
   values = { "define": "ts_diagnostics_mode=extended_diagnostics" }
)

However, when building with bazel build :my_target --define ts_diagnostics_mode=extended_diagnostics I get
Configurable attribute "some_attr" doesn't match this configuration (would a default condition help?).

What's missing?

like image 861
Christian Avatar asked Oct 29 '25 22:10

Christian


2 Answers

--define flags are handled specially by config_setting, via define_values, because they are multi-valued. I think this will work:

config_setting(
    name = "ts_diagnostics_mode_extended",
    define_values = { "ts_diagnostics_mode": "extended_diagnostics" }
)
like image 157
kevingessner Avatar answered Nov 01 '25 12:11

kevingessner


While define_values indeed works, your original example with values should also work. define_values is only necessary when you want the config_setting to have multiple entries.

See this line in the define_values documentation:

--define can still appear in values with normal flag syntax, and can be mixed freely with this attribute as long as dictionary keys remain distinct.

like image 43
Greg E Avatar answered Nov 01 '25 12:11

Greg E



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!