-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
80512: bazel: provide method for constructing distdir for offline builds r=rail a=rickystewart This commit enables bootstrapping a `distdir` containing all the dependencies. In doing so you can easily perform offline builds. In particular, you can now do the following: ``` bazel build `@distdir//:archives` mkdir -p ~/distdir tar -xzf _bazel/bin/external/distdir/archives.tar --strip-components=1 -C ~/distdir ``` Doing so will decompress all the dependencies needed for the build into `~/distdir`. At this point you can build with the command-line flag `--distdir=~/distdir` which will direct Bazel to consult the `~/distdir` directory instead of hitting the network where possible. To enable this we do all of the following: 1. Update `WORKSPACE` to contain SHA256 sums for the Go SDK and node/yarn. This doesn't change the functionality of the actual build (the same data is baked-in in the `rules_go` and `rules_nodejs` libraries) but makes it easier to enumerate all the archives we depend on. 2. Vendor the `rules_pkg` library that we'll use for building the `distdir`. 3. Add a new `generate-distdir` binary that enumerates all of the URL's that we depend on for the build. We have to check in three places: `WORKSPACE`, `DEPS.bzl`, and the `c-deps` directory. Integrate this with `dev generate bazel`. For the most part we search for `http_archive`s and add each URL/SHA256 that we find to the list, but the `c-deps`, Go SDK, and Node/Yarn require special handling. 4. Add a new `distdir` repository rule to capture all of the dependencies. The ``@distdir//:archives`` target consumes the list of URL's and SHA's produced by `generate-distdir` and builds a single `.tar` file. Closes #73316. Release note: None Co-authored-by: Ricky Stewart <[email protected]>
- Loading branch information
Showing
20 changed files
with
1,840 additions
and
187 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
load("@bazel_skylib//lib:paths.bzl", "paths") | ||
|
||
# Ref: https://github.com/bazelbuild/bazel/blob/master/distdir.bzl | ||
|
||
def _distdir_impl(rctx): | ||
for url in rctx.attr.files: | ||
rctx.download( | ||
url = url, | ||
output = paths.basename(url), | ||
sha256 = rctx.attr.files[url], | ||
) | ||
rctx.file("WORKSPACE", "") | ||
rctx.file("BUILD", """ | ||
load("@rules_pkg//:pkg.bzl", "pkg_tar") | ||
pkg_tar( | ||
name="archives", | ||
srcs = glob(["**"], exclude=["BUILD", "WORKSPACE"]), | ||
package_dir = "distdir", | ||
visibility = ["//visibility:public"], | ||
) | ||
""") | ||
|
||
distdir = repository_rule( | ||
implementation = _distdir_impl, | ||
attrs = { | ||
"files": attr.string_dict(), | ||
}, | ||
) |
Oops, something went wrong.