How to avoid duplicating work across bazel configurations?

Viewed 211

I'm working on a bazel project which uses many tools that are built within bazel as inputs to the execution of actions. Since these tools are built in an 'exec' configuration they depend on libraries which are built in the same 'exec' configuration and in addition I end up building the libraries in the 'target' configuration (as that is what I'm trying to validate builds). In my normal case these two configurations are both my host machine where bazel is running. In this scenario I would like to be able to avoid building all these libraries twice, but I cannot seem to figure out how to do that. When trying to figure out if I could make the configurations match exactly it seems that I couldn't because there is the 'build option': //command_line_option:is exec configuration which is different across the two.

Is this possible by approaching the problem in a different way or do I just have to deal with compiling all my code twice?

1 Answers

There is an option, --nodistinct_host_configuration, that will collapse the target and host configurations. However, it is ineffective against the exec configuration. Additionally, Bazel upstream has indicated that this option is not really supported. (For instance, see https://github.com/bazelbuild/bazel/issues/5572.)

Allowing configuration flexibility while keeping the amount of duplicate work done under control is a thorny problem that is on upstream's roadmap to address better in the future.

Related