Skip to content

Commit 41ad19a

Browse files
mkruskal-googletonyliaoss
authored andcommitted
Use the toolchain protoc by default in internal rules.
#test-continuous While we'd like to burn these down, they're still necessary at least for WKT to avoid cyclic dependencies. This solution at least enabled prebuilt protoc for languages other than Java/Kotlin. Fixes #25453 PiperOrigin-RevId: 862290462
1 parent cfe8991 commit 41ad19a

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,6 @@ internal_py_proto_library(
671671
testonly = 1,
672672
srcs = [":generated_protos"],
673673
default_runtime = "",
674-
protoc = ":protoc",
675674
deps = ["//python:python_common_test_protos"],
676675
)
677676

protobuf.bzl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

309311
def _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,

python/build_targets.bzl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def build_targets(name):
5555
srcs = [":copied_wkt_proto_files"],
5656
include = ".",
5757
default_runtime = "",
58-
protoc = "//:protoc",
5958
srcs_version = "PY2AND3",
6059
visibility = [
6160
"//:__pkg__",
@@ -291,7 +290,6 @@ def build_targets(name):
291290
],
292291
include = ".",
293292
default_runtime = "",
294-
protoc = "//:protoc",
295293
srcs_version = "PY2AND3",
296294
visibility = [
297295
"//:__pkg__",
@@ -306,7 +304,6 @@ def build_targets(name):
306304
srcs = [":copied_test_proto_files"],
307305
include = ".",
308306
default_runtime = "",
309-
protoc = "//:protoc",
310307
srcs_version = "PY2AND3",
311308
visibility = ["//:__pkg__"],
312309
deps = [":well_known_types_py_pb2", ":test_dependency_proto_py_pb2"],
@@ -321,7 +318,6 @@ def build_targets(name):
321318
]),
322319
include = ".",
323320
default_runtime = ":protobuf_python",
324-
protoc = "//:protoc",
325321
srcs_version = "PY2AND3",
326322
visibility = ["//:__pkg__"],
327323
deps = [":python_common_test_protos"],
@@ -333,7 +329,6 @@ def build_targets(name):
333329
srcs = [":copied_conformance_test_files"],
334330
include = ".",
335331
default_runtime = "//:protobuf_python",
336-
protoc = "//:protoc",
337332
visibility = [
338333
"//conformance:__pkg__",
339334
"//python:__subpackages__",

0 commit comments

Comments
 (0)