@@ -59,3 +59,68 @@ verified to ensure binaries have not been tampered with. The tarball is cached b
5959
6060The global Zig cache directory (`~/.cache/zig` on Linux) is automatically cached between runs, and all
6161local caches are redirected to the global cache directory to make optimal use of this cross-run caching.
62+
63+ # # Adding a mirror
64+
65+ Anyone is welcome to host a Zig download mirror; thanks to the tarball signatures, the mirror provider need
66+ not be trusted. Naturally, if a mirror is found to be a bad actor, it will be removed, and likewise if a
67+ mirror repeatedly encounters reliability problems.
68+
69+ The rules for adding a mirror are listed below. Note that I (@mlugg) reserve the right to, for any or no
70+ reason, exclude mirrors which obey these rules, or include mirrors which violate them.
71+
72+ > [!NOTE]
73+ > While there are a lot of rules listed here, most of them should be obvious. They are stated explicitly here
74+ > to ensure complete clarity on what is expected of a mirror. Please do read these requirements through before
75+ > attempting to add a mirror.
76+
77+ * A mirror provides a single base URL, which we will call `X`.
78+ * `X` **may** include a path component, but is not required to. For instance, `https://foo.bar/zig/` is okay,
79+ as is `https://zig.baz.qux/`.
80+ * The mirror **must** have working HTTPS support. `X` **must** start with `https://`.
81+ * The mirror **must** cache tarballs locally. For instance, it may not simply forward all requests to another
82+ mirror.
83+ * The mirror **may** routinely evict its local tarball caches based on any reasonable factor, such as age,
84+ access frequency, or the existence of newer versions. This does not affect whether the mirror may return 404
85+ for requests to these files (see below).
86+ * The mirror **must** download its tarballs from either `https://ziglang.org/`, or another mirror which
87+ follows these rules.
88+ * Tarballs **must** be accessible by sending GET requests for files under `X`, where the filename matches that
89+ of the files provided by `https://ziglang.org/`, not including the directory part. For instance,
90+ ` X/zig-linux-x86_64-0.13.0.tar.xz` is a valid access, and should return the same file as
91+ ` https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz` .
92+ * Files provided by the mirror **must** be bit-for-bit identical to their `https://ziglang.org/` counterparts.
93+ * If a file is accessed whose Zig version is a master branch build (i.e. a `-dev` version), and the version is
94+ ordered before the latest major release of Zig, the mirror **may** respond with 404 Not Found, but is not
95+ required to. For instance, at the time of writing, `0.13.0` is the latest major release of Zig, so a mirror
96+ may respond with 404 for `0.13.0-dev...` builds, but *not* for `0.14.0-dev...` builds.
97+ * If a file is accessed whose Zig version is `0.5.0` or below, the mirror **may** respond with 404 Not Found,
98+ but is not required to.
99+ * If a file is acccessed which represents a *source* tarball, such as `X/zig-0.13.0.tar.xz`, the mirror
100+ **may** respond with 404 Not Found, but is not required to. The same applies to "bootstrap source tarballs",
101+ such as `X/zig-bootstrap-0.13.0.tar.xz`.
102+ * For all other accesses of valid Zig tarballs, the mirror **must** respond with status code 200 OK and the
103+ file in question. If the mirror has not yet cached the file locally, it should immediately download it from
104+ a permitted source (as covered above), and respond with the downloaded file.
105+ * If a tarball `X/foo.ext` is available by the above rules, requesting the minisign signature file
106+ ` X/foo.ext.minisig` **must** also respond with status code 200 OK and the signature file in question, like
107+ the tarball itself.
108+ * The mirror **may** rate-limit accesses. If an access failed due to rate-limiting, the mirror **should**
109+ return HTTP status code 429 Too Many Requests.
110+ * The mirror **may** undergo maintenance, upgrades, and other scheduled downtime. If an access fails for this
111+ reason, where possible, the mirror **should** return HTTP status code 503 Unavailable. The mirror **should**
112+ try to minimize such downtime.
113+ * The mirror **may** undergo occasional unintended and unscheduled downtime. The mirror **must** go to all
114+ efforts to minimize such outages, and **must** resolve such outages within a reasonable time upon being
115+ notified of them.
116+ * The mirror **may** observe the `?source=github-actions` query parameter to track how many requests originate
117+ from this Action. This Action will provide this query parameter to all mirror requests.
118+
119+ The easiest way to set up a mirror right now is using Mach's [Wrench][wrench]. For instructions, please see
120+ [the relevant section of their README][setup-wrench].
121+
122+ [wrench] : https://github.com/hexops/wrench
123+ [setup-wrench] : https://github.com/hexops/wrench?tab=readme-ov-file#run-your-own-ziglangorgdownload-mirror
124+
125+ After setting up a mirror, you can add it to this GitHub Action by opening a PR which adds it to the list in
126+ [mirrors.json](https://github.com/mlugg/setup-zig/blob/main/mirrors.json).
0 commit comments