conan icon indicating copy to clipboard operation
conan copied to clipboard

[question] Using BazelDeps with conan center recipes

Open BuildMonkey opened this issue 1 year ago • 4 comments

What is your question?

Hello,

I am looking at Bazel as a potential build system. We also use conan, with some of our packages coming from conan center. I noticed that conan can build the BUILD.bazel files for a conan package using BazelDeps, but it seems one has to adjust the conan recipe to include BazelDeps.

I was wondering if there is another alternative to generating the BUILD.bazel files without customising the recipes. This would allow us to continue to use the conan center recipes without having to keep local copies to include BazelDeps.

Thanks!

Have you read the CONTRIBUTING guide?

  • [X] I've read the CONTRIBUTING guide

BuildMonkey avatar Oct 03 '24 21:10 BuildMonkey

Hi @BuildMonkey

Thanks for your question.

The files that BazelDeps generate are just the files to locate the dependencies, but it is still necessary to write the necessary build files for the current project.

So moving a package from a build system like CMake to Bazel requires both changing CMakeDeps->BazelDeps, but also to rewrite the build scripts for Bazel. So there is no other way than doing modifications to the current recipe and project, not only to change to Conan generator.

memsharded avatar Oct 03 '24 23:10 memsharded

Thanks for responding so quickly.

If I understand your explanation correctly, it is not our intention to adjust the third-party dependencies, such as boost, to convert to bazel. We would like to use boost in our current project with bazel as the build system. It seems from the documentation (https://docs.conan.io/2/reference/tools/google/bazeldeps.html) we have to place BazelDeps in the boost recipe to generate the BUILD.bazel file. We would like to avoid this and continue to leverage the boost recipe in conan center.

Is there a way to keep building boost through the conan center recipe while also having it generate a BUILD.bazel file for boost for us to use in our current project?

BuildMonkey avatar Oct 04 '24 03:10 BuildMonkey

Hi @BuildMonkey

It seems from the documentation (https://docs.conan.io/2/reference/tools/google/bazeldeps.html) we have to place BazelDeps in the boost recipe to generate the BUILD.bazel file. We would like to avoid this and continue to leverage the boost recipe in conan center.

You don't need to rewrite all the third-party dependencies to use BazelDeps or any other XXXDeps generator. Sorry if the documentation is not clear enough, but the documentation explains an example of a consumer using BazelDeps to bring all their dependencies.

For instance, let's imagine that you want to see how looks like the boost BUILD.bazel file created by Conan (and all the other Conan files needed to consume it):

$ conan install --requires=boost/1.86.0 -g BazelDeps -of my-folder --build=missing

This command creates a local folder my-folder where Conan saves all the files and folders created to help the users consume boost. Then, you'll also see the my-folder/boost/BUILD.bazel file.

That would be mostly the same as creating a conanfile.txt and run conan install . --build=missing to install locally all the third-party dependencies. For instance:

conanfile.txt

[requires]
boost/1.86.0

[generators]
BazelDeps
BazelToolchain

[layout]
bazel_layout

If you want to see a complete example of how to use Bazel in your local project:

  • Through the documentation: https://docs.conan.io/2/examples/tools/google/bazel.html (highly recommended).

franramirez688 avatar Oct 04 '24 06:10 franramirez688

The CLI option is great! This lets us continue to use the external recipe without customisations. I'll give this a try. Much appreciated.

BuildMonkey avatar Oct 06 '24 21:10 BuildMonkey

Hi @BuildMonkey

Did it work? Could we close the issue as resolved?

franramirez688 avatar Dec 10 '24 13:12 franramirez688