Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new documentation for the Bazel helper #2109

Merged
merged 2 commits into from May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -23,6 +23,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
venv

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
Binary file added images/conan-bazel_logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions integrations/build_system.rst
Expand Up @@ -31,3 +31,4 @@ Conan can be integrated with any build system. This can be done with:
build_system/meson
build_system/scons
build_system/gcc
build_system/bazel
40 changes: 40 additions & 0 deletions integrations/build_system/bazel.rst
@@ -0,0 +1,40 @@
.. _bazel:


|bazel_logo| Bazel
__________________

If you are using **Bazel** as your library build system, you can use the **Bazel** build helper.
This helper has a .build()`` method available to ease the call to Meson build system.

If you want to declare Conan dependencies in your project, you must do it, as usual, in the
**conanfile.py** file. For example:

.. code-block:: python

class BazelExampleConan(ConanFile):
name = "bazel-example"
....
build_requires = "boost/1.76.0"

Then, tell Bazel to use that dependencies by adding this to the **WORKSPACE** file:

.. code-block:: text

load("@//conandeps:dependencies.bzl", "load_conan_dependencies")
load_conan_dependencies()

After that, just update the BUILD files where you need to use the new dependency:

.. code-block:: text

cc_binary(
name = "hello-world",
srcs = ["hello-world.cc"],
deps = [
"@boost//:boost",
],
)


.. |bazel_logo| image:: ../../images/conan-bazel_logo.png
1 change: 1 addition & 0 deletions reference/conanfile/tools.rst
Expand Up @@ -37,6 +37,7 @@ Contents:

tools/cmake
tools/gnu
tools/google
tools/meson
tools/microsoft
tools/qbs
Expand Down
78 changes: 78 additions & 0 deletions reference/conanfile/tools/google.rst
@@ -0,0 +1,78 @@
.. _conan_tools_google:

conan.tools.google
==================

.. warning::

These tools are **experimental** and subject to breaking changes.


BazelDeps
---------

Available since: `1.37.0 <https://github.com/conan-io/conan/releases>`_

The ``BazelDeps`` helper will generate one **conandeps/xxxx/BUILD** file per dependency. This dependencies will be
automatically added to the project by adding the following to the project's **WORKSPACE** file:


.. code-block:: text

load("@//conandeps:dependencies.bzl", "load_conan_dependencies")
load_conan_dependencies()


The dependencies should be added to the **conanfile.py** file as usual:

.. code-block:: python

class BazelExampleConan(ConanFile):
name = "bazel-example"
...
generators = "BazelDeps", "BazelToolchain"
build_requires = "boost/1.76.0"

Bazel
-----
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)


.. code-block:: python

from conans 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
+++++++++++

.. code:: python

def __init__(self, conanfile):

- ``conanfile``: the current recipe object. Always use ``self``.


build()
+++++++

.. code:: python

def build(self, args=None, label=None):


Calls the build system. Equivalent to :command:`bazel build {label}` in the build folder.