conan.tools.google
Warning
These tools are experimental and subject to breaking changes.
BazelDeps
Available since: 1.37.0
The BazelDeps
helper will generate one conandeps/xxxx/BUILD file per dependency. This dependencies will be
automatically added to the project if you add the following lines to the project’s WORKSPACE file:
load("@//conandeps:dependencies.bzl", "load_conan_dependencies")
load_conan_dependencies()
The dependencies should be added to the conanfile.py file as usual:
class BazelExampleConan(ConanFile):
name = "bazel-example"
...
generators = "BazelDeps", "BazelToolchain"
requires = "boost/1.76.0"
BazelToolchain
Available since: 1.37.0
The BazelToolchain
is the toolchain generator for Bazel. It will generate a file called
conanbuild.conf
containing two keys:
bazelrc_path: defining Bazel rc-path. Can be set using the conf
tools.google.bazel:bazelrc_path
.bazel_configs: defining the configs to be activated in the
bazelrc_path
. Can be set with the conftools.google.bazel:configs
.
build:Release -c opt
build:RelWithDebInfo -c opt --copt=-O3 --copt=-DNDEBUG
build:MinSizeRel -c opt --copt=-Os --copt=-DNDEBUG
build --color=yes
build:withTimeStamps --show_timestamps
[settings]
...
build_type=Release
[conf]
tools.google.bazel:bazelrc_path=/path/to/mybazelrc
tools.google.bazel:configs=["Release"]
The Bazel build helper will use that conanbuild.conf
file to seamlessly call
the configure and make script using these precalculated arguments. Note that the file can have a
different name if you set the namespace argument in the constructor as explained below.
It supports the following methods and attributes:
constructor
def __init__(self, conanfile, namespace=None):
conanfile
: the current recipe object. Always useself
.namespace
: this argument avoids collisions when you have multiple toolchain calls in the same recipe. By setting this argument, the conanbuild.conf file used to pass information to the build helper will be named as: <namespace>_conanbuild.conf. The default value isNone
meaning that the name of the generated file is conanbuild.conf. This namespace must be also set with the same value in the constructor of theBazel
build helper so that it reads the information from the proper file.
Bazel
Available since: 1.37.0
The Bazel
build helper is a wrapper around the command line invocation of bazel. It will abstract the
calls like bazel build //main:hello-world
into Python method calls.
The helper is intended to be used in the build()
method, to call Bazel commands automatically
when a package is being built directly by Conan (create, install)
from conan import ConanFile
from conan.tools.google import Bazel
class App(ConanFile):
settings = "os", "arch", "compiler", "build_type"
def build(self):
bazel = Bazel(self)
bazel.configure()
bazel.build(label="//main:hello-world")
It supports the following methods:
constructor
def __init__(self, conanfile, namespace=None):
conanfile
: the current recipe object. Always useself
.namespace
: this argument avoids collisions when you have multiple toolchain calls in the same recipe. By setting this argument, the conanbuild.conf file used to pass information to the toolchain will be named as: <namespace>_conanbuild.conf. The default value isNone
meaning that the name of the generated file is conanbuild.conf. This namespace must be also set with the same value in the constructor ofBazelToolchain
so that it reads the information from the proper file.
build()
def build(self, args=None, label=None):
Calls the build system. Equivalent to bazel build {label} in the build folder.