Skip to content

Commit

Permalink
Merge pull request #3489 from conan-io/release/2.0
Browse files Browse the repository at this point in the history
Merge release/2.0 to develop2 branch
  • Loading branch information
czoido authored Dec 18, 2023
2 parents bad6939 + ad2baa6 commit 2fa828b
Show file tree
Hide file tree
Showing 42 changed files with 331 additions and 56 deletions.
2 changes: 1 addition & 1 deletion examples/conanfile/layout/conanfile_in_subfolder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Declaring the layout when the Conanfile is inside a subfolder
-------------------------------------------------------------

Please, first of all, clone the sources to recreate this project. You can find them in the
Please, first clone the sources to recreate this project. You can find them in the
`examples2.0 repository <https://github.com/conan-io/examples2>`_ in GitHub:

.. code-block:: bash
Expand Down
2 changes: 1 addition & 1 deletion examples/conanfile/layout/editable_components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ That is, if we want to put a package in ``editable`` mode, and that package defi
necessary to define the components layout correctly in the ``layout()`` method.
Let's see it in a real example.

Please, first of all, clone the sources to recreate this project. You can find them in the
Please, first clone the sources to recreate this project. You can find them in the
`examples2.0 repository <https://github.com/conan-io/examples2>`_ in GitHub:

.. code-block:: bash
Expand Down
2 changes: 1 addition & 1 deletion examples/conanfile/layout/multiple_subprojects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Declaring the layout when we have multiple subprojects
------------------------------------------------------

Please, first of all, clone the sources to recreate this project. You can find them in the
Please, first clone the sources to recreate this project. You can find them in the
`examples2.0 repository <https://github.com/conan-io/examples2>`_ in GitHub:

.. code-block:: bash
Expand Down
2 changes: 1 addition & 1 deletion examples/conanfile/layout/third_party_libraries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Declaring the layout when creating packages for third-party libraries
---------------------------------------------------------------------

Please, first of all, clone the sources to recreate this project. You can find them in the
Please, first clone the sources to recreate this project. You can find them in the
`examples2.0 repository <https://github.com/conan-io/examples2>`_ in GitHub:

.. code-block:: bash
Expand Down
2 changes: 1 addition & 1 deletion examples/conanfile/package_info/components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ component.
network;
}

Please, first of all, clone the sources to recreate this project. You can find them in the
Please, first clone the sources to recreate this project. You can find them in the
`examples2.0 repository <https://github.com/conan-io/examples2>`_ in GitHub:

.. code-block:: bash
Expand Down
2 changes: 1 addition & 1 deletion examples/config_files/settings/settings_user.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Customize your settings: create your settings_user.yml
======================================================

Please, first of all, clone the sources to recreate this project. You can find them in the
Please, first clone the sources to recreate this project. You can find them in the
`examples2.0 repository <https://github.com/conan-io/examples2>`_ in GitHub:

.. code-block:: bash
Expand Down
2 changes: 1 addition & 1 deletion examples/dev_flow/debug/step_into_dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Building from source

The recommended approach for debugging dependencies is building them from source in the local cache. This approach should work out of the box for most recipes, including ConanCenter recipes.

We can reuse the code from the very first example in the tutorial for this use case. Please, first clone the sources to recreate this project, you can find them in the
We can reuse the code from the very first example in the tutorial for this use case. Please, first clone the sources to recreate this project. You can find them in the
`examples2.0 repository <https://github.com/conan-io/examples2>`_ in GitHub:

.. code-block:: bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Custom command: Clean old recipe and package revisions
without needing this custom command.


Please, first of all, clone the sources to recreate this project. You can find them in the
Please, first clone the sources to recreate this project. You can find them in the
`examples2.0 repository <https://github.com/conan-io/examples2>`_ in GitHub:

.. code-block:: bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Copy sources from all your dependencies



Please, first of all, clone the sources to recreate this project. You can find them in the
Please, first clone the sources to recreate this project. You can find them in the
`examples2.0 repository <https://github.com/conan-io/examples2>`_ in GitHub:

