Skip to content

Commit d92eae2

Browse files
committed
Switch to toolchains
1 parent bc1a0e3 commit d92eae2

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

bazel/private/BUILD

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

54
package(default_applicable_licenses = ["//:license"])
@@ -29,11 +28,6 @@ toolchain_type(
2928
visibility = ["//visibility:public"],
3029
)
3130

32-
current_protoc(
33-
name = "current_protoc",
34-
visibility = ["//:__subpackages__"],
35-
)
36-
3731
bzl_library(
3832
name = "upb_proto_library_internal_bzl",
3933
srcs = [

protobuf.bzl

+33-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
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")
4+
load("//bazel/common:proto_common.bzl", "proto_common")
45
load("//bazel/common:proto_info.bzl", "ProtoInfo")
6+
<<<<<<< Updated upstream
57
load("//bazel/private:current_protoc.bzl", "ProtocFilesToRun")
8+
=======
9+
load("//bazel/private:toolchain_helpers.bzl", "toolchains")
10+
>>>>>>> Stashed changes
611

712
def _GetPath(ctx, path):
813
if ctx.label.workspace_root:
@@ -72,6 +77,26 @@ def _CsharpOuts(srcs):
7277
for src in srcs
7378
]
7479

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+
75100
ProtoGenInfo = provider(
76101
fields = ["srcs", "import_flags", "deps"],
77102
)
@@ -311,7 +336,7 @@ def _internal_gen_well_known_protos_java_impl(ctx):
311336
args.add_all([src.path[offset:] for src in dep.direct_sources])
312337

313338
ctx.actions.run(
314-
executable = ctx.attr._protoc[ProtocFilesToRun].files_to_run,
339+
executable = _protoc_files_to_run(ctx),
315340
inputs = descriptors,
316341
outputs = [srcjar],
317342
arguments = [args],
@@ -335,10 +360,9 @@ internal_gen_well_known_protos_java = rule(
335360
"javalite": attr.bool(
336361
default = False,
337362
),
338-
"_protoc": attr.label(
339-
default = "//bazel/private:current_protoc",
340-
),
341-
},
363+
} | _PROTOC_ATTRS,
364+
fragments = _PROTOC_FRAGMENTS,
365+
toolchains = _PROTOC_TOOLCHAINS,
342366
)
343367

344368
def _internal_gen_kt_protos(ctx):
@@ -372,7 +396,7 @@ def _internal_gen_kt_protos(ctx):
372396
args.add_all([src.path[offset:] for src in dep.direct_sources])
373397

374398
ctx.actions.run(
375-
executable = ctx.attr._protoc[ProtocFilesToRun].files_to_run,
399+
executable = _protoc_files_to_run(ctx),
376400
inputs = descriptors,
377401
outputs = [srcjar],
378402
arguments = [args],
@@ -396,10 +420,9 @@ internal_gen_kt_protos = rule(
396420
"lite": attr.bool(
397421
default = False,
398422
),
399-
"_protoc": attr.label(
400-
default = "//bazel/private:current_protoc",
401-
),
402-
},
423+
} | _PROTOC_ATTRS,
424+
fragments = _PROTOC_FRAGMENTS,
425+
toolchains = _PROTOC_TOOLCHAINS,
403426
)
404427

405428
def internal_objc_proto_library(

0 commit comments

Comments
 (0)