I was initially in agreement, but the more I think about this the less I like it. The obvious objection is that (if I understand it correctly) it affects third party tools. So if I'm using some C libraries to transform or generate source code they're going to be affected by --compilation_mode. A less obvious case is hermetic builds where you build the toolchain itself. In the case of OCaml, the kernel is written in C. I expect one would want that to always be built with full optimization. If we use --compilation_mode=dbg to control OCaml builds, we'll get a debug version of the compiler. So I'm inclined to think compilation mode should be fine-grained, and ruleset writers should provide a means to control it for their language independent of --compilation_mode, which should be reserved for CC builds. One could always provide a means for users to opt in, by specifying they want a debug build if their language-specific debug flag is on OR -compilation_mode is dbg. But that should be opt-in, not opt-out.
Which suggests we could use another built-in flag to control compilation mode for tools. Something like `--tool_compilation_mode` which would only apply to toolchains and anything listed in e.g. the tools attribute of genrule. And --compilation_mode would not apply to those. (Of course, this being Bazel, I won't be suprised if it turns out this is already supported in some manner.)
Cheers,
Gregg