11load ("@bazel_skylib//lib:versions.bzl" , "versions" )
22load ("@rules_cc//cc:defs.bzl" , "objc_library" )
33load ("@rules_python//python:defs.bzl" , "py_library" )
4+ load ("//bazel/common:proto_common.bzl" , "proto_common" )
45load ("//bazel/common:proto_info.bzl" , "ProtoInfo" )
6+ < << << << Updated upstream
57load ("//bazel/private:current_protoc.bzl" , "ProtocFilesToRun" )
8+ == == == =
9+ load ("//bazel/private:toolchain_helpers.bzl" , "toolchains" )
10+ > >> >> >> Stashed changes
611
712def _GetPath (ctx , path ):
813 if ctx .label .workspace_root :
@@ -72,6 +77,26 @@ def _CsharpOuts(srcs):
7277 for src in srcs
7378 ]
7479
80+ _PROTOC_ATTRS = toolchains .if_legacy_toolchain ({
81+ "_proto_compiler" : attr .label (
82+ cfg = "exec" ,
83+ executable = True ,
84+ allow_files = True ,
85+ default = configuration_field ("proto" , "proto_compiler" ),
86+ ),
87+ })
88+ _PROTOC_FRAGMENTS = ["proto" ]
89+ _PROTOC_TOOLCHAINS = toolchains .use_toolchain (toolchains .PROTO_TOOLCHAIN )
90+
91+ def _protoc_files_to_run (ctx ):
92+ if proto_common .INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION :
93+ toolchain = ctx .toolchains [toolchains .PROTO_TOOLCHAIN ]
94+ if not toolchain :
95+ fail ("Protocol compiler toolchain could not be resolved." )
96+ return toolchain .proto .proto_compiler
97+ else :
98+ return ctx .attr ._proto_compiler [DefaultInfo ].files_to_run
99+
75100ProtoGenInfo = provider (
76101 fields = ["srcs" , "import_flags" , "deps" ],
77102)
@@ -311,7 +336,7 @@ def _internal_gen_well_known_protos_java_impl(ctx):
311336 args .add_all ([src .path [offset :] for src in dep .direct_sources ])
312337
313338 ctx .actions .run (
314- executable = ctx . attr . _protoc [ ProtocFilesToRun ]. files_to_run ,
339+ executable = _protoc_files_to_run ( ctx ) ,
315340 inputs = descriptors ,
316341 outputs = [srcjar ],
317342 arguments = [args ],
@@ -335,10 +360,9 @@ internal_gen_well_known_protos_java = rule(
335360 "javalite" : attr .bool (
336361 default = False ,
337362 ),
338- "_protoc" : attr .label (
339- default = "//bazel/private:current_protoc" ,
340- ),
341- },
363+ } | _PROTOC_ATTRS ,
364+ fragments = _PROTOC_FRAGMENTS ,
365+ toolchains = _PROTOC_TOOLCHAINS ,
342366)
343367
344368def _internal_gen_kt_protos (ctx ):
@@ -372,7 +396,7 @@ def _internal_gen_kt_protos(ctx):
372396 args .add_all ([src .path [offset :] for src in dep .direct_sources ])
373397
374398 ctx .actions .run (
375- executable = ctx . attr . _protoc [ ProtocFilesToRun ]. files_to_run ,
399+ executable = _protoc_files_to_run ( ctx ) ,
376400 inputs = descriptors ,
377401 outputs = [srcjar ],
378402 arguments = [args ],
@@ -396,10 +420,9 @@ internal_gen_kt_protos = rule(
396420 "lite" : attr .bool (
397421 default = False ,
398422 ),
399- "_protoc" : attr .label (
400- default = "//bazel/private:current_protoc" ,
401- ),
402- },
423+ } | _PROTOC_ATTRS ,
424+ fragments = _PROTOC_FRAGMENTS ,
425+ toolchains = _PROTOC_TOOLCHAINS ,
403426)
404427
405428def internal_objc_proto_library (
0 commit comments