@@ -195,7 +195,8 @@ def _proto_gen_impl(ctx):
195195 generated_files .extend (outs )
196196
197197 inputs = [src ] + deps .to_list ()
198- tools = [ctx .executable .protoc ]
198+ protoc = ctx .executable .protoc or _protoc_files_to_run (ctx )
199+ tools = [protoc ]
199200 if ctx .executable .plugin :
200201 plugin = ctx .executable .plugin
201202 lang = ctx .attr .plugin_language
@@ -218,14 +219,14 @@ def _proto_gen_impl(ctx):
218219 tools = tools ,
219220 outputs = outs ,
220221 arguments = args + import_flags .to_list () + [src .path ],
221- executable = ctx . executable . protoc ,
222+ executable = protoc ,
222223 mnemonic = "ProtoCompile" ,
223224 use_default_shell_env = True ,
224225 )
225226 else :
226227 for out in outs :
227228 orig_command = " " .join (
228- ["$(realpath %s)" % ctx . executable . protoc .path ] + args +
229+ ["$(realpath %s)" % protoc .path ] + args +
229230 import_flags_real + [src .basename ],
230231 )
231232 command = ";" .join ([
@@ -267,7 +268,6 @@ Args:
267268 deps: a list of dependency labels; must be other proto libraries.
268269 enable_editions: if true, sets the --experimental_editions flag.
269270 includes: a list of include paths to .proto files.
270- protoc: the label of the protocol compiler to generate the sources.
271271 plugin: the label of the protocol compiler plugin to be passed to the protocol
272272 compiler.
273273 plugin_language: the language of the generated sources
@@ -288,7 +288,7 @@ _proto_gen = rule(
288288 cfg = "exec" ,
289289 executable = True ,
290290 allow_single_file = True ,
291- mandatory = True ,
291+ mandatory = False ,
292292 ),
293293 "plugin" : attr .label (
294294 cfg = "exec" ,
@@ -302,8 +302,10 @@ _proto_gen = rule(
302302 "out_type" : attr .string (
303303 default = "all" ,
304304 ),
305- },
305+ } | _PROTOC_ATTRS ,
306306 implementation = _proto_gen_impl ,
307+ fragments = _PROTOC_FRAGMENTS ,
308+ toolchains = _PROTOC_TOOLCHAINS ,
307309)
308310
309311def _internal_gen_well_known_protos_java_impl (ctx ):
@@ -434,7 +436,7 @@ def internal_objc_proto_library(
434436 proto_deps = [],
435437 includes = ["." ],
436438 default_runtime = Label ("//:protobuf_objc" ),
437- protoc = Label ( "//:protoc" ) ,
439+ protoc = None ,
438440 testonly = None ,
439441 visibility = ["//visibility:public" ],
440442 ** kwargs ):
@@ -522,7 +524,7 @@ def internal_ruby_proto_library(
522524 deps = [],
523525 includes = ["." ],
524526 default_runtime = "@com_google_protobuf//ruby:protobuf" ,
525- protoc = "@com_google_protobuf//:protoc" ,
527+ protoc = None ,
526528 testonly = None ,
527529 visibility = ["//visibility:public" ],
528530 ** kwargs ):
@@ -577,7 +579,7 @@ def internal_rbs_proto_library(
577579 srcs = [],
578580 deps = [],
579581 includes = ["." ],
580- protoc = "@com_google_protobuf//:protoc" ,
582+ protoc = None ,
581583 testonly = None ,
582584 visibility = ["//visibility:public" ],
583585 ** kwargs ):
@@ -640,7 +642,7 @@ def internal_py_proto_library(
640642 py_extra_srcs = [],
641643 include = None ,
642644 default_runtime = Label ("//:protobuf_python" ),
643- protoc = Label ( "//:protoc" ) ,
645+ protoc = None ,
644646 use_grpc_plugin = False ,
645647 testonly = None ,
646648 ** kargs ):
@@ -716,7 +718,7 @@ def _source_proto_library(
716718 outs = [],
717719 lang = None ,
718720 includes = ["." ],
719- protoc = Label ( "//:protoc" ) ,
721+ protoc = None ,
720722 testonly = None ,
721723 visibility = ["//visibility:public" ],
722724 enable_editions = False ,
0 commit comments