Add bazel plugins
Adds a bazel BuildElement and a bazel Source, which should really be used together. The design decisions should be reasonably well documented in the plugins themselves, but as an overview the workflow is this:
- Create a
kind: bazel
element. - Add a source to a bazel project
- If the bazel project does not have a repository resolved file, then add one as a local/patch source.
- Add a bazel source.
- The bazel source will download all of the external bazel dependencies specified in the repository resolved file
- The downloaded sources are passed to the
bazel build
command using the--distdir
option. - Bazel successfully builds your target inside a sandbox.
The repository resolved file is generated using bazel cquery --experimental_repository_resolved_file=string deps(//foo:bar)
This is compatible with every documented version of bazel.
The source plugin may be configured to fall back on host bazel to generate a repository resolved file, however this loses the ability to have the ref verified, as the repository resolved file is not generated deterministically. Best practice would be not to use this.
The bazel build element requires /dev/shm to be in the sandbox, so depends on this MR 0 for BuildStream. We also make sure that /home exists, and call it $HOME. This is because bazel makes a heavy usage of $HOME/.cache, and we want this separate from both build and install root to make sure we don't contaminate the finished binaries.
Finally, at the moment this doesn't support remote execution or caching for bazel, which largely removes the benefits. Downloading the remote cache could potentially be done during the source fetch, and pushing in a separate stage of commands after the build is completed, in the sandbox but with network access.
Adding tests may prove a little awkward for this one, as obviously the element requires bazel, which requires openjdk. Building this in CI would be ill-advised, as pipelines would take... a long time. I have a project using these plugins that works and can be tested at https://gitlab.com/codethinklabs/bazel-resources/bst-build-bazel however, building this also takes an awfully long time as you first need to build the freedesktop-sdk bootstrap and some other bits (notably cmake, which takes a surprisingly long time to build), and then openjdk.
#17 would probably help in this endeavour, as then we could just use cached builds to cut down on build time.
Merge request reports
Activity
mentioned in issue #17
- Resolved by Javier Jardón
- Resolved by Javier Jardón
added 3 commits
-
49b904bc...f01c3233 - 2 commits from branch
master
- 465f8b0b - Add bazel plugins
-
49b904bc...f01c3233 - 2 commits from branch
added 5 commits
-
465f8b0b...65a146fb - 4 commits from branch
master
- 2830dcd3 - Add bazel plugins
-
465f8b0b...65a146fb - 4 commits from branch
added 7 commits
-
2830dcd3...a9f081ad - 6 commits from branch
master
- e13f7f96 - Add bazel plugins
-
2830dcd3...a9f081ad - 6 commits from branch
Seems @coldtom tackle the comments already; let's merge this and open new issues if needed
mentioned in commit 99c5f360