From de6972c8e035cb71208485c7b4efe6a87ccbaae4 Mon Sep 17 00:00:00 2001 From: Google APIs Date: Fri, 7 Feb 2025 10:25:45 -0800 Subject: [PATCH] feat: Add `upb_c_proto_library` rules for some well known protobuf types These are not for general consumption. They are specifically for projects which have an agreement with protobuf on directly accessing upb. Any other usage is unsupported and may be broken at anytime without warning. PiperOrigin-RevId: 724391383 --- google/rpc/BUILD.bazel | 52 +++++++++++++++++++----------------------- repository_rules.bzl | 10 ++++++++ 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/google/rpc/BUILD.bazel b/google/rpc/BUILD.bazel index 304538b8c5..edaed6f193 100644 --- a/google/rpc/BUILD.bazel +++ b/google/rpc/BUILD.bazel @@ -1,3 +1,15 @@ +############################################################################## +# Java +############################################################################## +load( + "@com_google_googleapis_imports//:imports.bzl", + "cc_proto_library", + "go_proto_library", + "java_gapic_assembly_gradle_pkg", + "java_proto_library", + "py_proto_library", + "upb_c_proto_library", +) load("@rules_proto//proto:defs.bzl", "proto_library") # This is an API workspace, having public visibility by default makes perfect sense. @@ -28,13 +40,6 @@ proto_library( ], ) -############################################################################## -# Java -############################################################################## -load("@com_google_googleapis_imports//:imports.bzl", - "java_gapic_assembly_gradle_pkg", - "java_proto_library") - java_proto_library( name = "rpc_java_proto", deps = [ @@ -50,19 +55,13 @@ java_proto_library( java_gapic_assembly_gradle_pkg( name = "google-rpc-java", deps = [ - ":rpc_java_proto", - ":code_proto", "error_details_proto", - "status_proto" + "status_proto", + ":code_proto", + ":rpc_java_proto", ], ) - -############################################################################## -# Go -############################################################################## -load("@com_google_googleapis_imports//:imports.bzl", "go_proto_library") - go_proto_library( name = "code_go_proto", importpath = "google.golang.org/genproto/googleapis/rpc/code", @@ -81,14 +80,6 @@ go_proto_library( protos = [":status_proto"], ) -############################################################################## -# C++ -############################################################################## -load( - "@com_google_googleapis_imports//:imports.bzl", - "cc_proto_library", -) - cc_proto_library( name = "code_cc_proto", deps = [":code_proto"], @@ -104,10 +95,15 @@ cc_proto_library( deps = [":status_proto"], ) -############################################################################## -# Python -############################################################################## -load("@com_google_googleapis_imports//:imports.bzl", "py_proto_library") +upb_c_proto_library( + name = "code_upb_proto", + deps = [":code_proto"], +) + +upb_c_proto_library( + name = "status_upb_proto", + deps = [":status_proto"], +) py_proto_library( name = "code_py_proto", diff --git a/repository_rules.bzl b/repository_rules.bzl index 9c6643b789..2f87ad682f 100644 --- a/repository_rules.bzl +++ b/repository_rules.bzl @@ -66,6 +66,7 @@ def switched_rules_by_language( ruby = False, csharp = False, go_test = False, + upb = False, rules_override = {}): """Switches rules in the generated imports.bzl between no-op and the actual implementation. @@ -220,6 +221,15 @@ def switched_rules_by_language( ) rules["cc_gapic_library"] = _switch(False) + # + # upb + # + rules["upb_c_proto_library"] = _switch( + upb, + "@com_google_protobuf//bazel:upb_c_proto_library.bzl", + "upb_c_proto_library", + ) + # # PHP #