| 
 | 1 | +From d2e4671e04bd72211d15183f891707c4ff2f11cd Mon Sep 17 00:00:00 2001  | 
 | 2 | +From: Fabian Meumertzheim < [email protected]>  | 
 | 3 | +Date: Mon, 16 Dec 2024 22:20:13 +0100  | 
 | 4 | +Subject: [PATCH 2/2] Switch to toolchains  | 
 | 5 | + | 
 | 6 | +---  | 
 | 7 | + bazel/private/BUILD |  6 ------  | 
 | 8 | + protobuf.bzl        | 41 ++++++++++++++++++++++++++++++-----------  | 
 | 9 | + 2 files changed, 30 insertions(+), 17 deletions(-)  | 
 | 10 | + | 
 | 11 | +diff --git a/bazel/private/BUILD b/bazel/private/BUILD  | 
 | 12 | +index a5b3abeda..8c1c94ac8 100644  | 
 | 13 | +--- a/bazel/private/BUILD  | 
 | 14 | ++++ b/bazel/private/BUILD  | 
 | 15 | +@@ -1,5 +1,4 @@  | 
 | 16 | + load("@bazel_skylib//:bzl_library.bzl", "bzl_library")  | 
 | 17 | +-load(":current_protoc.bzl", "current_protoc")  | 
 | 18 | + load(":native_bool_flag.bzl", "native_bool_flag")  | 
 | 19 | +   | 
 | 20 | + package(default_applicable_licenses = ["//:license"])  | 
 | 21 | +@@ -29,11 +28,6 @@ toolchain_type(  | 
 | 22 | +     visibility = ["//visibility:public"],  | 
 | 23 | + )  | 
 | 24 | +   | 
 | 25 | +-current_protoc(  | 
 | 26 | +-    name = "current_protoc",  | 
 | 27 | +-    visibility = ["//:__subpackages__"],  | 
 | 28 | +-)  | 
 | 29 | +-  | 
 | 30 | + bzl_library(  | 
 | 31 | +     name = "upb_proto_library_internal_bzl",  | 
 | 32 | +     srcs = [  | 
 | 33 | +diff --git a/protobuf.bzl b/protobuf.bzl  | 
 | 34 | +index 736cc19cf..acb190942 100644  | 
 | 35 | +--- a/protobuf.bzl  | 
 | 36 | ++++ b/protobuf.bzl  | 
 | 37 | +@@ -1,8 +1,9 @@  | 
 | 38 | + load("@bazel_skylib//lib:versions.bzl", "versions")  | 
 | 39 | + load("@rules_cc//cc:defs.bzl", "objc_library")  | 
 | 40 | + load("@rules_python//python:defs.bzl", "py_library")  | 
 | 41 | ++load("//bazel/common:proto_common.bzl", "proto_common")  | 
 | 42 | + load("//bazel/common:proto_info.bzl", "ProtoInfo")  | 
 | 43 | +-load("//bazel/private:current_protoc.bzl", "ProtocFilesToRun")  | 
 | 44 | ++load("//bazel/private:toolchain_helpers.bzl", "toolchains")  | 
 | 45 | +   | 
 | 46 | + def _GetPath(ctx, path):  | 
 | 47 | +     if ctx.label.workspace_root:  | 
 | 48 | +@@ -72,6 +73,26 @@ def _CsharpOuts(srcs):  | 
 | 49 | +         for src in srcs  | 
 | 50 | +     ]  | 
 | 51 | +   | 
 | 52 | ++_PROTOC_ATTRS = toolchains.if_legacy_toolchain({  | 
 | 53 | ++    "_proto_compiler": attr.label(  | 
 | 54 | ++        cfg = "exec",  | 
 | 55 | ++        executable = True,  | 
 | 56 | ++        allow_files = True,  | 
 | 57 | ++        default = configuration_field("proto", "proto_compiler"),  | 
 | 58 | ++    ),  | 
 | 59 | ++})  | 
 | 60 | ++_PROTOC_FRAGMENTS = ["proto"]  | 
 | 61 | ++_PROTOC_TOOLCHAINS = toolchains.use_toolchain(toolchains.PROTO_TOOLCHAIN)  | 
 | 62 | ++  | 
 | 63 | ++def _protoc_files_to_run(ctx):  | 
 | 64 | ++    if proto_common.INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION:  | 
 | 65 | ++        toolchain = ctx.toolchains[toolchains.PROTO_TOOLCHAIN]  | 
 | 66 | ++        if not toolchain:  | 
 | 67 | ++            fail("Protocol compiler toolchain could not be resolved.")  | 
 | 68 | ++        return toolchain.proto.proto_compiler  | 
 | 69 | ++    else:  | 
 | 70 | ++        return ctx.attr._proto_compiler[DefaultInfo].files_to_run  | 
 | 71 | ++  | 
 | 72 | + ProtoGenInfo = provider(  | 
 | 73 | +     fields = ["srcs", "import_flags", "deps"],  | 
 | 74 | + )  | 
 | 75 | +@@ -311,7 +332,7 @@ def _internal_gen_well_known_protos_java_impl(ctx):  | 
 | 76 | +             args.add_all([src.path[offset:] for src in dep.direct_sources])  | 
 | 77 | +   | 
 | 78 | +     ctx.actions.run(  | 
 | 79 | +-        executable = ctx.attr._protoc[ProtocFilesToRun].files_to_run,  | 
 | 80 | ++        executable = _protoc_files_to_run(ctx),  | 
 | 81 | +         inputs = descriptors,  | 
 | 82 | +         outputs = [srcjar],  | 
 | 83 | +         arguments = [args],  | 
 | 84 | +@@ -335,10 +356,9 @@ internal_gen_well_known_protos_java = rule(  | 
 | 85 | +         "javalite": attr.bool(  | 
 | 86 | +             default = False,  | 
 | 87 | +         ),  | 
 | 88 | +-        "_protoc": attr.label(  | 
 | 89 | +-            default = "//bazel/private:current_protoc",  | 
 | 90 | +-        ),  | 
 | 91 | +-    },  | 
 | 92 | ++    } | _PROTOC_ATTRS,  | 
 | 93 | ++    fragments = _PROTOC_FRAGMENTS,  | 
 | 94 | ++    toolchains = _PROTOC_TOOLCHAINS,  | 
 | 95 | + )  | 
 | 96 | +   | 
 | 97 | + def _internal_gen_kt_protos(ctx):  | 
 | 98 | +@@ -372,7 +392,7 @@ def _internal_gen_kt_protos(ctx):  | 
 | 99 | +             args.add_all([src.path[offset:] for src in dep.direct_sources])  | 
 | 100 | +   | 
 | 101 | +     ctx.actions.run(  | 
 | 102 | +-        executable = ctx.attr._protoc[ProtocFilesToRun].files_to_run,  | 
 | 103 | ++        executable = _protoc_files_to_run(ctx),  | 
 | 104 | +         inputs = descriptors,  | 
 | 105 | +         outputs = [srcjar],  | 
 | 106 | +         arguments = [args],  | 
 | 107 | +@@ -396,10 +416,9 @@ internal_gen_kt_protos = rule(  | 
 | 108 | +         "lite": attr.bool(  | 
 | 109 | +             default = False,  | 
 | 110 | +         ),  | 
 | 111 | +-        "_protoc": attr.label(  | 
 | 112 | +-            default = "//bazel/private:current_protoc",  | 
 | 113 | +-        ),  | 
 | 114 | +-    },  | 
 | 115 | ++    } | _PROTOC_ATTRS,  | 
 | 116 | ++    fragments = _PROTOC_FRAGMENTS,  | 
 | 117 | ++    toolchains = _PROTOC_TOOLCHAINS,  | 
 | 118 | + )  | 
 | 119 | +   | 
 | 120 | + def internal_objc_proto_library(  | 
 | 121 | +--   | 
 | 122 | +2.49.0  | 
 | 123 | + | 
0 commit comments