From 2895f0c2bf42f22c806924ff8eb0125b7fd1d040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Fri, 18 Mar 2022 05:44:22 +0100 Subject: [PATCH] replace `url_format` with `url_formats` --- README.md | 15 +++++++++------ toolchain/defs.bzl | 21 ++++++--------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 1fa24c2..79bd110 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,15 @@ http_archive( load("@bazel-zig-cc//toolchain:defs.bzl", zig_register_toolchains = "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`: @@ -99,12 +108,6 @@ how to contribute. 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. -## 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 The path to Bazel toolchains is `@zig_sdk//:_toolchain`. It should diff --git a/toolchain/defs.bzl b/toolchain/defs.bzl index f883cc2..f185737 100644 --- a/toolchain/defs.bzl +++ b/toolchain/defs.bzl @@ -140,21 +140,21 @@ def _target_linux_musl(gocpu, zigcpu): ) # 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 # solution would be to allow the downstream project specify their own mirrors. # This is explained in # https://sr.ht/~motiejus/bazel-zig-cc/#alternative-download-urls and is # 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 # 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 # drive sitting in my home closet on a 1GB/s symmetric residential connection, # 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" @@ -168,8 +168,7 @@ _HOST_PLATFORM_SHA256 = { def register_toolchains( register = [], version = _VERSION, - url_format = [_URL_FORMAT_JAKSTYS], - url_formats = [], + url_formats = [URL_FORMAT_JAKSTYS], host_platform_sha256 = _HOST_PLATFORM_SHA256): """ Download zig toolchain and register some. @@ -179,8 +178,7 @@ def register_toolchains( zig_repository( name = "zig_sdk", version = version, - url_format = url_format if type(url_format) == type("") else None, - url_formats = url_format if type(url_format) == type([""]) else None, + url_formats = url_formats, host_platform_sha256 = host_platform_sha256, host_platform_include_root = { "linux-aarch64": "lib/", @@ -242,14 +240,8 @@ def _zig_repository_impl(repository_ctx): "host_platform": host_platform, } - url_format = repository_ctx.attr.url_format 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( url = [uf.format(**format_vars) for uf in url_formats], stripPrefix = "zig-{host_platform}-{version}/".format(**format_vars), @@ -288,8 +280,7 @@ zig_repository = repository_rule( attrs = { "version": attr.string(), "host_platform_sha256": attr.string_dict(), - "url_format": attr.string(doc = "Deprecated in favor of url_formats"), - "url_formats": attr.string_list(), + "url_formats": attr.string_list(allow_empty = False), "host_platform_include_root": attr.string_dict(), }, implementation = _zig_repository_impl,