Skip to content

Commit 535e845

Browse files
committedMay 31, 2021
Add new documentation for the Bazel helper
1 parent ad42ed2 commit 535e845

File tree

6 files changed

+121
-0
lines changed

6 files changed

+121
-0
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var/
2323
*.egg-info/
2424
.installed.cfg
2525
*.egg
26+
venv
2627

2728
# PyInstaller
2829
# Usually these files are written by a python script from a template

‎images/conan-bazel_logo.png

5.73 KB
Loading

‎integrations/build_system.rst

+1
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ Conan can be integrated with any build system. This can be done with:
3131
build_system/meson
3232
build_system/scons
3333
build_system/gcc
34+
build_system/bazel

‎integrations/build_system/bazel.rst

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.. _bazel:
2+
3+
4+
|bazel_logo| Bazel
5+
__________________
6+
7+
If you are using **Bazel** as your library build system, you can use the **Bazel** build helper.
8+
This helper has a .build()`` method available to ease the call to Meson build system.
9+
10+
If you want to declare Conan dependencies in your project, you must do it, as usual, in the
11+
**conanfile.py** file. For example:
12+
13+
.. code-block:: python
14+
15+
class BazelExampleConan(ConanFile):
16+
name = "bazel-example"
17+
....
18+
build_requires = "boost/1.76.0"
19+
20+
Then, tell Bazel to use that dependencies by adding this to the **WORKSPACE** file:
21+
22+
.. code-block:: text
23+
24+
load("@//conandeps:dependencies.bzl", "load_conan_dependencies")
25+
load_conan_dependencies()
26+
27+
After that, just update the BUILD files where you need to use the new dependency:
28+
29+
.. code-block:: text
30+
31+
cc_binary(
32+
name = "hello-world",
33+
srcs = ["hello-world.cc"],
34+
deps = [
35+
"@boost//:boost",
36+
],
37+
)
38+
39+
40+
.. |bazel_logo| image:: ../../images/conan-bazel_logo.png

‎reference/conanfile/tools.rst

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Contents:
3737

3838
tools/cmake
3939
tools/gnu
40+
tools/google
4041
tools/meson
4142
tools/microsoft
4243
tools/qbs

‎reference/conanfile/tools/google.rst

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
.. _conan_tools_google:
2+
3+
conan.tools.google
4+
==================
5+
6+
.. warning::
7+
8+
These tools are **experimental** and subject to breaking changes.
9+
10+
11+
BazelDeps
12+
---------
13+
14+
Available since: `1.37.0 <https://github.com/conan-io/conan/releases/tag/1.37.0>`_
15+
16+
The ``BazelDeps`` helper will generate one **conandeps/xxxx/BUILD** file per dependency. This dependencies will be
17+
automatically added to the project by adding the following to the project's **WORKSPACE** file:
18+
19+
20+
.. code-block:: text
21+
22+
load("@//conandeps:dependencies.bzl", "load_conan_dependencies")
23+
load_conan_dependencies()
24+
25+
26+
The dependencies should be added to the **conanfile.py** file as usual:
27+
28+
.. code-block:: python
29+
30+
class BazelExampleConan(ConanFile):
31+
name = "bazel-example"
32+
...
33+
generators = "BazelDeps", "BazelToolchain"
34+
build_requires = "boost/1.76.0"
35+
36+
Bazel
37+
-----
38+
The ``Bazel`` build helper is a wrapper around the command line invocation of bazel. It will abstract the
39+
calls like ``bazel build //main:hello-world`` into Python method calls.
40+
41+
The helper is intended to be used in the ``build()`` method, to call Bazel commands automatically
42+
when a package is being built directly by Conan (create, install)
43+
44+
45+
.. code-block:: python
46+
47+
from conans import ConanFile
48+
from conan.tools.google import Bazel
49+
50+
class App(ConanFile):
51+
settings = "os", "arch", "compiler", "build_type"
52+
53+
def build(self):
54+
bazel = Bazel(self)
55+
bazel.configure()
56+
bazel.build(label="//main:hello-world")
57+
58+
It supports the following methods:
59+
60+
constructor
61+
+++++++++++
62+
63+
.. code:: python
64+
65+
def __init__(self, conanfile):
66+
67+
- ``conanfile``: the current recipe object. Always use ``self``.
68+
69+
70+
build()
71+
+++++++
72+
73+
.. code:: python
74+
75+
def build(self, args=None, label=None):
76+
77+
78+
Calls the build system. Equivalent to :command:`bazel build {label}` in the build folder.

0 commit comments

Comments
 (0)
Please sign in to comment.