diff --git a/go/private/BUILD.sdk.bazel b/go/private/BUILD.sdk.bazel index d33813e098..47415dc371 100644 --- a/go/private/BUILD.sdk.bazel +++ b/go/private/BUILD.sdk.bazel @@ -97,6 +97,13 @@ config_setting( }, ) +config_setting( + name = "match_{extra_sdk_version}_sdk", + flag_values = { + sdk_version_label: "{extra_sdk_version}", + }, +) + selects.config_setting_group( name = "sdk_version_setting", match_any = [ @@ -105,6 +112,7 @@ selects.config_setting_group( ":match_major_minor_version", ":match_patch_version", ":match_prerelease_version", + ":match_{extra_sdk_version}_sdk", ], ) diff --git a/go/private/sdk.bzl b/go/private/sdk.bzl index 3bc23d9fa8..34065f23f6 100644 --- a/go/private/sdk.bzl +++ b/go/private/sdk.bzl @@ -254,6 +254,7 @@ def _sdk_build_file(ctx, platform, version): "{minor_version}": str(minor), "{patch_version}": str(patch), "{prerelease_suffix}": prerelease, + "{extra_sdk_version}": ctx.attr.name, }, ) diff --git a/go/toolchains.rst b/go/toolchains.rst index 25b7ee84c5..1f1efe1e77 100644 --- a/go/toolchains.rst +++ b/go/toolchains.rst @@ -76,6 +76,7 @@ the flag ``--@io_bazel_rules_go//go/toolchain:sdk_version="version"`` where ``"version"`` is the SDK version you would like to build with, eg. ``"1.18.3"``. The SDK version can omit the patch, or include a prerelease part, eg. ``"1"``, ``"1.18"``, ``"1.18.0"``, and ``"1.19.0beta1"`` are all valid values for ``sdk_version``. +You can also refer to a Go SDK by name of the target used to declare it. The toolchain ~~~~~~~~~~~~~ diff --git a/tests/core/go_download_sdk/go_download_sdk_test.go b/tests/core/go_download_sdk/go_download_sdk_test.go index 51dd5c0ae4..2c89b7c3a3 100644 --- a/tests/core/go_download_sdk/go_download_sdk_test.go +++ b/tests/core/go_download_sdk/go_download_sdk_test.go @@ -107,10 +107,13 @@ go_download_sdk( `, optToWantVersion: map[string]string{ "": "go1.16", - "--@io_bazel_rules_go//go/toolchain:sdk_version=1": "go1.16", - "--@io_bazel_rules_go//go/toolchain:sdk_version=1.17": "go1.17", - "--@io_bazel_rules_go//go/toolchain:sdk_version=1.17.0": "go1.17", - "--@io_bazel_rules_go//go/toolchain:sdk_version=1.17.1": "go1.17.1", + "--@io_bazel_rules_go//go/toolchain:sdk_version=1": "go1.16", + "--@io_bazel_rules_go//go/toolchain:sdk_version=1.17": "go1.17", + "--@io_bazel_rules_go//go/toolchain:sdk_version=1.17.0": "go1.17", + "--@io_bazel_rules_go//go/toolchain:sdk_version=1.17.1": "go1.17.1", + "--@io_bazel_rules_go//go/toolchain:sdk_version=go_sdk": "go1.16", + "--@io_bazel_rules_go//go/toolchain:sdk_version=go_sdk_1_17": "go1.17", + "--@io_bazel_rules_go//go/toolchain:sdk_version=go_sdk_1_17_1": "go1.17.1", }, }, } { @@ -122,7 +125,7 @@ go_download_sdk( i := bytes.Index(origWorkspaceData, []byte("go_rules_dependencies()")) if i < 0 { - t.Fatalf("%s: could not find call to go_rules_dependencies()") + t.Fatal("could not find call to go_rules_dependencies()") } buf := &bytes.Buffer{} @@ -143,17 +146,19 @@ go_register_toolchains() }() for opt, wantVersion := range test.optToWantVersion { - args := []string{ - "test", - "//:version_test", - "--test_arg=-version=" + wantVersion, - } - if opt != "" { - args = append(args, opt) - } - if err := bazel_testing.RunBazel(args...); err != nil { - t.Fatal(err) - } + t.Run(wantVersion, func(t *testing.T) { + args := []string{ + "test", + "//:version_test", + "--test_arg=-version=" + wantVersion, + } + if opt != "" { + args = append(args, opt) + } + if err := bazel_testing.RunBazel(args...); err != nil { + t.Fatal(err) + } + }) } }) }