1

Move Label dependencies above archive fetching to reduce restarts

This commit is contained in:
Ken Micklas 2022-09-15 19:20:21 +01:00 committed by Motiejus Jakštys
parent f161caf870
commit ba0b0376ea

View File

@ -170,6 +170,35 @@ def _zig_repository_impl(repository_ctx):
"host_platform": host_platform, "host_platform": host_platform,
} }
# Fetch Label dependencies before doing download/extract.
# The Bazel docs are not very clear about this behavior but see:
# https://bazel.build/extending/repo#when_is_the_implementation_function_executed
# and a related rules_go PR:
# https://github.com/bazelbuild/bazel-gazelle/pull/1206
for dest, src in {
"platform/BUILD": "//toolchain/platform:BUILD",
"toolchain/BUILD": "//toolchain/toolchain:BUILD",
"libc/BUILD": "//toolchain/libc:BUILD",
"libc_aware/platform/BUILD": "//toolchain/libc_aware/platform:BUILD",
"libc_aware/toolchain/BUILD": "//toolchain/libc_aware/toolchain:BUILD",
}.items():
repository_ctx.symlink(Label(src), dest)
for dest, src in {
"BUILD": "//toolchain:BUILD.sdk.bazel",
"private/BUILD": "//toolchain/private:BUILD.sdk.bazel",
}.items():
repository_ctx.template(
dest,
Label(src),
executable = False,
substitutions = {
"{absolute_path}": _quote(str(repository_ctx.path(""))),
"{os}": _quote(os),
"{zig_include_root}": _quote(zig_include_root),
},
)
urls = [uf.format(**format_vars) for uf in repository_ctx.attr.url_formats] urls = [uf.format(**format_vars) for uf in repository_ctx.attr.url_formats]
repository_ctx.download_and_extract( repository_ctx.download_and_extract(
auth = use_netrc(read_user_netrc(repository_ctx), urls, {}), auth = use_netrc(read_user_netrc(repository_ctx), urls, {}),
@ -200,30 +229,6 @@ def _zig_repository_impl(repository_ctx):
content = _fcntl_h, content = _fcntl_h,
) )
for dest, src in {
"platform/BUILD": "//toolchain/platform:BUILD",
"toolchain/BUILD": "//toolchain/toolchain:BUILD",
"libc/BUILD": "//toolchain/libc:BUILD",
"libc_aware/platform/BUILD": "//toolchain/libc_aware/platform:BUILD",
"libc_aware/toolchain/BUILD": "//toolchain/libc_aware/toolchain:BUILD",
}.items():
repository_ctx.symlink(Label(src), dest)
for dest, src in {
"BUILD": "//toolchain:BUILD.sdk.bazel",
"private/BUILD": "//toolchain/private:BUILD.sdk.bazel",
}.items():
repository_ctx.template(
dest,
Label(src),
executable = False,
substitutions = {
"{absolute_path}": _quote(str(repository_ctx.path(""))),
"{os}": _quote(os),
"{zig_include_root}": _quote(zig_include_root),
},
)
zig_repository = repository_rule( zig_repository = repository_rule(
attrs = { attrs = {
"version": attr.string(), "version": attr.string(),