Add platform contraints for GOAMD64 (#3251)

The new constraints `//go/constraints/amd64:v1` to `v4` can be used to
mark a platform as supporting the corresponding level of `GOAMD64`.

To use the new feature, users would supply their own platform:

```starlark
platform(
    name = "amd64_with_avx",
    contraint_values = [
        "@platforms//os:linux",
        "@platforms//cpu:x86_64",
        "@io_bazel_rules_go//go/constraints/amd64:v3",
    ],
)
```

and then specify the platform with `--platforms`.
diff --git a/BUILD.bazel b/BUILD.bazel
index 2687c95..a6d0ca1 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -105,6 +105,13 @@
 # to depend on all build settings directly.
 go_config(
     name = "go_config",
+    amd64 = select({
+        "//go/constraints/amd64:v2": "v2",
+        "//go/constraints/amd64:v3": "v3",
+        "//go/constraints/amd64:v4": "v4",
+        # The default is v1.
+        "//conditions:default": None,
+    }),
     cover_format = "//go/config:cover_format",
     # Always include debug symbols with -c dbg.
     debug = select({
diff --git a/go/BUILD.bazel b/go/BUILD.bazel
index eb8588d..fbe073e 100644
--- a/go/BUILD.bazel
+++ b/go/BUILD.bazel
@@ -5,6 +5,7 @@
     testonly = True,
     srcs = glob(["**"]) + [
         "//go/config:all_files",
+        "//go/constraints/amd64:all_files",
         "//go/platform:all_files",
         "//go/toolchain:all_files",
         "//go/tools:all_files",
diff --git a/go/constraints/amd64/BUILD.bazel b/go/constraints/amd64/BUILD.bazel
new file mode 100644
index 0000000..0bc0ba3
--- /dev/null
+++ b/go/constraints/amd64/BUILD.bazel
@@ -0,0 +1,38 @@
+package(
+    default_visibility = ["//visibility:public"],
+)
+
+# Represents the level of support for the particular microarchitecture of a
+# target platform based on the general amd64 architecture.
+# GOAMD64 is set based on the chosen constraint_value.
+# See https://github.com/golang/go/wiki/MinimumRequirements#amd64
+constraint_setting(
+    name = "amd64",
+)
+
+constraint_value(
+    name = "v1",
+    constraint_setting = ":amd64",
+)
+
+constraint_value(
+    name = "v2",
+    constraint_setting = ":amd64",
+)
+
+constraint_value(
+    name = "v3",
+    constraint_setting = ":amd64",
+)
+
+constraint_value(
+    name = "v4",
+    constraint_setting = ":amd64",
+)
+
+filegroup(
+    name = "all_files",
+    testonly = True,
+    srcs = glob(["**"]),
+    visibility = ["//visibility:public"],
+)
diff --git a/go/private/context.bzl b/go/private/context.bzl
index 054b86e..fa76447 100644
--- a/go/private/context.bzl
+++ b/go/private/context.bzl
@@ -432,6 +432,12 @@
         # happen. See #2291 for more information.
         "GOPATH": "",
     }
+
+    # The level of support is determined by the platform constraints in
+    # //go/constraints/amd64.
+    # See https://github.com/golang/go/wiki/MinimumRequirements#amd64
+    if mode.amd64:
+        env["GOAMD64"] = mode.amd64
     if mode.pure:
         crosstool = []
         cgo_tools = None
@@ -814,6 +820,7 @@
         tags = ctx.attr.gotags[BuildSettingInfo].value,
         stamp = ctx.attr.stamp,
         cover_format = ctx.attr.cover_format[BuildSettingInfo].value,
+        amd64 = ctx.attr.amd64,
     )]
 
 go_config = rule(
@@ -856,6 +863,7 @@
             mandatory = True,
             providers = [BuildSettingInfo],
         ),
+        "amd64": attr.string(),
     },
     provides = [GoConfigInfo],
     doc = """Collects information about build settings in the current
diff --git a/go/private/mode.bzl b/go/private/mode.bzl
index e9b094b..19c240a 100644
--- a/go/private/mode.bzl
+++ b/go/private/mode.bzl
@@ -80,6 +80,7 @@
     debug = go_config_info.debug if go_config_info else False
     linkmode = go_config_info.linkmode if go_config_info else LINKMODE_NORMAL
     cover_format = go_config_info and go_config_info.cover_format
+    amd64 = go_config_info.amd64 if go_config_info else None
     goos = go_toolchain.default_goos if getattr(ctx.attr, "goos", "auto") == "auto" else ctx.attr.goos
     goarch = go_toolchain.default_goarch if getattr(ctx.attr, "goarch", "auto") == "auto" else ctx.attr.goarch
 
@@ -112,6 +113,7 @@
         goarch = goarch,
         tags = tags,
         cover_format = cover_format,
+        amd64 = amd64,
     )
 
 def installsuffix(mode):