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

[feature] Generator for Bazel #6235

Closed
1 task done
arlyon opened this issue Dec 14, 2019 · 8 comments · Fixed by #8991
Closed
1 task done

[feature] Generator for Bazel #6235

arlyon opened this issue Dec 14, 2019 · 8 comments · Fixed by #8991

Comments

@arlyon
Copy link

arlyon commented Dec 14, 2019

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)

  • I've read the CONTRIBUTING guide.

@memsharded
Copy link
Member

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!

@technoir42
Copy link

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

@planetmarshall
Copy link
Contributor

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.

@memsharded
Copy link
Member

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.

@lummax
Copy link

lummax commented Jul 28, 2020

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.

@paulherman
Copy link

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.

@lummax
Copy link

lummax commented Jan 1, 2021

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

@memsharded
Copy link
Member

Hi all!

We are providing in #8991 an experimental, built-in integration with Bazel.
It is very early stage, so testing and feedback will be very appreciated.

This issue will be closed when merged, and it will be released in 1.37 next week. Thanks!

@memsharded memsharded added this to the 1.37 milestone May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants