Conan: [feature] Generator for Bazel

Created on 14 Dec 2019  路  7Comments  路  Source: conan-io/conan

Dependencies with Bazel are a pain sometimes. This has the potential to solve it. google/cargo-raze is a tool that interprets Rust's Cargo.toml and generates build files from which simplifies the import story for Rust packages. There is the possibility of creating something similar for your conanfile.txt in the form of a Bazel generator. This would generate build files for each of the libraries and make them available as dependencies to other actions.

The main question that needs to be answered is how to reason with the various combinations of local cache vs remote and build-from-source vs prebuilt. Some ideas:

  • Cargo raze is the simplest approach in that it always downloads the source code and builds locally
  • We have the potential to, where they exist, download precompiled binaries and depend on them with cc_import (fast)

  • [x] I've read the CONTRIBUTING guide.

medium Build help wanted low queue feature

Most helpful comment

I created a Bazel generator. It's very basic right now so I'm not going to contribute it in the current state.

All 7 comments

Yes, a Bazel generator might be useful and interesting. It is not the first time it has been floating as an idea. Creating generators is not difficult, check for example (https://blog.conan.io/2019/07/24/C++-build-systems-new-integrations-in-Conan-package-manager.html), if you know a bit about the build system. Unfortunately we don't have that expertise in the team, and now our backlog is completely full, so it doesn't seem we could prioritize this.

Regarding the ideas:

  • From source vs binary should be transparent using Conan, because it models uses information for the binaries, but is able to fallback and build from sources when they are not available. But the interface is always the packaged binaries.

  • I ignore about the cc_import I guess this is in Bazel, right? In that case I can imagine a generated file that does a bunch of cc_import to the different binaries provided by Conan.

I will annotate this as a valid feature request at the moment and open for contributions as we won't be able to work on it at least in the short term. Thanks for the suggestion!

I created a Bazel generator. It's very basic right now so I'm not going to contribute it in the current state.

Currently looking at this related to building a tensorflow package. Not sure how rapid progress is likely to be but will submit a PR once I have something workable.

Hi @technoir42 , @planetmarshall

Don't hold that contribution for too long unnecessarily, it doesn't need to be perfect. New generators for build systems are very low-risk, so we can start releasing a very basic functionality (label it as experimental), put it in other users hands and then they can help with testing, feedback, etc.

I've looked into at a little as well. IMHO the first step would be something like the make generator to generate a file with definitions that can be loaded and used from within bazel when manually creating rules. Maybe a helper-macro to define a new_local_repository() would be nice.

On the other hand: I guess integration could be accomplished using the json generator and parsing that on the bazel side.

One potential helper is is to use the CMake generator and have Bazel build using CMake (https://github.com/bazelbuild/rules_foreign_cc). I don't plan to work on this myself, I'm just sharing it as I've had some success using those rules.

On the other hand: I guess integration could be accomplished using the json generator and parsing that on the bazel side.

I've had some time to play with this and created a small POC. This is by no means a fully functioning solution, but may provide some pointers for others. I might continue exploring this in the future. What it does (from inside a bazel build invocation):

  • setup a venv in which to install conan
  • run conan to install the fmt C++ library
  • compile a small hello-world program that uses the fmt loaded via conan

See https://github.com/lummax/experiments_rules_conan/tree/c6a54e1041a36e9b374b5ebe640ab31a37a6a676

Was this page helpful?
0 / 5 - 0 ratings