.. code-block:: bash
Expand Down
2 changes: 1 addition & 1 deletion examples/graph/tool_requires/different_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Will generate a "conflict", showing an error like ``Duplicated requirement``.

However there are some exceptional situations that we could need to depend on the same ``tool_requires`` version,
but using different binaries of that ``tool_requires``. This can be achieved by passing different ``options`` to those
``tool_requires``. Please, first, clone the sources to recreate this project, you can find them in the
``tool_requires``. Please, first clone the sources to recreate this project. You can find them in the
`examples2.0 repository <https://github.com/conan-io/examples2>`_ on GitHub:

.. code-block:: shell
Expand Down
2 changes: 1 addition & 1 deletion examples/graph/tool_requires/different_versions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Will generate a "conflict", showing an error like ``Duplicated requirement``. Th
when it is obvious that it is not possible to use 2 versions of the same compiler to build the current package.

However there are some exceptional situations when something like that is desired. Let's recreate the potential
scenario. Please, first, clone the sources to recreate this project, you can find them in the
scenario. Please, first clone the sources to recreate this project. You can find them in the
`examples2.0 repository <https://github.com/conan-io/examples2>`_ on GitHub:

.. code-block:: shell
Expand Down
2 changes: 1 addition & 1 deletion examples/graph/tool_requires/using_protobuf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ should look like:
This is the way to proceed with any other library used in both contexts. Nonetheless, let's see a detailed example to see
how the example looks like.

Please, first, clone the sources to recreate this project, you can find them in the
Please, first clone the sources to recreate this project. You can find them in the
`examples2.0 repository <https://github.com/conan-io/examples2>`_ on GitHub:

.. code-block:: shell
Expand Down
1 change: 1 addition & 0 deletions examples/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ Conan recipe tools examples
tools/cmake/cmake
tools/files/files
tools/meson/meson
tools/google/bazel
tools/autotools/autotools
tools/scm/git/capture_scm/git_capture_scm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ that uses one of the most popular C++ libraries: `fmt <https://fmt.dev/latest/in
We'll use `Autotools <https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html>`_ as build system and `pkg-config <https://www.freedesktop.org/wiki/Software/pkg-config/>`_ as a helper tool in this case, so you should get them installed
on Linux and Mac before going forward with this example.

Please, first, clone the sources to recreate this project, you can find them in the
Please, first clone the sources to recreate this project. You can find them in the
`examples2.0 repository <https://github.com/conan-io/examples2>`_ on GitHub:

.. code-block:: shell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ generated ones.

.. include:: ../../../../tutorial/cmake_presets_note.inc

Please, first of all, clone the sources to recreate this project. You can find them in the
Please, first clone the sources to recreate this project. You can find them in the
`examples2.0 repository <https://github.com/conan-io/examples2>`_ in GitHub:

.. code-block:: bash
Expand Down
10 changes: 10 additions & 0 deletions examples/tools/google/bazel.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _examples_tools_bazel:


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

.. toctree::
:maxdepth: 2

bazeltoolchain/build_simple_bazel_project
135 changes: 135 additions & 0 deletions examples/tools/google/bazeltoolchain/build_simple_bazel_project.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
.. _examples_tools_bazel_toolchain_build_simple_bazel_project:

Build a simple Bazel project using Conan
========================================

In this example, we are going to create a Hello World program
that uses one of the most popular C++ libraries: `fmt <https://fmt.dev/latest/index.html/>`_.

.. note::

This example is based on the main :ref:`Build a simple CMake project using Conan<consuming_packages_build_simple_cmake_project>`
tutorial. So we highly recommend reading it before trying out this one.


We'll use Bazel as the build system and helper tool in this case, so you should get it installed
before going forward with this example. See `how to install Bazel <https://bazel.build/install>`_.

Please, first clone the sources to recreate this project. You can find them in the
`examples2.0 repository <https://github.com/conan-io/examples2>`_ in GitHub:

