I am trying to build an external project that uses Bazel as its build system from CMake with Ninja. I am doing this by using ExternalProject_Add
ExternalProject_Add(bazel_proj
SOURCE_DIR "${bazel_proj_DIR}"
CONFIGURE_COMMAND :
CONFIGURE_HANDLED_BY_BUILD ON
BUILD_COMMAND bazel build //:install
INSTALL_COMMAND bazel run //:install
BUILD_IN_SOURCE ON
BUILD_ALWAYS ON
USES_TERMINAL_BUILD ON
USES_TERMINAL_INSTALL ON
LOG_BUILD ON
LOG_INSTALL ON
LOG_OUTPUT_ON_FAILURE ON
LOG_MERGED_STDOUTERR ON
INACTIVITY_TIMEOUT 10
)
I tried to add --worker_quit_after_build
to the build command but it did not help. Bazel uses the linux-sandbox spawn strategy by default.
The only way to work around this is to stop the build with CTRL C and start over so it goes to the install step the next time!
I also could not make CMake print the progress report of Bazel to the terminal. That might be related.
CodePudding user response:
Bazel has a client/server model, where the server stays around for subsequent incremental builds. So this might be due to the server staying around. Try using the --batch
startup flag, which tells bazel not to use this client/server model:
bazel --batch build //:install
https://bazel.build/docs/user-manual#batch
Note that bazel run //:install
will also start the server. You could add --batch
there as well, but it will probably be a bit slow because Bazel will reanalyze the build. You could possibly instead run the install
program directly, which will be something like bazel-bin/install
(depends on what the //:install
target actually builds).