Bazel has different output directories for different compilation modes (fastbuild, opt, dbg) which allows it to keep the release build-cache intact after you compile the app in debug mode. Which is great.
Is it possible to do the same for different compilation options?
My use-case: I have a custom-built C++ symbolic computations system. Each run of the program is one computation. Most computations take a few seconds. But some take minutes. To speed up the latter I unrolled several low-level functions, and now thousands of lines of code are copied to every compilation unit (because the functions are templated). This made a decent effect on computation speed but also slowed down compilation significantly. It really only makes sense to use these optimizations for a small fraction of runs.
So, a put them under a define which I can toggle via --cxxopt=-DUNROLL_ALL_THE_THINGS
. But whenever I switch from unrolled version to a simple one and back Bazel drops compilation cache. In essence, I've split “opt” mode into two (“opt” and “super-opt”) but I can't make Bazel see it this way.
One can use the --platform_suffix
option to manually add a suffix to the output directory name. So, you could pass --platform_suffix=super
whenever you use --cxxopt=-DUNROLL_ALL_THE_THINGS
.