Skip to content

Commit bc1a0e3

Browse files
committed
bazel: Remove hardcoded dependency on //:protoc from language runtimes
Without this change, language runtimes still result in a build of `//:protoc` even with a prebuilt `proto_toolchain` registered or `--proto_compiler` set to a precompiled protoc.
1 parent e9ea43a commit bc1a0e3

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

bazel/private/BUILD

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2+
load(":current_protoc.bzl", "current_protoc")
23
load(":native_bool_flag.bzl", "native_bool_flag")
34

45
package(default_applicable_licenses = ["//:license"])
@@ -28,6 +29,11 @@ toolchain_type(
2829
visibility = ["//visibility:public"],
2930
)
3031

32+
current_protoc(
33+
name = "current_protoc",
34+
visibility = ["//:__subpackages__"],
35+
)
36+
3137
bzl_library(
3238
name = "upb_proto_library_internal_bzl",
3339
srcs = [

protobuf.bzl

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ load("@bazel_skylib//lib:versions.bzl", "versions")
22
load("@rules_cc//cc:defs.bzl", "objc_library")
33
load("@rules_python//python:defs.bzl", "py_library")
44
load("//bazel/common:proto_info.bzl", "ProtoInfo")
5+
load("//bazel/private:current_protoc.bzl", "ProtocFilesToRun")
56

67
def _GetPath(ctx, path):
78
if ctx.label.workspace_root:
@@ -310,7 +311,7 @@ def _internal_gen_well_known_protos_java_impl(ctx):
310311
args.add_all([src.path[offset:] for src in dep.direct_sources])
311312

312313
ctx.actions.run(
313-
executable = ctx.executable._protoc,
314+
executable = ctx.attr._protoc[ProtocFilesToRun].files_to_run,
314315
inputs = descriptors,
315316
outputs = [srcjar],
316317
arguments = [args],
@@ -335,9 +336,7 @@ internal_gen_well_known_protos_java = rule(
335336
default = False,
336337
),
337338
"_protoc": attr.label(
338-
executable = True,
339-
cfg = "exec",
340-
default = "//:protoc",
339+
default = "//bazel/private:current_protoc",
341340
),
342341
},
343342
)
@@ -373,7 +372,7 @@ def _internal_gen_kt_protos(ctx):
373372
args.add_all([src.path[offset:] for src in dep.direct_sources])
374373

375374
ctx.actions.run(
376-
executable = ctx.executable._protoc,
375+
executable = ctx.attr._protoc[ProtocFilesToRun].files_to_run,
377376
inputs = descriptors,
378377
outputs = [srcjar],
379378
arguments = [args],
@@ -398,9 +397,7 @@ internal_gen_kt_protos = rule(
398397
default = False,
399398
),
400399
"_protoc": attr.label(
401-
executable = True,
402-
cfg = "exec",
403-
default = "//:protoc",
400+
default = "//bazel/private:current_protoc",
404401
),
405402
},
406403
)

0 commit comments

Comments
 (0)