Skip to content

Commit 0af7160

Browse files
authored
Upgrade zig to 0.11.0 (#111)
Zig 0.11.0 is released. Upgrading to the released version exposed some wrong assumptions about URL format. So this PR also fixed those assumptions by using `URL_FORMAT_RELEASE` for released version and determining the mirror URL format from the original one.
1 parent 9a7a9e0 commit 0af7160

File tree

3 files changed

+57
-22
lines changed

3 files changed

+57
-22
lines changed

toolchain/defs.bzl

+17-11
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,14 @@ URL_FORMAT_RELEASE = "https://ziglang.org/download/{version}/zig-{host_platform}
1818
# Bazel mirror or your own.
1919
URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{host_platform}-{version}.{_ext}"
2020

21-
# Official Bazel's mirror with selected Zig SDK versions. Bazel community is
22-
# generous enough to host the artifacts, which we use.
23-
URL_FORMAT_BAZELMIRROR = "https://mirror.bazel.build/ziglang.org/builds/zig-{host_platform}-{version}.{_ext}"
24-
25-
_VERSION = "0.11.0-dev.3886+0c1bfe271"
21+
_VERSION = "0.11.0"
2622

2723
_HOST_PLATFORM_SHA256 = {
28-
"linux-aarch64": "12be476ed53c219507e77737dbb7f2a77b280760b8acbc6ba2eaaeb42b7d145e",
29-
"linux-x86_64": "1b1c115c4ccbdc215cc3b07833c7957336d9f5fff816f97e5cafee556a9d8be8",
30-
"macos-aarch64": "3943612c560dd066fba5698968317a146a0f585f6cdaa1e7c1df86685c7c4eaf",
31-
"macos-x86_64": "0c89e5d934ecbf9f4d2dea6e3b8dfcc548a3d4184a856178b3db74e361031a2b",
32-
"windows-x86_64": "c17df4db67ca328e77d2ff9a790a5e013d885de0667dbf25d9a1206103662d30",
24+
"linux-aarch64": "956eb095d8ba44ac6ebd27f7c9956e47d92937c103bf754745d0a39cdaa5d4c6",
25+
"linux-x86_64": "2d00e789fec4f71790a6e7bf83ff91d564943c5ee843c5fd966efc474b423047",
26+
"macos-aarch64": "c6ebf927bb13a707d74267474a9f553274e64906fd21bf1c75a20bde8cadf7b2",
27+
"macos-x86_64": "1c1c6b9a906b42baae73656e24e108fd8444bb50b6e8fd03e9e7a3f8b5f05686",
28+
"windows-x86_64": "142caa3b804d86b4752556c9b6b039b7517a08afa3af842645c7e2dcd125f652",
3329
}
3430

3531
_HOST_PLATFORM_EXT = {
@@ -68,7 +64,7 @@ lightning" three times in a row.
6864

6965
def toolchains(
7066
version = _VERSION,
71-
url_formats = [URL_FORMAT_BAZELMIRROR, URL_FORMAT_NIGHTLY],
67+
url_formats = [],
7268
host_platform_sha256 = _HOST_PLATFORM_SHA256,
7369
host_platform_ext = _HOST_PLATFORM_EXT):
7470
"""
@@ -77,6 +73,16 @@ def toolchains(
7773
the user with register_toolchains() in the WORKSPACE file. See README
7874
for possible choices.
7975
"""
76+
77+
if not url_formats:
78+
if "dev" in version:
79+
original_format = URL_FORMAT_NIGHTLY
80+
else:
81+
original_format = URL_FORMAT_RELEASE
82+
83+
mirror_format = original_format.replace("https://ziglang.org/", "https://mirror.bazel.build/ziglang.org/")
84+
url_formats = [mirror_format, original_format]
85+
8086
zig_repository(
8187
name = "zig_sdk",
8288
version = version,

tools/releaser/main.go

+22-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var (
4040
// hashes of already-released versions. Then just hardcode it here.
4141
_tagHashes = map[string]string{
4242
"v2.0.0-rc2": "40dff82816735e631e8bd51ede3af1c4ed1ad4646928ffb6a0e53e228e55738c",
43-
"v2.0.0": "57f03a6c29793e8add7bd64186fc8066d23b5ffd06fe9cc6b0b8c499914d3a65",
43+
"v2.0.0": "57f03a6c29793e8add7bd64186fc8066d23b5ffd06fe9cc6b0b8c499914d3a65",
4444
}
4545

4646
_boilerplateFiles = []string{
@@ -465,7 +465,7 @@ func checkZigMirrored(repoRoot string) error {
465465
// - so we'd rather pick a single platform and test it.
466466
// - because windows coverage is smallest, let's take the windows platform.
467467
url := strings.Replace(upstream.urlTemplate, "{host_platform}", "windows-x86_64", 1)
468-
url = strings.Replace(url, "{version}", upstream.version, 1)
468+
url = strings.ReplaceAll(url, "{version}", upstream.version)
469469
url = strings.Replace(url, "{_ext}", "zip", 1)
470470

471471
log("checking if zig is mirorred in %q", url)
@@ -495,6 +495,7 @@ func parseZigUpstream(defsPath string) (zigUpstream, error) {
495495
return zigUpstream{}, err
496496
}
497497

498+
var nightlyFormat, releaseFormat string
498499
for _, expr := range parsed.Stmt {
499500
def, ok := expr.(*bzl.AssignExpr)
500501
if !ok {
@@ -507,8 +508,10 @@ func parseZigUpstream(defsPath string) (zigUpstream, error) {
507508
switch key.Name {
508509
case "_VERSION":
509510
to = &ret.version
510-
case "URL_FORMAT_BAZELMIRROR":
511-
to = &ret.urlTemplate
511+
case "URL_FORMAT_RELEASE":
512+
to = &releaseFormat
513+
case "URL_FORMAT_NIGHTLY":
514+
to = &nightlyFormat
512515
default:
513516
continue
514517
}
@@ -521,9 +524,22 @@ func parseZigUpstream(defsPath string) (zigUpstream, error) {
521524
*to = value.Value
522525
}
523526

524-
if ret.version == "" || ret.urlTemplate == "" {
525-
return zigUpstream{}, errors.New("_VERSION and/or URL_FORMAT_BAZELMIRROR not found")
527+
if ret.version == "" {
528+
return zigUpstream{}, errors.New("_VERSION not found")
526529
}
530+
if strings.Contains(ret.version, "dev") {
531+
ret.urlTemplate = nightlyFormat
532+
} else {
533+
ret.urlTemplate = releaseFormat
534+
}
535+
if ret.urlTemplate == "" {
536+
return zigUpstream{}, fmt.Errorf("url format for %q not found", ret.version)
537+
}
538+
ret.urlTemplate = strings.Replace(ret.urlTemplate,
539+
"https://ziglang.org/",
540+
"https://mirror.bazel.build/ziglang.org/",
541+
1,
542+
)
527543

528544
return ret, nil
529545
}

tools/releaser/main_test.go

+18-5
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,19 @@ func TestParseZigVersion(t *testing.T) {
4848
wantErr string
4949
}{
5050
{
51-
name: "ok",
52-
contents: `_VERSION = "foo bar"; URL_FORMAT_BAZELMIRROR = "yadda"`,
51+
name: "released url",
52+
contents: `_VERSION = "0.11.0"; URL_FORMAT_RELEASE = "https://ziglang.org/download/{version}/zig-{host_platform}-{version}.{_ext}"`,
5353
want: zigUpstream{
54-
version: "foo bar",
55-
urlTemplate: "yadda",
54+
version: "0.11.0",
55+
urlTemplate: "https://mirror.bazel.build/ziglang.org/download/{version}/zig-{host_platform}-{version}.{_ext}",
56+
},
57+
},
58+
{
59+
name: "nightly url",
60+
contents: `_VERSION = "0.11.0-dev.2619+bd3e248c7"; URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{host_platform}-{version}.{_ext}"`,
61+
want: zigUpstream{
62+
version: "0.11.0-dev.2619+bd3e248c7",
63+
urlTemplate: "https://mirror.bazel.build/ziglang.org/builds/zig-{host_platform}-{version}.{_ext}",
5664
},
5765
},
5866
{
@@ -61,10 +69,15 @@ func TestParseZigVersion(t *testing.T) {
6169
wantErr: "got a non-string expression",
6270
},
6371
{
64-
name: "missing assignment",
72+
name: "missing version assignment",
6573
contents: "x1 = 1",
6674
wantErr: "assign statement _VERSION = <...> not found",
6775
},
76+
{
77+
name: "missing url assignment",
78+
contents: `_VERSION = "0.11.0"; URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{host_platform}-{version}.{_ext}"`,
79+
wantErr: "url format for '0.11.0' not found",
80+
},
6881
}
6982

7083
for _, tt := range tests {

0 commit comments

Comments
 (0)