C++ syntax check only for quick validation of the build changes

64 views
Skip to first unread message

Konstantin

unread,
Nov 24, 2022, 1:09:42 PM11/24/22
to bazel-discuss

We have a huge C++ build and every time we make a change in one of the Bazel macros affecting attributes of many C++ targets it takes hours to validate the change. Example: change the order of includes for all compilations. I am looking for an easy to implement (even if hacky) way to reduce validation time by making it fail fast.

I toyed with the idea to use compiler option to only perform syntax checking and skip producing binary. When I tried that Bazel naturally stopped after the first compilation complaining that expected object file was not produced. Even “—keep_going” flag does not let it go any further. And obviously all the linking steps are predictably going to fail.  

Any wild ideas how to make that partial but failing fast validation?

Konstantin

Jonathan Mayer

unread,
Nov 28, 2022, 1:53:50 PM11/28/22
to bazel-discuss
I'm no expert but:

My guess is that compiling a CC file is only a little bit slower than parsing it, and that you're spending the bulk of your time linking and optimizing.  You can confirm this by generating a flame chart profiling where bazel is spending its time (see https://bazel.build/rules/performance#performance-profiling ).

If my hunch is right, you can just run the compilation steps without the linking steps, like this:

bazel query "kind('cc_library rule', //...)" | xargs bazel build --copt -O0

For full code coverage, you might need to rewrite your build rules so that every .cc file has a cc_library target, and cc_binary rules contain nothing but cc_library dependencies.  Does that help?

carpen...@gmail.com

unread,
Nov 29, 2022, 4:47:49 AM11/29/22
to bazel-discuss
Why not try only asking bazel for the object files? Not all the files? 
`bazel build //... --output_groups=compilation_outputs`
Will only go as far as compiling .obj files over the entire codebase. We use this for clang-format validations which only go that fat. 


Konstantin

unread,
Nov 29, 2022, 3:29:34 PM11/29/22
to bazel-discuss
Thank you guys! I was able to use both of your tips! We use our own C++ toolchain and ruleset (because built-in ones do not have the features we need), but I was able to implement fastbuild flavor with the settings Jonathan recommended AND also implement compilation_outputs output group in our ruleset to limit the build to compilations only per Carpenter's great advice! Together it made a very noticable difference. Thanks again!

Konstantin

Reply all
Reply to author
Forward
0 new messages