-
-
Couldn't load subscription status.
- Fork 258
Add a repository rule for efficient sysroots #572
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| module "crosstool" [system] { | ||
| %textual_headers% | ||
| %cxx_builtin_include_files% | ||
| %sysroot% | ||
| %umbrella_submodules% | ||
| } |
This file contains hidden or 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,70 @@ | ||
| load("@aspect_bazel_lib//lib:repo_utils.bzl", "repo_utils") | ||
|
|
||
| def _sysroot_impl(rctx): | ||
| urls = rctx.attr.urls | ||
| if rctx.attr.url: | ||
| urls = [rctx.attr.url] + urls | ||
|
|
||
| if not urls: | ||
| fail("At least one of url and urls must be provided") | ||
|
|
||
| _, _, archive = urls[0].rpartition("/") | ||
|
|
||
| rctx.download(urls, archive, sha256 = rctx.attr.sha256) | ||
|
|
||
| # Source directories are more efficient than file groups for 2 reasons: | ||
| # - They can be symlinked into a local sandbox with a single symlink instead of 1-per-file | ||
| # - They serve as a signal to the Merkle tree cache machinery since they can be memoized as a single node. | ||
| # Since sysroots are usually a ton of files, it can improve build performance to declare them as source directories. | ||
|
|
||
| # Also, create the BUILD file before extracting because `bsdtar` expects the target | ||
| # directory to exist, and this way Bazel creates it for us without needing `mkdir`. | ||
| rctx.file( | ||
| "sysroot/BUILD.bazel", | ||
| """filegroup( | ||
| name = "sysroot", | ||
| srcs = ["."], | ||
fmeum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| visibility = ["//visibility:public"], | ||
| )""", | ||
| ) | ||
|
|
||
| host_bsdtar = Label("@bsd_tar_toolchains_%s//:tar" % repo_utils.platform(rctx)) | ||
fmeum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| cmd = [ | ||
| str(rctx.path(host_bsdtar)), | ||
| "--extract", | ||
| "--no-same-owner", | ||
| "--no-same-permissions", | ||
| "--file", | ||
| archive, | ||
| "--directory", | ||
| "sysroot", | ||
| ] | ||
|
|
||
| for include in rctx.attr.include_patterns: | ||
| cmd.extend(["--include", include]) | ||
|
|
||
| for exclude in rctx.attr.exclude_patterns: | ||
| cmd.extend(["--exclude", exclude]) | ||
|
|
||
| result = rctx.execute(cmd) | ||
| if result.return_code != 0: | ||
| fail(result.stdout + result.stderr) | ||
|
|
||
| rctx.delete(archive) | ||
dzbarsky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if hasattr(rctx, "repo_metadata"): | ||
| return rctx.repo_metadata(reproducible = True) | ||
| else: | ||
| return None | ||
|
|
||
| sysroot = repository_rule( | ||
| implementation = _sysroot_impl, | ||
| attrs = { | ||
| "url": attr.string(), | ||
| "urls": attr.string_list(), | ||
| "sha256": attr.string(), | ||
| "include_patterns": attr.string_list(), | ||
| "exclude_patterns": attr.string_list(), | ||
| }, | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.