replace url_format
with url_formats
This commit is contained in:
parent
fb0cf50c44
commit
2895f0c2bf
15
README.md
15
README.md
@ -26,6 +26,15 @@ http_archive(
|
|||||||
load("@bazel-zig-cc//toolchain:defs.bzl", zig_register_toolchains = "register_toolchains")
|
load("@bazel-zig-cc//toolchain:defs.bzl", zig_register_toolchains = "register_toolchains")
|
||||||
|
|
||||||
zig_register_toolchains()
|
zig_register_toolchains()
|
||||||
|
|
||||||
|
# Or, if you are using this in production, you probably want more control:
|
||||||
|
zig_register_toolchains(
|
||||||
|
version = "<...>",
|
||||||
|
url_formats = [
|
||||||
|
"https://example.internal/zig/zig-{host_platform}-{version}.tar.xz",
|
||||||
|
],
|
||||||
|
host_platform_sha256 = { ... },
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
And this to `.bazelrc`:
|
And this to `.bazelrc`:
|
||||||
@ -99,12 +108,6 @@ how to contribute.
|
|||||||
Currently zig cache is in `$HOME`, so `bazel clean --expunge` does not clear
|
Currently zig cache is in `$HOME`, so `bazel clean --expunge` does not clear
|
||||||
the zig cache. Zig's cache should be stored somewhere in the project's path.
|
the zig cache. Zig's cache should be stored somewhere in the project's path.
|
||||||
|
|
||||||
## Alternative download URLs
|
|
||||||
|
|
||||||
Currently zig is downloaded from
|
|
||||||
[dl.jakstys.lt/zig](https://dl.jakstys.lt/zig/), which is nuts. One should
|
|
||||||
provide a way to specify alternative URLs for the zig toolchain.
|
|
||||||
|
|
||||||
## Toolchain and platform target locations
|
## Toolchain and platform target locations
|
||||||
|
|
||||||
The path to Bazel toolchains is `@zig_sdk//:<toolchain>_toolchain`. It should
|
The path to Bazel toolchains is `@zig_sdk//:<toolchain>_toolchain`. It should
|
||||||
|
@ -140,21 +140,21 @@ def _target_linux_musl(gocpu, zigcpu):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Official recommended version. Should use this when we have a usable release.
|
# Official recommended version. Should use this when we have a usable release.
|
||||||
_URL_FORMAT_RELEASE = "https://ziglang.org/download/{version}/zig-{host_platform}-{version}.tar.xz"
|
URL_FORMAT_RELEASE = "https://ziglang.org/download/{version}/zig-{host_platform}-{version}.tar.xz"
|
||||||
|
|
||||||
# Caution: nightly releases are purged from ziglang.org after ~90 days. A real
|
# Caution: nightly releases are purged from ziglang.org after ~90 days. A real
|
||||||
# solution would be to allow the downstream project specify their own mirrors.
|
# solution would be to allow the downstream project specify their own mirrors.
|
||||||
# This is explained in
|
# This is explained in
|
||||||
# https://sr.ht/~motiejus/bazel-zig-cc/#alternative-download-urls and is
|
# https://sr.ht/~motiejus/bazel-zig-cc/#alternative-download-urls and is
|
||||||
# awaiting my attention or your contribution.
|
# awaiting my attention or your contribution.
|
||||||
_URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{host_platform}-{version}.tar.xz"
|
URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{host_platform}-{version}.tar.xz"
|
||||||
|
|
||||||
# Author's mirror that doesn't purge the nightlies so aggressively. I will be
|
# Author's mirror that doesn't purge the nightlies so aggressively. I will be
|
||||||
# cleaning those up manually only after the artifacts are not in use for many
|
# cleaning those up manually only after the artifacts are not in use for many
|
||||||
# months in bazel-zig-cc. dl.jakstys.lt is a small x86_64 server with an NVMe
|
# months in bazel-zig-cc. dl.jakstys.lt is a small x86_64 server with an NVMe
|
||||||
# drive sitting in my home closet on a 1GB/s symmetric residential connection,
|
# drive sitting in my home closet on a 1GB/s symmetric residential connection,
|
||||||
# which, as of writing, has been quite reliable.
|
# which, as of writing, has been quite reliable.
|
||||||
_URL_FORMAT_JAKSTYS = "https://dl.jakstys.lt/zig/zig-{host_platform}-{version}.tar.xz"
|
URL_FORMAT_JAKSTYS = "https://dl.jakstys.lt/zig/zig-{host_platform}-{version}.tar.xz"
|
||||||
|
|
||||||
_VERSION = "0.10.0-dev.513+029844210"
|
_VERSION = "0.10.0-dev.513+029844210"
|
||||||
|
|
||||||
@ -168,8 +168,7 @@ _HOST_PLATFORM_SHA256 = {
|
|||||||
def register_toolchains(
|
def register_toolchains(
|
||||||
register = [],
|
register = [],
|
||||||
version = _VERSION,
|
version = _VERSION,
|
||||||
url_format = [_URL_FORMAT_JAKSTYS],
|
url_formats = [URL_FORMAT_JAKSTYS],
|
||||||
url_formats = [],
|
|
||||||
host_platform_sha256 = _HOST_PLATFORM_SHA256):
|
host_platform_sha256 = _HOST_PLATFORM_SHA256):
|
||||||
"""
|
"""
|
||||||
Download zig toolchain and register some.
|
Download zig toolchain and register some.
|
||||||
@ -179,8 +178,7 @@ def register_toolchains(
|
|||||||
zig_repository(
|
zig_repository(
|
||||||
name = "zig_sdk",
|
name = "zig_sdk",
|
||||||
version = version,
|
version = version,
|
||||||
url_format = url_format if type(url_format) == type("") else None,
|
url_formats = url_formats,
|
||||||
url_formats = url_format if type(url_format) == type([""]) else None,
|
|
||||||
host_platform_sha256 = host_platform_sha256,
|
host_platform_sha256 = host_platform_sha256,
|
||||||
host_platform_include_root = {
|
host_platform_include_root = {
|
||||||
"linux-aarch64": "lib/",
|
"linux-aarch64": "lib/",
|
||||||
@ -242,14 +240,8 @@ def _zig_repository_impl(repository_ctx):
|
|||||||
"host_platform": host_platform,
|
"host_platform": host_platform,
|
||||||
}
|
}
|
||||||
|
|
||||||
url_format = repository_ctx.attr.url_format
|
|
||||||
url_formats = repository_ctx.attr.url_formats
|
url_formats = repository_ctx.attr.url_formats
|
||||||
|
|
||||||
if len(url_formats) == 0:
|
|
||||||
url_formats = [url_format]
|
|
||||||
elif url_format != "":
|
|
||||||
fail("Only one of url_format and url_formats should be specified.")
|
|
||||||
|
|
||||||
repository_ctx.download_and_extract(
|
repository_ctx.download_and_extract(
|
||||||
url = [uf.format(**format_vars) for uf in url_formats],
|
url = [uf.format(**format_vars) for uf in url_formats],
|
||||||
stripPrefix = "zig-{host_platform}-{version}/".format(**format_vars),
|
stripPrefix = "zig-{host_platform}-{version}/".format(**format_vars),
|
||||||
@ -288,8 +280,7 @@ zig_repository = repository_rule(
|
|||||||
attrs = {
|
attrs = {
|
||||||
"version": attr.string(),
|
"version": attr.string(),
|
||||||
"host_platform_sha256": attr.string_dict(),
|
"host_platform_sha256": attr.string_dict(),
|
||||||
"url_format": attr.string(doc = "Deprecated in favor of url_formats"),
|
"url_formats": attr.string_list(allow_empty = False),
|
||||||
"url_formats": attr.string_list(),
|
|
||||||
"host_platform_include_root": attr.string_dict(),
|
"host_platform_include_root": attr.string_dict(),
|
||||||
},
|
},
|
||||||
implementation = _zig_repository_impl,
|
implementation = _zig_repository_impl,
|
||||||
|
Loading…
Reference in New Issue
Block a user