forked from aspect-build/toolchains_protoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0002-Switch-to-toolchains.patch
More file actions
123 lines (112 loc) · 3.87 KB
/
0002-Switch-to-toolchains.patch
File metadata and controls
123 lines (112 loc) · 3.87 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
From d2e4671e04bd72211d15183f891707c4ff2f11cd Mon Sep 17 00:00:00 2001
From: Fabian Meumertzheim <fabian@meumertzhe.im>
Date: Mon, 16 Dec 2024 22:20:13 +0100
Subject: [PATCH 2/2] Switch to toolchains
---
bazel/private/BUILD | 6 ------
protobuf.bzl | 41 ++++++++++++++++++++++++++++++-----------
2 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/bazel/private/BUILD b/bazel/private/BUILD
index a5b3abeda..8c1c94ac8 100644
--- a/bazel/private/BUILD
+++ b/bazel/private/BUILD
@@ -1,5 +1,4 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
-load(":current_protoc.bzl", "current_protoc")
load(":native_bool_flag.bzl", "native_bool_flag")
package(default_applicable_licenses = ["//:license"])
@@ -29,11 +28,6 @@ toolchain_type(
visibility = ["//visibility:public"],
)
-current_protoc(
- name = "current_protoc",
- visibility = ["//:__subpackages__"],
-)
-
bzl_library(
name = "upb_proto_library_internal_bzl",
srcs = [
diff --git a/protobuf.bzl b/protobuf.bzl
index 736cc19cf..acb190942 100644
--- a/protobuf.bzl
+++ b/protobuf.bzl
@@ -1,8 +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:current_protoc.bzl", "ProtocFilesToRun")
+load("//bazel/private:toolchain_helpers.bzl", "toolchains")
def _GetPath(ctx, path):
if ctx.label.workspace_root:
@@ -72,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"],
)
@@ -311,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.attr._protoc[ProtocFilesToRun].files_to_run,
+ executable = _protoc_files_to_run(ctx),
inputs = descriptors,
outputs = [srcjar],
arguments = [args],
@@ -335,10 +356,9 @@ internal_gen_well_known_protos_java = rule(
"javalite": attr.bool(
default = False,
),
- "_protoc": attr.label(
- default = "//bazel/private:current_protoc",
- ),
- },
+ } | _PROTOC_ATTRS,
+ fragments = _PROTOC_FRAGMENTS,
+ toolchains = _PROTOC_TOOLCHAINS,
)
def _internal_gen_kt_protos(ctx):
@@ -372,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.attr._protoc[ProtocFilesToRun].files_to_run,
+ executable = _protoc_files_to_run(ctx),
inputs = descriptors,
outputs = [srcjar],
arguments = [args],
@@ -396,10 +416,9 @@ internal_gen_kt_protos = rule(
"lite": attr.bool(
default = False,
),
- "_protoc": attr.label(
- default = "//bazel/private:current_protoc",
- ),
- },
+ } | _PROTOC_ATTRS,
+ fragments = _PROTOC_FRAGMENTS,
+ toolchains = _PROTOC_TOOLCHAINS,
)
def internal_objc_proto_library(
--
2.49.0