1
1
load ("@bazel_skylib//lib:versions.bzl" , "versions" )
2
2
load ("@rules_cc//cc:defs.bzl" , "objc_library" )
3
3
load ("@rules_python//python:defs.bzl" , "py_library" )
4
+ load ("//bazel/common:proto_common.bzl" , "proto_common" )
4
5
load ("//bazel/common:proto_info.bzl" , "ProtoInfo" )
5
- load ("//bazel/private:current_protoc .bzl" , "ProtocFilesToRun " )
6
+ load ("//bazel/private:toolchain_helpers .bzl" , "toolchains " )
6
7
7
8
def _GetPath (ctx , path ):
8
9
if ctx .label .workspace_root :
@@ -72,6 +73,26 @@ def _CsharpOuts(srcs):
72
73
for src in srcs
73
74
]
74
75
76
+ _PROTOC_ATTRS = toolchains .if_legacy_toolchain ({
77
+ "_proto_compiler" : attr .label (
78
+ cfg = "exec" ,
79
+ executable = True ,
80
+ allow_files = True ,
81
+ default = configuration_field ("proto" , "proto_compiler" ),
82
+ ),
83
+ })
84
+ _PROTOC_FRAGMENTS = ["proto" ]
85
+ _PROTOC_TOOLCHAINS = toolchains .use_toolchain (toolchains .PROTO_TOOLCHAIN )
86
+
87
+ def _protoc_files_to_run (ctx ):
88
+ if proto_common .INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION :
89
+ toolchain = ctx .toolchains [toolchains .PROTO_TOOLCHAIN ]
90
+ if not toolchain :
91
+ fail ("Protocol compiler toolchain could not be resolved." )
92
+ return toolchain .proto .proto_compiler
93
+ else :
94
+ return ctx .attr ._proto_compiler [DefaultInfo ].files_to_run
95
+
75
96
ProtoGenInfo = provider (
76
97
fields = ["srcs" , "import_flags" , "deps" ],
77
98
)
@@ -311,7 +332,7 @@ def _internal_gen_well_known_protos_java_impl(ctx):
311
332
args .add_all ([src .path [offset :] for src in dep .direct_sources ])
312
333
313
334
ctx .actions .run (
314
- executable = ctx . attr . _protoc [ ProtocFilesToRun ]. files_to_run ,
335
+ executable = _protoc_files_to_run ( ctx ) ,
315
336
inputs = descriptors ,
316
337
outputs = [srcjar ],
317
338
arguments = [args ],
@@ -335,10 +356,9 @@ internal_gen_well_known_protos_java = rule(
335
356
"javalite" : attr .bool (
336
357
default = False ,
337
358
),
338
- "_protoc" : attr .label (
339
- default = "//bazel/private:current_protoc" ,
340
- ),
341
- },
359
+ } | _PROTOC_ATTRS ,
360
+ fragments = _PROTOC_FRAGMENTS ,
361
+ toolchains = _PROTOC_TOOLCHAINS ,
342
362
)
343
363
344
364
def _internal_gen_kt_protos (ctx ):
@@ -372,7 +392,7 @@ def _internal_gen_kt_protos(ctx):
372
392
args .add_all ([src .path [offset :] for src in dep .direct_sources ])
373
393
374
394
ctx .actions .run (
375
- executable = ctx . attr . _protoc [ ProtocFilesToRun ]. files_to_run ,
395
+ executable = _protoc_files_to_run ( ctx ) ,
376
396
inputs = descriptors ,
377
397
outputs = [srcjar ],
378
398
arguments = [args ],
@@ -396,10 +416,9 @@ internal_gen_kt_protos = rule(
396
416
"lite" : attr .bool (
397
417
default = False ,
398
418
),
399
- "_protoc" : attr .label (
400
- default = "//bazel/private:current_protoc" ,
401
- ),
402
- },
419
+ } | _PROTOC_ATTRS ,
420
+ fragments = _PROTOC_FRAGMENTS ,
421
+ toolchains = _PROTOC_TOOLCHAINS ,
403
422
)
404
423
405
424
def internal_objc_proto_library (
0 commit comments