I tried to create a Conan package of a library built with Bazel. The dependencies of the library, however, are modeled in Bazel. Everything worked fine as long as the parameter "clean" to the Bazel.build function was set to False, however upon using True I faced the following issue when running conan create .:
WARNING: Running Bazel server needs to be killed, because the startup options are different.
WARNING: Waiting for server process to terminate (waited 5 seconds, waiting at most 60)
As it turns out, the issue seems to be that bazel is indeed called with different startup options:
# bazel from apt needs access to this cacerts location
startup --host_jvm_args=-Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts
changes, the bazel startup options, the startup options are indeed different for above bazel commands.
I propose the following to fix the issue:
def build(self, args=None, target="//...", clean=True):
"""
Runs "bazel <rcpaths> build <configs> <args> <targets>" command where:
* ``rcpaths``: adds ``--bazelrc=xxxx`` per rc-file path. It listens to ``BazelToolchain``
(``--bazelrc=conan_bzl.rc``), and ``tools.google.bazel:bazelrc_path`` conf.
* ``configs``: adds ``--config=xxxx`` per bazel-build configuration.
It listens to ``BazelToolchain`` (``--config=conan-config``), and
``tools.google.bazel:configs`` conf.
* ``args``: they are any extra arguments to add to the ``bazel build`` execution.
* ``targets``: all the target labels.
:param target: It is the target label. By default, it's "//..." which runs all the targets.
:param args: list of extra arguments to pass to the CLI.
:param clean: boolean that indicates to run a "bazel clean" before running the "bazel build".
Notice that this is important to ensure a fresh bazel cache every
"""
# Use BazelToolchain generated file if exists
conan_bazelrc = os.path.join(self._conanfile.generators_folder, BazelToolchain.bazelrc_name)
use_conan_config = os.path.exists(conan_bazelrc)
bazelrc_paths = []
bazelrc_configs = []
if use_conan_config:
bazelrc_paths.append(conan_bazelrc)
bazelrc_configs.append(BazelToolchain.bazelrc_config)
# User bazelrc paths have more prio than Conan one
# See more info in https://bazel.build/run/bazelrc
bazelrc_paths.extend(self._conanfile.conf.get("tools.google.bazel:bazelrc_path", default=[],
check_type=list))
# Note: In case of error like this: ... https://bcr.bazel.build/: PKIX path building failed
# Check this comment: https://github.com/bazelbuild/bazel/issues/3915#issuecomment-1120894057
bazel_exe = "bazel"
startup_options = ""
for rc in bazelrc_paths:
rc = rc.replace("\\", "/")
startup_options += f" --bazelrc={rc}"
build_command = bazel_exe + startup_options + " build"
bazelrc_configs.extend(self._conanfile.conf.get("tools.google.bazel:configs", default=[],
check_type=list))
for config in bazelrc_configs:
build_command += f" --config={config}"
if args:
build_command += " ".join(f" {arg}" for arg in args)
build_command += f" {target}"
if clean:
clean_command = bazel_exe + startup_options + " clean"
self._safe_run_command(clean_command)
self._safe_run_command(build_command)
Describe the bug
I tried to create a Conan package of a library built with Bazel. The dependencies of the library, however, are modeled in Bazel. Everything worked fine as long as the parameter "clean" to the Bazel.build function was set to False, however upon using True I faced the following issue when running
conan create .
:As it turns out, the issue seems to be that bazel is indeed called with different startup options:
https://github.com/conan-io/conan/blob/2.8.0/conan/tools/google/bazel.py#L71
results in 2 bazel calls:
As my .bazelrc file
changes, the bazel startup options, the startup options are indeed different for above bazel commands.
I propose the following to fix the issue:
More information:
Ubuntu 20.04 Conan version 2.8.0 Bazel 7.2.1
Conan config:
conanfily.py
How to reproduce it
conan create .