.. code-block:: bash
$ git clone https://github.com/conan-io/examples2.git
$ cd examples2/examples/tools/google/bazeltoolchain/string_formatter
We start from a very simple C++ language project with this structure:

.. code-block:: text
.
├── WORKSPACE
├── conanfile.txt
└── main
├── BUILD
└── demo.cpp
This project contains a *WORKSPACE* file loading the Conan dependencies (in this case only ``fmt``)
and a *main/BUILD* file which defines the *demo* bazel target and it's in charge of using ``fmt`` to build a
simple Hello World program.

Let's have a look at each file's content:

.. code-block:: cpp
:caption: **main/demo.cpp**
#include <cstdlib>
#include <fmt/core.h>
int main() {
fmt::print("{} - The C++ Package Manager!\n", "Conan");
return EXIT_SUCCESS;
}
.. code-block:: python
:caption: **WORKSPACE**
load("@//conan:dependencies.bzl", "load_conan_dependencies")
load_conan_dependencies()
.. code-block:: python
:caption: **main/BUILD**
load("@rules_cc//cc:defs.bzl", "cc_binary")
cc_binary(
name = "demo",
srcs = ["demo.cpp"],
deps = [
"@fmt//:fmt"
],
)
.. code-block:: ini
:caption: **conanfile.txt**
[requires]
fmt/10.1.1
[generators]
BazelDeps
BazelToolchain
[layout]
bazel_layout
Conan uses the :ref:`conan_tools_google_bazeltoolchain` to generate a ``conan_bzl.rc`` file which defines the
``conan-config`` bazel-build configuration. This file and the configuration are passed as parameters to the
``bazel build`` command. Apart from that, Conan uses the :ref:`conan_tools_google_bazeldeps` generator
to create all the bazel files (*[DEP]/BUILD.bazel* and *dependencies.bzl*) which define all the dependencies
as public bazel targets. The *WORKSPACE* above is already ready to load the *dependencies.bzl* which will tell the
*main/BUILD* all the information about the ``@fmt//:fmt`` bazel target.

