Skip to content

Commit

Permalink
Upgrade zig to 0.11.0 (#111)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
linzhp authored Sep 2, 2023
1 parent 9a7a9e0 commit 0af7160
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 22 deletions.
28 changes: 17 additions & 11 deletions toolchain/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@ URL_FORMAT_RELEASE = "https://ziglang.org/download/{version}/zig-{host_platform}
# Bazel mirror or your own.
URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{host_platform}-{version}.{_ext}"

# Official Bazel's mirror with selected Zig SDK versions. Bazel community is
# generous enough to host the artifacts, which we use.
URL_FORMAT_BAZELMIRROR = "https://mirror.bazel.build/ziglang.org/builds/zig-{host_platform}-{version}.{_ext}"

_VERSION = "0.11.0-dev.3886+0c1bfe271"
_VERSION = "0.11.0"

_HOST_PLATFORM_SHA256 = {
"linux-aarch64": "12be476ed53c219507e77737dbb7f2a77b280760b8acbc6ba2eaaeb42b7d145e",
"linux-x86_64": "1b1c115c4ccbdc215cc3b07833c7957336d9f5fff816f97e5cafee556a9d8be8",
"macos-aarch64": "3943612c560dd066fba5698968317a146a0f585f6cdaa1e7c1df86685c7c4eaf",
"macos-x86_64": "0c89e5d934ecbf9f4d2dea6e3b8dfcc548a3d4184a856178b3db74e361031a2b",
"windows-x86_64": "c17df4db67ca328e77d2ff9a790a5e013d885de0667dbf25d9a1206103662d30",
"linux-aarch64": "956eb095d8ba44ac6ebd27f7c9956e47d92937c103bf754745d0a39cdaa5d4c6",
"linux-x86_64": "2d00e789fec4f71790a6e7bf83ff91d564943c5ee843c5fd966efc474b423047",
"macos-aarch64": "c6ebf927bb13a707d74267474a9f553274e64906fd21bf1c75a20bde8cadf7b2",
"macos-x86_64": "1c1c6b9a906b42baae73656e24e108fd8444bb50b6e8fd03e9e7a3f8b5f05686",
"windows-x86_64": "142caa3b804d86b4752556c9b6b039b7517a08afa3af842645c7e2dcd125f652",
}

_HOST_PLATFORM_EXT = {
Expand Down Expand Up @@ -68,7 +64,7 @@ lightning" three times in a row.

def toolchains(
version = _VERSION,
url_formats = [URL_FORMAT_BAZELMIRROR, URL_FORMAT_NIGHTLY],
url_formats = [],
host_platform_sha256 = _HOST_PLATFORM_SHA256,
host_platform_ext = _HOST_PLATFORM_EXT):
"""
Expand All @@ -77,6 +73,16 @@ def toolchains(
the user with register_toolchains() in the WORKSPACE file. See README
for possible choices.
"""

if not url_formats:
if "dev" in version:
original_format = URL_FORMAT_NIGHTLY
else:
original_format = URL_FORMAT_RELEASE

mirror_format = original_format.replace("https://ziglang.org/", "https://mirror.bazel.build/ziglang.org/")
url_formats = [mirror_format, original_format]

zig_repository(
name = "zig_sdk",
version = version,
Expand Down
28 changes: 22 additions & 6 deletions tools/releaser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var (
// hashes of already-released versions. Then just hardcode it here.
_tagHashes = map[string]string{
"v2.0.0-rc2": "40dff82816735e631e8bd51ede3af1c4ed1ad4646928ffb6a0e53e228e55738c",
"v2.0.0": "57f03a6c29793e8add7bd64186fc8066d23b5ffd06fe9cc6b0b8c499914d3a65",
"v2.0.0": "57f03a6c29793e8add7bd64186fc8066d23b5ffd06fe9cc6b0b8c499914d3a65",
}

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

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

var nightlyFormat, releaseFormat string
for _, expr := range parsed.Stmt {
def, ok := expr.(*bzl.AssignExpr)
if !ok {
Expand All @@ -507,8 +508,10 @@ func parseZigUpstream(defsPath string) (zigUpstream, error) {
switch key.Name {
case "_VERSION":
to = &ret.version
case "URL_FORMAT_BAZELMIRROR":
to = &ret.urlTemplate
case "URL_FORMAT_RELEASE":
to = &releaseFormat
case "URL_FORMAT_NIGHTLY":
to = &nightlyFormat
default:
continue
}
Expand All @@ -521,9 +524,22 @@ func parseZigUpstream(defsPath string) (zigUpstream, error) {
*to = value.Value
}

if ret.version == "" || ret.urlTemplate == "" {
return zigUpstream{}, errors.New("_VERSION and/or URL_FORMAT_BAZELMIRROR not found")
if ret.version == "" {
return zigUpstream{}, errors.New("_VERSION not found")
}
if strings.Contains(ret.version, "dev") {
ret.urlTemplate = nightlyFormat
} else {
ret.urlTemplate = releaseFormat
}
if ret.urlTemplate == "" {
return zigUpstream{}, fmt.Errorf("url format for %q not found", ret.version)
}
ret.urlTemplate = strings.Replace(ret.urlTemplate,
"https://ziglang.org/",
"https://mirror.bazel.build/ziglang.org/",
1,
)

return ret, nil
}
23 changes: 18 additions & 5 deletions tools/releaser/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@ func TestParseZigVersion(t *testing.T) {
wantErr string
}{
{
name: "ok",
contents: `_VERSION = "foo bar"; URL_FORMAT_BAZELMIRROR = "yadda"`,
name: "released url",
contents: `_VERSION = "0.11.0"; URL_FORMAT_RELEASE = "https://ziglang.org/download/{version}/zig-{host_platform}-{version}.{_ext}"`,
want: zigUpstream{
version: "foo bar",
urlTemplate: "yadda",
version: "0.11.0",
urlTemplate: "https://mirror.bazel.build/ziglang.org/download/{version}/zig-{host_platform}-{version}.{_ext}",
},
},
{
name: "nightly url",
contents: `_VERSION = "0.11.0-dev.2619+bd3e248c7"; URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{host_platform}-{version}.{_ext}"`,
want: zigUpstream{
version: "0.11.0-dev.2619+bd3e248c7",
urlTemplate: "https://mirror.bazel.build/ziglang.org/builds/zig-{host_platform}-{version}.{_ext}",
},
},
{
Expand All @@ -61,10 +69,15 @@ func TestParseZigVersion(t *testing.T) {
wantErr: "got a non-string expression",
},
{
name: "missing assignment",
name: "missing version assignment",
contents: "x1 = 1",
wantErr: "assign statement _VERSION = <...> not found",
},
{
name: "missing url assignment",
contents: `_VERSION = "0.11.0"; URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{host_platform}-{version}.{_ext}"`,
wantErr: "url format for '0.11.0' not found",
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 0af7160

Please sign in to comment.