Skip to content

Commit

Permalink
Support matching release candidate toolchain versions (#3998)
Browse files Browse the repository at this point in the history
Release candidate versions are of the format `X.YrcZ`.
(ex: golang/go@30b6fd6)

Unfortunately, this format doesn't get matched properly in `go_toolchain.bzl`
so it's not possible to use rc versions without patching `VERSION`,
or you'll run into the error, for e.g., with the added test case:
```
no matching toolchains found for types @io_bazel_rules_go//go:toolchain
```

This PR adds a way to match `rc` versions for the toolchain.
  • Loading branch information
JacobOaks authored Jul 29, 2024
1 parent fb3afab commit 86a7f02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions go/private/go_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ def declare_bazel_toolchains(
visibility = ["//visibility:private"],
)

native.config_setting(
name = prefix + "match_minor_release_candidate",
flag_values = {
sdk_version_label: major + "." + minor + prerelease,
},
visibility = ["//visibility:private"],
)

native.config_setting(
name = prefix + "match_sdk_type",
flag_values = {
Expand All @@ -186,6 +194,7 @@ def declare_bazel_toolchains(
":" + prefix + "match_major_minor_version",
":" + prefix + "match_patch_version",
":" + prefix + "match_prerelease_version",
":" + prefix + "match_minor_release_candidate",
":" + prefix + "match_sdk_type",
],
visibility = ["//visibility:private"],
Expand Down
10 changes: 10 additions & 0 deletions tests/core/cross/sdk_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ var testCases = []testcase{
SDKVersion: "1.17.1",
expectedVersion: "go1.17.1",
},
{
Name: "1_17_release_candidate",
SDKVersion: "1.17rc1",
expectedVersion: "go1.17rc1",
},
}

func TestMain(m *testing.M) {
Expand All @@ -79,6 +84,11 @@ go_download_sdk(
name = "go_sdk_1_17_1",
version = "1.17.1",
)
go_download_sdk(
name = "go_sdk_1_17_rc1",
version = "1.17rc1",
)
go_register_toolchains()
-- main.go --
package main
Expand Down

0 comments on commit 86a7f02

Please sign in to comment.