As the first step, we should install all the dependencies listed in the ``conanfile.txt``.
The command :ref:`conan install<reference_commands_install>` does not only install the ``fmt`` package,
it also builds it from sources in case your profile does not match with a pre-built binary in your remotes.
Furthermore, it will save all the files created by the generators listed in the ``conanfile.txt``
in a folder named *conan/* (default folder defined by the ``bazel_layout``).

.. code-block:: bash
$ conan install . --build=missing
# ...
======== Finalizing install (deploy, generators) ========
conanfile.txt: Writing generators to /Users/franchuti/develop/examples2/examples/tools/google/bazeltoolchain/string_formatter/conan
conanfile.txt: Generator 'BazelDeps' calling 'generate()'
conanfile.txt: Generator 'BazelToolchain' calling 'generate()'
conanfile.txt: Generating aggregated env files
conanfile.txt: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
Install finished successfully
Now we are ready to build and run our application:

.. code-block:: bash
$ bazel --bazelrc=./conan/conan_bzl.rc build --config=conan-config //main:demo
Starting local Bazel server and connecting to it...
INFO: Analyzed target //main:demo (38 packages loaded, 272 targets configured).
INFO: Found 1 target...
INFO: From Linking main/demo:
ld: warning: ignoring duplicate libraries: '-lc++'
Target //main:demo up-to-date:
bazel-bin/main/demo
INFO: Elapsed time: 60.180s, Critical Path: 7.68s
INFO: 6 processes: 4 internal, 2 darwin-sandbox.
INFO: Build completed successfully, 6 total actions
.. code-block:: bash
$ ./bazel-bin/main/demo
Conan - The C++ Package Manager!
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ that uses one of the most popular C++ libraries: `Zlib <https://zlib.net/>`__.
We'll use Meson as build system and pkg-config as helper tool in this case, so you should get them installed
before going forward with this example.

Please, at first, clone the sources to recreate this project, you can find them in the
Please, first clone the sources to recreate this project. You can find them in the
`examples2.0 repository <https://github.com/conan-io/examples2>`_ in GitHub:

.. code-block:: bash
Expand Down
Binary file added images/integrations/conan-bazel-logo.png
Loading
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.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Xcode.
integrations/clion
integrations/visual_studio
integrations/autotools
integrations/bazel
integrations/makefile
integrations/xcode
integrations/meson
Expand Down
26 changes: 26 additions & 0 deletions integrations/bazel.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.. _integrations_bazel:

|bazel_logo| Bazel
==================

Conan provides different tools to help manage your projects using Bazel. They can be
imported from ``conan.tools.google``. The most relevant tools are:

- ``BazelDeps``: the dependencies generator for Bazel, which generates a *[DEPENDENCY]/BUILD.bazel* file for each dependency
and a *dependencies.bzl* file containing a Bazel function to load all those ones. That function must be loaded by your
*WORKSPACE* file.

- ``BazelToolchain``: the toolchain generator for Bazel, which generates a ``conan_bzl.rc`` file that contains
a build configuration ``conan-config`` to inject all the parameters into the :command:`bazel build` command.

- ``Bazel``: the Bazel build helper. It's simply a wrapper around the command line invocation of Bazel.

.. seealso::

- Reference for :ref:`conan_tools_google_bazeldeps`.
- Reference for :ref:`conan_tools_google_bazeltoolchain`.
- Reference for :ref:`conan_tools_google_bazel`.
- :ref:`examples_tools_bazel_toolchain_build_simple_bazel_project`


.. |bazel_logo| image:: ../images/integrations/conan-bazel-logo.png
31 changes: 31 additions & 0 deletions reference/conanfile/attributes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,34 @@ Currently these are the automatic implementations provided by Conan:
.. warning::

This is a 2.0-only feature, and it will not work in 1.X


alias
-----

.. warning::

While aliases can technically still be used in Conan 2.0, their usage is not recommended
and they may be fully removed in future releases. Users are encouraged to adapt to the
:ref:`newer versioning features<devops_versioning>` for a more standardized and efficient
package management experience.

In Conan 2.0, the `alias` attribute remains a part of the recipe, allowing users to define
an alias for a package version. Normally, you would create one using the ``conan new``
command with the ``alias`` template and the exporting the recipe with conan export:

.. code-block:: shell
$ conan new alias -d name=mypkg -d version=latest -d target=1.0
$ conan export .
Note that when requiring the alias, you must place the version in parentheses ``()`` to
explicitly declare the use of an alias as a requirement:

.. code-block:: python
class Consumer(ConanFile):
...
requires = "mypkg/(latest)"
...
4 changes: 2 additions & 2 deletions reference/conanfile/attributes/binary_model.inc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ For example, in the ``configure()`` method a typical pattern for a C library wou
.. seealso::

- :ref:`reference_config_files_settings_yml`.
- Removing settings in the ``package_id()`` method. <MISSING PAGE>
- :ref:`Removing settings in the package_id() method<reference_conanfile_methods_package_id_clear>`.


.. _conan_conanfile_properties_options:
Expand Down Expand Up @@ -233,7 +233,7 @@ Take into account that if a value is assigned in the ``configure()`` method it c
.. seealso::
Read more about the <MISSING PAGE>method_configure_config_options method.
Read more about the :ref:`config_options() method<reference_conanfile_methods_config_options>`.
default_build_options
---------------------
Expand Down
2 changes: 1 addition & 1 deletion reference/conanfile/attributes/build.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ List or tuple of strings with names of generators.
generators = "CMakeDeps", "CMakeToolchain"


The generators can also be instantiated explicitly in the <MISSING PAGE> generate() method.
The generators can also be instantiated explicitly in the :ref:`generate() method<reference_conanfile_methods_generate>`.


.. code-block:: python
Expand Down
Loading

0 comments on commit 2fa828b

Please sign in to comment.