-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Support consuming autoconf/make external dependencies via a Bazel rule #2792
Comments
+1; this is a nontrivial blocker to C++ projects that use existing non-Bazel libraries (i.e.: most of them). (I had hoped that the "contributed Bazel BUILD files" repository would help solve this, but it appears to be mostly stagnant.) |
I think what we're doing in envoyproxy/envoy#716 is actually not the best way to approach it. By defining a |
Can you investigate if repository_rule solves your needs and then ping this thread? |
@mhlopko It does, see envoyproxy/envoy#747. However, it's got a horrible UX because of #1289. I've filed an issue to improve documentation of best practices for consuming C++ autoconf/make dependencies at #2814. I'll close this issue out, since the machinery is there today. |
Re-opening. As discussed in envoyproxy/envoy#747 (comment), Bazel could do more to support finer grained builds of autoconf/make dependencies under a |
I think envoyproxy/envoy#747 (comment) provides some useful data on what the performance issues are. There's a foundational issue when it comes to dealing with multiple autoconf/make deps and how the There's also an issue that hasn't been previously raised. If the the autoconf/make dependency (e.g. Lightstep in our case) wants to consume from something that can be cleanly imported as a It seems we need to either make |
* Build a recursive make cache in a parallel directory to where Bazel thinks the repository rule outputs are. E.g. if Bazel think the deps are in ~/.cache/bazel/89676793239ac96d94294e6c7a44597f/external/envoy_deps, the cache lives in ~/.cache/bazel/89676793239ac96d94294e6c7a44597f/external/envoy_deps_cache. This allow us to avoid Bazel falsely clobbering all the make build directories everytime it _thinks_ there is a dependency change (e.g. a single recipe is modified). We then defer to make to figure out when it's time to rebuild these deps. If something gets really messed up, bazel clean --expunge still works with this cache. Underlying issue tracked in bazelbuild/bazel#2792. * Always output stuff after the build of external deps, to signal what's happened. Otherwise, it appears mysterious to the user where all the time went as Bazel doesn't report progress. Underlying issue tracked in bazelbuild/bazel#1289. * Add a `bazel fetch` step to the documentation so that the mystery hang when Bazel first builds the external deps is understandable. Underlying issue tracked in bazelbuild/bazel#1289.
* Build a recursive make cache in a parallel directory to where Bazel thinks the repository rule outputs are. E.g. if Bazel think the deps are in ~/.cache/bazel/89676793239ac96d94294e6c7a44597f/external/envoy_deps, the cache lives in ~/.cache/bazel/89676793239ac96d94294e6c7a44597f/external/envoy_deps_cache. This allow us to avoid Bazel falsely clobbering all the make build directories everytime it _thinks_ there is a dependency change (e.g. a single recipe is modified). We then defer to make to figure out when it's time to rebuild these deps. If something gets really messed up, bazel clean --expunge still works with this cache. Underlying issue tracked in bazelbuild/bazel#2792. * Always output stuff after the build of external deps, to signal what's happened. Otherwise, it appears mysterious to the user where all the time went as Bazel doesn't report progress. Underlying issue tracked in bazelbuild/bazel#1289. * Add a `bazel fetch` step to the documentation so that the mystery hang when Bazel first builds the external deps is understandable. Underlying issue tracked in bazelbuild/bazel#1289.
Having recently converted a mid-sized project from cmake to Bazel (https://github.com/lyft/envoy, envoyproxy/envoy#415), one of the very significant challenges was dealing with more than a dozen external dependencies (https://lyft.github.io/envoy/docs/install/requirements.html), almost all of which had no native Bazel support and were mostly autoconf/make based.
We had a requirement to consume these external dependencies in multiple ways. Some organizations (notably Lyft, the project owner) required the dependencies as prebuilts, essentially
.a
and.h
files in a standard--prefix
layout. This was also required by our CI system for performance reasons. Other developers wanted a way to have Bazel perform the build of the dependencies. To compose with other projects, allowing Envoy to be consumed as agit_repository
, we wanted to avoid having the consuming project figure out its own dependencies, so we needed a self-contained Bazel build of the dependencies as well for this reason.We settled on building the dependencies under a common recursive make both when creating the prebuilts and also ran the recursive make under a Bazel
genrule
for the Bazel build. Unfortunately, AFAICT,genrule
s need to know ahead of time all the headers and libraries in itsouts
, we can't just glob them. Explicitly declaring the libraries is fine, each dependency only had 1 or 2. The headers would be a nightmare though by hand, there are O(1k) of these.We settled on performing an offline build outside of Bazel, then analyzing the build outputs to generate a
.bzl
with the smarts to provide agenrule
for the dependencies. This.bzl
then gets checked into the repository. See envoyproxy/envoy#716. This seems like a huge amount of engineering effort to allow for easy consumption of external deps that are non-Bazel based (Please let us know if there is a better way!).I think Bazel should have an option in its
git_repository
for taking an external repository, performing a native build under autoconf/make (or whatever native build system it has) and discovering its generated files (perhaps with globs), that runs prior to building the dependency graph.CC: @mattklein123 @lizan @tschroed
The text was updated successfully, but these errors were encountered: