Remove cc toolchain attr (#4601)

This is a legacy thing from before dedicated toolchains. We can drop it
now.
diff --git a/go/private/context.bzl b/go/private/context.bzl
index 049b8ec..395771c 100644
--- a/go/private/context.bzl
+++ b/go/private/context.bzl
@@ -81,7 +81,6 @@
 
 CPP_TOOLCHAIN_TYPE = Label("@bazel_tools//tools/cpp:toolchain_type")
 CGO_ATTRS = {
-    "_cc_toolchain": attr.label(default = "@rules_cc//cc:optional_current_cc_toolchain"),
     "_xcode_config": attr.label(default = configuration_field(fragment = "apple", name = "xcode_config_label")),
     "_pure_flag": attr.label(default = "//go/config:pure"),
     "_pure_constraint": attr.label(default = "//go/toolchain:cgo_off"),
@@ -580,17 +579,11 @@
         ctx.target_platform_has_constraint(attr._pure_constraint[platform_common.ConstraintValueInfo])
     )
 
-    has_cc_toolchain_attr = getattr(attr, "_cc_toolchain", None) != None
     needs_cgo_context = maybe_needs_cc_toolchain or go_config_info != None
-    if not cgo_disabled and needs_cgo_context and has_cc_toolchain_attr and CPP_TOOLCHAIN_TYPE in ctx.toolchains:
+    if not cgo_disabled and needs_cgo_context and CPP_TOOLCHAIN_TYPE in ctx.toolchains:
         cgo_context_info = cgo_context_data_impl(ctx)
 
-    if has_cc_toolchain_attr:
-        cgo_available = cgo_context_info != None
-    else:
-        # Preserve cgo build-mode/tag behavior for rules that won't use the
-        # C/C++ toolchain in their own actions.
-        cgo_available = not cgo_disabled
+    cgo_available = cgo_context_info != None
 
     if goos == "auto" and goarch == "auto" and cgo_available and go_config_info != None and not go_config_info.pure:
         # Fast-path to reuse the GoConfigInfo as-is
@@ -796,8 +789,6 @@
 
     # TODO(jayconrod): find a way to get a list of files that comprise the
     # toolchain (to be inputs into actions that need it).
-    # ctx.files._cc_toolchain won't work when cc toolchain resolution
-    # is switched on.
     cc_toolchain = find_cc_toolchain(ctx, mandatory = False)
     if not cc_toolchain or cc_toolchain.compiler in _UNSUPPORTED_C_COMPILERS:
         return None
diff --git a/proto/compiler.bzl b/proto/compiler.bzl
index 86ff492..520b7f3 100644
--- a/proto/compiler.bzl
+++ b/proto/compiler.bzl
@@ -32,6 +32,9 @@
 )
 load(
     "//go/private:context.bzl",
+    "CGO_ATTRS",
+    "CGO_FRAGMENTS",
+    "CGO_TOOLCHAINS",
     "new_go_info",
 )
 load(
@@ -246,7 +249,7 @@
 
 _go_proto_compiler = rule(
     implementation = _go_proto_compiler_impl,
-    attrs = dict({
+    attrs = {
         "deps": attr.label_list(providers = [GoInfo]),
         "options": attr.string_list(),
         "suffix": attr.string(default = ".pb.go"),
@@ -270,7 +273,7 @@
         "_go_context_data": attr.label(
             default = "//:go_context_data",
         ),
-    }, **_if_legacy_toolchain({
+    } | CGO_ATTRS | _if_legacy_toolchain({
         "_legacy_proto_toolchain": attr.label(
             # Setting cfg = "exec" here as the legacy_proto_toolchain target
             # already needs to apply the non_go_tool_transition. Flipping the
@@ -279,8 +282,9 @@
             cfg = "exec",
             default = "//proto/private:legacy_proto_toolchain",
         ),
-    })),
-    toolchains = [GO_TOOLCHAIN] + _use_toolchain(_PROTO_TOOLCHAIN_TYPE),
+    }),
+    fragments = CGO_FRAGMENTS,
+    toolchains = [GO_TOOLCHAIN] + CGO_TOOLCHAINS + _use_toolchain(_PROTO_TOOLCHAIN_TYPE),
 )
 
 def go_proto_compiler(name, **kwargs):
diff --git a/tests/core/go_binary/many_deps.bzl b/tests/core/go_binary/many_deps.bzl
index 827be2e..7eb32ae 100644
--- a/tests/core/go_binary/many_deps.bzl
+++ b/tests/core/go_binary/many_deps.bzl
@@ -19,6 +19,9 @@
 )
 load(
     "//go/private:context.bzl",
+    "CGO_ATTRS",
+    "CGO_FRAGMENTS",
+    "CGO_TOOLCHAINS",
     "new_go_info",
 )
 
@@ -44,8 +47,9 @@
         "_go_context_data": attr.label(
             default = "//:go_context_data",
         ),
-    },
-    toolchains = ["@io_bazel_rules_go//go:toolchain"],
+    } | CGO_ATTRS,
+    fragments = CGO_FRAGMENTS,
+    toolchains = ["@io_bazel_rules_go//go:toolchain"] + CGO_TOOLCHAINS,
 )
 
 def _gen_main_src_impl(ctx):
diff --git a/tests/core/go_proto_aspect/codegen.bzl b/tests/core/go_proto_aspect/codegen.bzl
index 4dc131f..761a5a0 100644
--- a/tests/core/go_proto_aspect/codegen.bzl
+++ b/tests/core/go_proto_aspect/codegen.bzl
@@ -1,5 +1,11 @@
 load("@bazel_skylib//lib:paths.bzl", "paths")
 load("@io_bazel_rules_go//go:def.bzl", "go_context", "new_go_info")
+load(
+    "//go/private:context.bzl",
+    "CGO_ATTRS",
+    "CGO_FRAGMENTS",
+    "CGO_TOOLCHAINS",
+)
 
 def _go_generated_library_impl(ctx):
     src = ctx.actions.declare_file("generated.go")
@@ -32,6 +38,7 @@
     attrs = {
         "importpath": attr.string(),
         "_go_context_data": attr.label(default = "@io_bazel_rules_go//:go_context_data"),
-    },
-    toolchains = ["@io_bazel_rules_go//go:toolchain"],
+    } | CGO_ATTRS,
+    fragments = CGO_FRAGMENTS,
+    toolchains = ["@io_bazel_rules_go//go:toolchain"] + CGO_TOOLCHAINS,
 )