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