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" )
6
+ < << << << Updated upstream
5
7
load ("//bazel/private:current_protoc.bzl" , "ProtocFilesToRun" )
8
+ == == == =
9
+ load ("//bazel/private:toolchain_helpers.bzl" , "toolchains" )
10
+ > >> >> >> Stashed changes
6
11
7
12
def _GetPath (ctx , path ):
8
13
if ctx .label .workspace_root :
@@ -72,6 +77,26 @@ def _CsharpOuts(srcs):
72
77
for src in srcs
73
78
]
74
79
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
+
75
100
ProtoGenInfo = provider (
76
101
fields = ["srcs" , "import_flags" , "deps" ],
77
102
)
@@ -311,7 +336,7 @@ def _internal_gen_well_known_protos_java_impl(ctx):
311
336
args .add_all ([src .path [offset :] for src in dep .direct_sources ])
312
337
313
338
ctx .actions .run (
314
- executable = ctx . attr . _protoc [ ProtocFilesToRun ]. files_to_run ,
339
+ executable = _protoc_files_to_run ( ctx ) ,
315
340
inputs = descriptors ,
316
341
outputs = [srcjar ],
317
342
arguments = [args ],
@@ -335,10 +360,9 @@ internal_gen_well_known_protos_java = rule(
335
360
"javalite" : attr .bool (
336
361
default = False ,
337
362
),
338
- "_protoc" : attr .label (
339
- default = "//bazel/private:current_protoc" ,
340
- ),
341
- },
363
+ } | _PROTOC_ATTRS ,
364
+ fragments = _PROTOC_FRAGMENTS ,
365
+ toolchains = _PROTOC_TOOLCHAINS ,
342
366
)
343
367
344
368
def _internal_gen_kt_protos (ctx ):
@@ -372,7 +396,7 @@ def _internal_gen_kt_protos(ctx):
372
396
args .add_all ([src .path [offset :] for src in dep .direct_sources ])
373
397
374
398
ctx .actions .run (
375
- executable = ctx . attr . _protoc [ ProtocFilesToRun ]. files_to_run ,
399
+ executable = _protoc_files_to_run ( ctx ) ,
376
400
inputs = descriptors ,
377
401
outputs = [srcjar ],
378
402
arguments = [args ],
@@ -396,10 +420,9 @@ internal_gen_kt_protos = rule(
396
420
"lite" : attr .bool (
397
421
default = False ,
398
422
),
399
- "_protoc" : attr .label (
400
- default = "//bazel/private:current_protoc" ,
401
- ),
402
- },
423
+ } | _PROTOC_ATTRS ,
424
+ fragments = _PROTOC_FRAGMENTS ,
425
+ toolchains = _PROTOC_TOOLCHAINS ,
403
426
)
404
427
405
428
def internal_objc_proto_library (
0 commit comments