-
Notifications
You must be signed in to change notification settings - Fork 286
/
Copy path0001-protobuf-19679-rm-protoc-dep.patch
91 lines (85 loc) · 2.87 KB
/
0001-protobuf-19679-rm-protoc-dep.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
diff --git a/protobuf.bzl b/protobuf.bzl
index 283c85850..ad91faba6 100644
--- a/protobuf.bzl
+++ b/protobuf.bzl
@@ -1,7 +1,9 @@
load("@bazel_skylib//lib:versions.bzl", "versions")
load("@rules_cc//cc:defs.bzl", "objc_library")
load("@rules_python//python:defs.bzl", "py_library")
+load("//bazel/common:proto_common.bzl", "proto_common")
load("//bazel/common:proto_info.bzl", "ProtoInfo")
+load("//bazel/private:toolchain_helpers.bzl", "toolchains")
def _GetPath(ctx, path):
if ctx.label.workspace_root:
@@ -71,6 +73,26 @@ def _CsharpOuts(srcs):
for src in srcs
]
+_PROTOC_ATTRS = toolchains.if_legacy_toolchain({
+ "_proto_compiler": attr.label(
+ cfg = "exec",
+ executable = True,
+ allow_files = True,
+ default = configuration_field("proto", "proto_compiler"),
+ ),
+})
+_PROTOC_FRAGMENTS = ["proto"]
+_PROTOC_TOOLCHAINS = toolchains.use_toolchain(toolchains.PROTO_TOOLCHAIN)
+
+def _protoc_files_to_run(ctx):
+ if proto_common.INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION:
+ toolchain = ctx.toolchains[toolchains.PROTO_TOOLCHAIN]
+ if not toolchain:
+ fail("Protocol compiler toolchain could not be resolved.")
+ return toolchain.proto.proto_compiler
+ else:
+ return ctx.attr._proto_compiler[DefaultInfo].files_to_run
+
ProtoGenInfo = provider(
fields = ["srcs", "import_flags", "deps"],
)
@@ -310,7 +332,7 @@ def _internal_gen_well_known_protos_java_impl(ctx):
args.add_all([src.path[offset:] for src in dep.direct_sources])
ctx.actions.run(
- executable = ctx.executable._protoc,
+ executable = _protoc_files_to_run(ctx),
inputs = descriptors,
outputs = [srcjar],
arguments = [args],
@@ -334,12 +356,9 @@ internal_gen_well_known_protos_java = rule(
"javalite": attr.bool(
default = False,
),
- "_protoc": attr.label(
- executable = True,
- cfg = "exec",
- default = "//:protoc",
- ),
- },
+ } | _PROTOC_ATTRS,
+ fragments = _PROTOC_FRAGMENTS,
+ toolchains = _PROTOC_TOOLCHAINS,
)
def _internal_gen_kt_protos(ctx):
@@ -373,7 +392,7 @@ def _internal_gen_kt_protos(ctx):
args.add_all([src.path[offset:] for src in dep.direct_sources])
ctx.actions.run(
- executable = ctx.executable._protoc,
+ executable = _protoc_files_to_run(ctx),
inputs = descriptors,
outputs = [srcjar],
arguments = [args],
@@ -397,12 +416,9 @@ internal_gen_kt_protos = rule(
"lite": attr.bool(
default = False,
),
- "_protoc": attr.label(
- executable = True,
- cfg = "exec",
- default = "//:protoc",
- ),
- },
+ } | _PROTOC_ATTRS,
+ fragments = _PROTOC_FRAGMENTS,
+ toolchains = _PROTOC_TOOLCHAINS,
)
def internal_objc_proto_library(