1616 "@bazel_skylib//lib:paths.bzl" ,
1717 "paths" ,
1818)
19- load ("@com_google_protobuf//bazel/common:proto_common.bzl" , "proto_common" )
2019load (
21- "@com_google_protobuf//bazel/common:proto_lang_toolchain_info .bzl" ,
22- "ProtoLangToolchainInfo " ,
20+ "@rules_proto//proto:proto_common .bzl" ,
21+ proto_toolchains = "toolchains " ,
2322)
2423load (
2524 "//go:def.bzl" ,
4948# default.
5049_PROTO_TOOLCHAIN_TYPE = "@rules_proto//proto:toolchain_type"
5150
52- def _incompatible_toolchains_enabled ():
53- return getattr (proto_common , "INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION" , False )
54-
55- def _find_toolchain (ctx , legacy_attr , toolchain_type ):
56- if _incompatible_toolchains_enabled ():
57- toolchain = ctx .toolchains [toolchain_type ]
58- if not toolchain :
59- fail ("No toolchains registered for '%s'." % toolchain_type )
60- return toolchain .proto
61- else :
62- return getattr (ctx .attr , legacy_attr )[ProtoLangToolchainInfo ]
63-
64- def _use_toolchain (toolchain_type ):
65- if _incompatible_toolchains_enabled ():
66- return [config_common .toolchain_type (toolchain_type , mandatory = False )]
67- else :
68- return []
69-
70- def _if_legacy_toolchain (legacy_attr_dict ):
71- if _incompatible_toolchains_enabled ():
72- return {}
73- else :
74- return legacy_attr_dict
75-
7651GoProtoCompiler = provider (
7752 doc = "Information and dependencies needed to generate Go code from protos" ,
7853 fields = {
@@ -219,7 +194,7 @@ def proto_path(src, proto):
219194def _go_proto_compiler_impl (ctx ):
220195 go = go_context (ctx , include_deprecated_properties = False )
221196 go_info = new_go_info (go , ctx .attr )
222- proto_toolchain = _find_toolchain (
197+ proto_toolchain = proto_toolchains . find_toolchain (
223198 ctx ,
224199 legacy_attr = "_legacy_proto_toolchain" ,
225200 toolchain_type = _PROTO_TOOLCHAIN_TYPE ,
@@ -269,7 +244,7 @@ _go_proto_compiler = rule(
269244 "_go_context_data" : attr .label (
270245 default = "//:go_context_data" ,
271246 ),
272- }, ** _if_legacy_toolchain ({
247+ }, ** proto_toolchains . if_legacy_toolchain ({
273248 "_legacy_proto_toolchain" : attr .label (
274249 # Setting cfg = "exec" here as the legacy_proto_toolchain target
275250 # already needs to apply the non_go_tool_transition. Flipping the
@@ -279,7 +254,7 @@ _go_proto_compiler = rule(
279254 default = "//proto/private:legacy_proto_toolchain" ,
280255 ),
281256 })),
282- toolchains = [GO_TOOLCHAIN ] + _use_toolchain (_PROTO_TOOLCHAIN_TYPE ),
257+ toolchains = [GO_TOOLCHAIN ] + proto_toolchains . use_toolchain (_PROTO_TOOLCHAIN_TYPE ),
283258)
284259
285260def go_proto_compiler (name , ** kwargs ):
0 commit comments