Should --compilation_mode be used for other language rules?

173 views
Skip to first unread message

Rob Figueiredo

unread,
Dec 14, 2021, 9:47:13 AM12/14/21
to bazel-discuss
Hi,

I'm helping to maintain rules_go, and I was hoping to get some advice regarding a recent PR to hook up `-c dbg` to an existing "debug" build config.
https://github.com/bazelbuild/rules_go/pull/3029

My personal usage of Bazel has been for Go, Java, JS, so I have never had a use for this flag. It is documented specifically in terms of C/C++ compilation effects, but I can also imagine that someone in a C++/Go mixed repo would find it convenient and natural to expect -c dbg to do comparable things across them.

Does anyone have advice on whether rules for other languages should toggle comparable config settings based on --compilation_mode?

Thanks,
Rob

Keith Smiley

unread,
Dec 14, 2021, 1:22:32 PM12/14/21
to Rob Figueiredo, bazel-discuss
rules_swift also uses this flag for debug info, but Swift's compilation model is very similar to C/C++ in that regard so it's pretty natural to. I would personally expect it to be respected when the language has a use for it so I agree with your sentiment.
--
Keith Smiley


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/fc452c23-ae19-4308-9923-246190f4e140n%40googlegroups.com.

Alex Eagle

unread,
Dec 14, 2021, 7:15:19 PM12/14/21
to bazel-discuss
rules_nodejs has used --compilation_mode for some purposes, for example

I personally think it would be great for all rulesets to use this same affordance, making Bazel usage more consistent. Would be a good topic for the Rules Authors SIG, if we want to amend the rules style guide to recommend that.

Gregg Reynolds

unread,
Dec 17, 2021, 11:30:55 AM12/17/21
to Alex Eagle, bazel-discuss
On Tue, Dec 14, 2021 at 6:15 PM Alex Eagle <al...@aspect.dev> wrote:
rules_nodejs has used --compilation_mode for some purposes, for example

I personally think it would be great for all rulesets to use this same affordance, making Bazel usage more consistent. Would be a good topic for the Rules Authors SIG, if we want to amend the rules style guide to recommend that.

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

Fabian Meumertzheim

unread,
Dec 17, 2021, 3:16:31 PM12/17/21
to Gregg Reynolds, Alex Eagle, bazel-discuss
Bazel already distinguishes between --compilation_mode and --host_compilation_mode (https://docs.bazel.build/versions/main/command-line-reference.html#flag--host_compilation_mode). The latter is used to build tools that are run during the build. It defaults to opt and can be changed independently, so there is no risk of tools being affected if --compilation_mode is changed globally.

I would thus welcome adding recommendations on the use of --compilation_mode to the rules authors style guide.


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

Gregg Reynolds

unread,
Dec 17, 2021, 3:47:28 PM12/17/21
to Fabian Meumertzheim, Alex Eagle, bazel-discuss
On Fri, Dec 17, 2021 at 2:16 PM Fabian Meumertzheim <fab...@meumertzhe.im> wrote:
Bazel already distinguishes between --compilation_mode and --host_compilation_mode (https://docs.bazel.build/versions/main/command-line-reference.html#flag--host_compilation_mode). The latter is used to build tools that are run during the build. It defaults to opt and can be changed independently, so there is no risk of tools being affected if --compilation_mode is changed globally.

Thanks, I did not know about that.  How would compilation mode work with remote execution?  I have not used remote builds, but my understanding is that the build tools would be built on the execution rather than the host platform, since that is where build actions occur.
 
Gregg

Fabian Meumertzheim

unread,
Dec 17, 2021, 4:11:28 PM12/17/21
to Gregg Reynolds, Alex Eagle, bazel-discuss
As far as I know, the --host_* flags currently all also apply to the exec platform. There is already an ongoing effort to replace all uses of the host configuration within Bazel to the exec configuration. Maybe the flags will even be renamed at some point.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages