diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel index c70cebd..67ad840 100644 --- a/examples/MODULE.bazel +++ b/examples/MODULE.bazel @@ -7,6 +7,8 @@ bazel_dep(name = "platforms", version = "0.0.11") bazel_dep(name = "protobuf", version = "29.3") bazel_dep(name = "rules_java", version = "8.6.3") bazel_dep(name = "rules_proto", version = "7.1.0") +bazel_dep(name = "rules_proto_grpc", version = "5.0.1") +bazel_dep(name = "rules_proto_grpc_python", version = "5.0.1") bazel_dep(name = "rules_python", version = "1.2.0-rc0") bazel_dep(name = "rules_rust", version = "0.59.1") bazel_dep(name = "rules_rust_prost", version = "0.59.1") @@ -36,8 +38,6 @@ protoc.toolchain( ) use_repo(protoc, "com_google_protobuf", "toolchains_protoc_hub") -register_toolchains("@toolchains_protoc_hub//:all") - # NB: the `:all` here is critical, because `proto_lang_toolchain` expands into two targets: # - proto_lang_toolchain rule [name] # - toolchain rule [name]_toolchain @@ -47,6 +47,8 @@ register_toolchains("@toolchains_protoc_hub//:all") # Declared toolchains should be created with the 'toolchain' rule and should not have dependencies that themselves require toolchains. register_toolchains("//tools/toolchains:all") +register_toolchains("@toolchains_protoc_hub//:all") + ####### PYTHON ########## # Shows how a typical Python user fetches all the dependencies of their app, including the protobuf runtime dev_pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") diff --git a/examples/proto/BUILD.bazel b/examples/proto/BUILD.bazel index 88c206c..c4e53cb 100644 --- a/examples/proto/BUILD.bazel +++ b/examples/proto/BUILD.bazel @@ -3,6 +3,7 @@ load("@rules_go//proto:def.bzl", "go_proto_library") load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_rust_prost//:defs.bzl", "rust_prost_library") load("@protobuf//bazel:py_proto_library.bzl", "py_proto_library") +load("//python:python_grpc_library.bzl", "python_grpc_library") package(default_visibility = ["//visibility:public"]) @@ -17,6 +18,10 @@ py_proto_library( deps = [":greeter_proto"], ) +python_grpc_library( + name = "greeter_py_grpc", + protos = [":greeter_proto"], +) # Broken by https://github.com/protocolbuffers/protobuf/pull/19679 # which causes building C++ code from source. # TODO: re-enable once protobuf honors the toolchain diff --git a/examples/python/BUILD b/examples/python/BUILD index 34becda..e69de29 100644 --- a/examples/python/BUILD +++ b/examples/python/BUILD @@ -1,7 +0,0 @@ -load("@rules_python//python:defs.bzl", "py_test") - -py_test( - name = "message_test", - srcs = ["message_test.py"], - deps = ["//proto:greeter_py_proto"], -) diff --git a/examples/python/client/BUILD.bazel b/examples/python/client/BUILD.bazel new file mode 100644 index 0000000..dc5c34c --- /dev/null +++ b/examples/python/client/BUILD.bazel @@ -0,0 +1,12 @@ +load("@aspect_rules_py//py:defs.bzl", "py_binary") + +py_binary( + name = "client", + srcs = ["__main__.py"], + main = "__main__.py", + deps = [ + "//proto:greeter_py_grpc", + "@pypi//grpcio", + "@pypi//protobuf", + ], +) diff --git a/examples/python/client/__main__.py b/examples/python/client/__main__.py new file mode 100644 index 0000000..bd2b644 --- /dev/null +++ b/examples/python/client/__main__.py @@ -0,0 +1,36 @@ +import logging + +import grpc +from proto import greeter_pb2 +from proto.greeter_pb2_grpc import GreeterStub +from google.protobuf.any_pb2 import Any + + +def run(): + # Create a channel to connect to the server + with grpc.insecure_channel('[::1]:5042') as channel: + # Create a stub (client) + stub = GreeterStub(channel) + + # Create a detail message using Any + detail = Any() + detail.type_url = "type.googleapis.com/mypackage.MyMessage" + detail.value = b"details" + + # Create the request + request = greeter_pb2.HelloRequest( + name="Python Client", + details=[detail] + ) + + # Make the call + try: + response = stub.SayHello(request) + print(f"Response: {response.message}") + except grpc.RpcError as e: + print(f"RPC failed: {e}") + + +if __name__ == "__main__": + logging.basicConfig() + run() \ No newline at end of file diff --git a/examples/python/message_test.py b/examples/python/message_test.py deleted file mode 100644 index 2e03b51..0000000 --- a/examples/python/message_test.py +++ /dev/null @@ -1,15 +0,0 @@ -import sys -import unittest - -from proto import greeter_pb2 - -class TestCase(unittest.TestCase): - def test_message(self): - got = greeter_pb2.HelloReply( - message = "hello world", - ) - self.assertIsNotNone(got) - - -if __name__ == "__main__": - sys.exit(unittest.main()) diff --git a/examples/python/python_grpc_compile.bzl b/examples/python/python_grpc_compile.bzl new file mode 100644 index 0000000..fa129bb --- /dev/null +++ b/examples/python/python_grpc_compile.bzl @@ -0,0 +1,30 @@ +""" +Generated definition of python_grpc_compile. +Modified from https://github.com/rules-proto-grpc/rules_proto_grpc/blob/d17b5b16c8b12143c6f1b78dabd6bbc228e89b58/modules/python/python_grpc_compile.bzl +""" + +load( + "@rules_proto_grpc//:defs.bzl", + "ProtoPluginInfo", + "proto_compile_attrs", + "proto_compile_impl", + "proto_compile_toolchains", +) + +# Create compile rule +python_grpc_compile = rule( + implementation = proto_compile_impl, + attrs = dict( + proto_compile_attrs, + _plugins = attr.label_list( + providers = [ProtoPluginInfo], + default = [ + Label("//tools/toolchains:proto_plugin"), + Label("//tools/toolchains:grpc_plugin"), + ], + cfg = "exec", + doc = "List of protoc plugins to apply", + ), + ), + toolchains = proto_compile_toolchains, +) diff --git a/examples/python/python_grpc_library.bzl b/examples/python/python_grpc_library.bzl new file mode 100644 index 0000000..0e9071f --- /dev/null +++ b/examples/python/python_grpc_library.bzl @@ -0,0 +1,60 @@ +"""Generated definition of python_grpc_library.""" + +load("@rules_proto_grpc//:defs.bzl", "bazel_build_rule_common_attrs", "proto_compile_attrs") +load("@pypi//:requirements.bzl", "requirement") +load("@rules_python//python:defs.bzl", "py_library") +load(":python_grpc_compile.bzl", "python_grpc_compile") + +def python_grpc_library(name, generate_pyi = False, **kwargs): + """ + python_grpc_library generates Python code from proto and gRPC, and creates a py_library for them. + + Args: + name: the name of the target. + generate_pyi: flag to specify whether .pyi files should be created. + **kwargs: common Bazel attributes will be passed to both python_grpc_compile and py_library; + python_grpc_compile attributes will be passed to python_grpc_compile only. + """ + + # Compile protos + name_pb = name + "_pb" + python_grpc_compile( + name = name_pb, + **{ + k: v + for (k, v) in kwargs.items() + if k in proto_compile_attrs.keys() or + k in bazel_build_rule_common_attrs + } # Forward args + ) + + # For other code to import generated code with prefix_path if it's given + output_mode = kwargs.get("output_mode", "PREFIXED") + if output_mode == "PREFIXED": + imports = [name_pb] + else: + imports = ["."] + + # for pb2_grpc.py to import pb2.py + prefix_path = kwargs.get("prefix_path", None) + if prefix_path: + imports.append(imports[0] + "/" + prefix_path) + + # Create python library + py_library( + name = name, + srcs = [name_pb], + deps = GRPC_DEPS + kwargs.get("deps", []), + data = kwargs.get("data", []), # See https://github.com/rules-proto-grpc/rules_proto_grpc/issues/257 for use case + imports = imports, + **{ + k: v + for (k, v) in kwargs.items() + if k in bazel_build_rule_common_attrs + } # Forward Bazel common args + ) + +GRPC_DEPS = [ + Label(requirement("grpcio")), + Label(requirement("protobuf")), +] \ No newline at end of file diff --git a/examples/python/server/BUILD.bazel b/examples/python/server/BUILD.bazel new file mode 100644 index 0000000..9aeef32 --- /dev/null +++ b/examples/python/server/BUILD.bazel @@ -0,0 +1,11 @@ +load("@aspect_rules_py//py:defs.bzl", "py_binary") + +py_binary( + name = "server", + srcs = ["__main__.py"], + main = "__main__.py", + deps = [ + "//proto:greeter_py_grpc", + "@pypi//grpcio", + ], +) diff --git a/examples/python/server/__main__.py b/examples/python/server/__main__.py new file mode 100644 index 0000000..c709bb0 --- /dev/null +++ b/examples/python/server/__main__.py @@ -0,0 +1,21 @@ +from concurrent import futures +import logging + +import grpc +from proto import greeter_pb2 +from proto.greeter_pb2_grpc import GreeterServicer, add_GreeterServicer_to_server + +class Greeter(GreeterServicer): + def SayHello(self, request, context): + return greeter_pb2.HelloReply(message=f'Hello {request.name}, I am Python server') + +def serve(): + server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) + add_GreeterServicer_to_server(Greeter(), server) + server.add_insecure_port("[::1]:5042") + server.start() + server.wait_for_termination() + +if __name__ == "__main__": + logging.basicConfig() + serve() diff --git a/examples/rust/server/src/server.rs b/examples/rust/server/src/server.rs index 4984721..e5975ca 100644 --- a/examples/rust/server/src/server.rs +++ b/examples/rust/server/src/server.rs @@ -21,7 +21,7 @@ impl Greeter for MyGreeter { println!("Got a request from {:?}", request.remote_addr()); let reply = HelloReply { - message: format!("Hello {}!", request.into_inner().name), + message: format!("Hello {}, I am Rust server", request.into_inner().name), }; Ok(Response::new(reply)) } diff --git a/examples/tools/grpcio_tools/BUILD.bazel b/examples/tools/grpcio_tools/BUILD.bazel new file mode 100644 index 0000000..c0d1bb4 --- /dev/null +++ b/examples/tools/grpcio_tools/BUILD.bazel @@ -0,0 +1,11 @@ +load("@rules_python//python:defs.bzl", "py_binary") + +py_binary( + name = "protoc", + srcs = ["__main__.py"], + main = "__main__.py", + visibility = ["//visibility:public"], + deps = [ + "@pypi//grpcio_tools", + ], +) diff --git a/examples/tools/grpcio_tools/__main__.py b/examples/tools/grpcio_tools/__main__.py new file mode 100644 index 0000000..ed7824c --- /dev/null +++ b/examples/tools/grpcio_tools/__main__.py @@ -0,0 +1,3 @@ +import runpy + +runpy.run_module('grpc_tools.protoc', run_name='__main__') diff --git a/examples/tools/requirements.in b/examples/tools/requirements.in index 07c7637..313bb45 100644 --- a/examples/tools/requirements.in +++ b/examples/tools/requirements.in @@ -1 +1,3 @@ -protobuf==5.28.0 +protobuf==5.29.1 +grpcio +grpcio-tools diff --git a/examples/tools/requirements.txt b/examples/tools/requirements.txt index acd4713..a1bbf0e 100644 --- a/examples/tools/requirements.txt +++ b/examples/tools/requirements.txt @@ -2,16 +2,130 @@ # bazel run @@//tools:generate_requirements_txt --index-url https://pypi.org/simple -protobuf==5.28.0 \ - --hash=sha256:018db9056b9d75eb93d12a9d35120f97a84d9a919bcab11ed56ad2d399d6e8dd \ - --hash=sha256:510ed78cd0980f6d3218099e874714cdf0d8a95582e7b059b06cabad855ed0a0 \ - --hash=sha256:532627e8fdd825cf8767a2d2b94d77e874d5ddb0adefb04b237f7cc296748681 \ - --hash=sha256:6206afcb2d90181ae8722798dcb56dc76675ab67458ac24c0dd7d75d632ac9bd \ - --hash=sha256:66c3edeedb774a3508ae70d87b3a19786445fe9a068dd3585e0cefa8a77b83d0 \ - --hash=sha256:6d7cc9e60f976cf3e873acb9a40fed04afb5d224608ed5c1a105db4a3f09c5b6 \ - --hash=sha256:853db610214e77ee817ecf0514e0d1d052dff7f63a0c157aa6eabae98db8a8de \ - --hash=sha256:d001a73c8bc2bf5b5c1360d59dd7573744e163b3607fa92788b7f3d5fefbd9a5 \ - --hash=sha256:dde74af0fa774fa98892209992295adbfb91da3fa98c8f67a88afe8f5a349add \ - --hash=sha256:dde9fcaa24e7a9654f4baf2a55250b13a5ea701493d904c54069776b99a8216b \ - --hash=sha256:eef7a8a2f4318e2cb2dee8666d26e58eaf437c14788f3a2911d0c3da40405ae8 +grpcio==1.71.0 \ + --hash=sha256:0ab8b2864396663a5b0b0d6d79495657ae85fa37dcb6498a2669d067c65c11ea \ + --hash=sha256:0fa05ee31a20456b13ae49ad2e5d585265f71dd19fbd9ef983c28f926d45d0a7 \ + --hash=sha256:0ff35c8d807c1c7531d3002be03221ff9ae15712b53ab46e2a0b4bb271f38537 \ + --hash=sha256:1be857615e26a86d7363e8a163fade914595c81fec962b3d514a4b1e8760467b \ + --hash=sha256:20e8f653abd5ec606be69540f57289274c9ca503ed38388481e98fa396ed0b41 \ + --hash=sha256:22c3bc8d488c039a199f7a003a38cb7635db6656fa96437a8accde8322ce2366 \ + --hash=sha256:24e867651fc67717b6f896d5f0cac0ec863a8b5fb7d6441c2ab428f52c651c6b \ + --hash=sha256:2b85f7820475ad3edec209d3d89a7909ada16caab05d3f2e08a7e8ae3200a55c \ + --hash=sha256:39983a9245d37394fd59de71e88c4b295eb510a3555e0a847d9965088cdbd033 \ + --hash=sha256:3d081e859fb1ebe176de33fc3adb26c7d46b8812f906042705346b314bde32c3 \ + --hash=sha256:469f42a0b410883185eab4689060a20488a1a0a00f8bbb3cbc1061197b4c5a79 \ + --hash=sha256:47be9584729534660416f6d2a3108aaeac1122f6b5bdbf9fd823e11fe6fbaa29 \ + --hash=sha256:4be74ddeeb92cc87190e0e376dbc8fc7736dbb6d3d454f2fa1f5be1dee26b9d7 \ + --hash=sha256:4dd0dfbe4d5eb1fcfec9490ca13f82b089a309dc3678e2edabc144051270a66e \ + --hash=sha256:5b08d03ace7aca7b2fadd4baf291139b4a5f058805a8327bfe9aece7253b6d67 \ + --hash=sha256:63e41b91032f298b3e973b3fa4093cbbc620c875e2da7b93e249d4728b54559a \ + --hash=sha256:652350609332de6dac4ece254e5d7e1ff834e203d6afb769601f286886f6f3a8 \ + --hash=sha256:693bc706c031aeb848849b9d1c6b63ae6bcc64057984bb91a542332b75aa4c3d \ + --hash=sha256:74258dce215cb1995083daa17b379a1a5a87d275387b7ffe137f1d5131e2cfbb \ + --hash=sha256:789d5e2a3a15419374b7b45cd680b1e83bbc1e52b9086e49308e2c0b5bbae6e3 \ + --hash=sha256:7c9c80ac6091c916db81131d50926a93ab162a7e97e4428ffc186b6e80d6dda4 \ + --hash=sha256:7d6ac9481d9d0d129224f6d5934d5832c4b1cddb96b59e7eba8416868909786a \ + --hash=sha256:85da336e3649a3d2171e82f696b5cad2c6231fdd5bad52616476235681bee5b3 \ + --hash=sha256:8700a2a57771cc43ea295296330daaddc0d93c088f0a35cc969292b6db959bf3 \ + --hash=sha256:8997d6785e93308f277884ee6899ba63baafa0dfb4729748200fcc537858a509 \ + --hash=sha256:9182e0063112e55e74ee7584769ec5a0b4f18252c35787f48738627e23a62b97 \ + --hash=sha256:9b91879d6da1605811ebc60d21ab6a7e4bae6c35f6b63a061d61eb818c8168f6 \ + --hash=sha256:a2242d6950dc892afdf9e951ed7ff89473aaf744b7d5727ad56bdaace363722b \ + --hash=sha256:a371e6b6a5379d3692cc4ea1cb92754d2a47bdddeee755d3203d1f84ae08e03e \ + --hash=sha256:a76d39b5fafd79ed604c4be0a869ec3581a172a707e2a8d7a4858cb05a5a7637 \ + --hash=sha256:ad9f30838550695b5eb302add33f21f7301b882937460dd24f24b3cc5a95067a \ + --hash=sha256:b2266862c5ad664a380fbbcdbdb8289d71464c42a8c29053820ee78ba0119e5d \ + --hash=sha256:b78a99cd1ece4be92ab7c07765a0b038194ded2e0a26fd654591ee136088d8d7 \ + --hash=sha256:c200cb6f2393468142eb50ab19613229dcc7829b5ccee8b658a36005f6669fdd \ + --hash=sha256:c30f393f9d5ff00a71bb56de4aa75b8fe91b161aeb61d39528db6b768d7eac69 \ + --hash=sha256:c6a0a28450c16809f94e0b5bfe52cabff63e7e4b97b44123ebf77f448534d07d \ + --hash=sha256:cebc1b34ba40a312ab480ccdb396ff3c529377a2fce72c45a741f7215bfe8379 \ + --hash=sha256:d2c170247315f2d7e5798a22358e982ad6eeb68fa20cf7a820bb74c11f0736e7 \ + --hash=sha256:d35a95f05a8a2cbe8e02be137740138b3b2ea5f80bd004444e4f9a1ffc511e32 \ + --hash=sha256:d5170929109450a2c031cfe87d6716f2fae39695ad5335d9106ae88cc32dc84c \ + --hash=sha256:d6aa986318c36508dc1d5001a3ff169a15b99b9f96ef5e98e13522c506b37eef \ + --hash=sha256:d6de81c9c00c8a23047136b11794b3584cdc1460ed7cbc10eada50614baa1444 \ + --hash=sha256:dc1a1231ed23caac1de9f943d031f1bc38d0f69d2a3b243ea0d664fc1fbd7fec \ + --hash=sha256:e6beeea5566092c5e3c4896c6d1d307fb46b1d4bdf3e70c8340b190a69198594 \ + --hash=sha256:e6d8de076528f7c43a2f576bc311799f89d795aa6c9b637377cc2b1616473804 \ + --hash=sha256:e6f83a583ed0a5b08c5bc7a3fe860bb3c2eac1f03f1f63e0bc2091325605d2b7 \ + --hash=sha256:f250ff44843d9a0615e350c77f890082102a0318d66a99540f54769c8766ab73 \ + --hash=sha256:f71574afdf944e6652203cd1badcda195b2a27d9c83e6d88dc1ce3cfb73b31a5 \ + --hash=sha256:f903017db76bf9cc2b2d8bdd37bf04b505bbccad6be8a81e1542206875d0e9db \ + --hash=sha256:f9a412f55bb6e8f3bb000e020dbc1e709627dcb3a56f6431fa7076b4c1aab0db \ + --hash=sha256:f9c30c464cb2ddfbc2ddf9400287701270fdc0f14be5f08a1e3939f1e749b455 + # via + # -r tools/requirements.in + # grpcio-tools +grpcio-tools==1.71.0 \ + --hash=sha256:072b2a5805ac97e4623b3aa8f7818275f3fb087f4aa131b0fce00471065f6eaa \ + --hash=sha256:0ccfb837152b7b858b9f26bb110b3ae8c46675d56130f6c2f03605c4f129be13 \ + --hash=sha256:0e647794bd7138b8c215e86277a9711a95cf6a03ff6f9e555d54fdf7378b9f9d \ + --hash=sha256:1291a6136c07a86c3bb09f6c33f5cf227cc14956edd1b85cb572327a36e0aef8 \ + --hash=sha256:1331e726e08b7bdcbf2075fcf4b47dff07842b04845e6e220a08a4663e232d7f \ + --hash=sha256:145985c0bf12131f0a1503e65763e0f060473f7f3928ed1ff3fb0e8aad5bc8ac \ + --hash=sha256:192808cf553cedca73f0479cc61d5684ad61f24db7a5f3c4dfe1500342425866 \ + --hash=sha256:1f19b16b49afa5d21473f49c0966dd430c88d089cd52ac02404d8cef67134efb \ + --hash=sha256:28784f39921d061d2164a9dcda5164a69d07bf29f91f0ea50b505958292312c9 \ + --hash=sha256:2a1712f12102b60c8d92779b89d0504e0d6f3a59f2b933e5622b8583f5c02992 \ + --hash=sha256:3059c14035e5dc03d462f261e5900b9a077fd1a36976c3865b8507474520bad4 \ + --hash=sha256:38dba8e0d5e0fb23a034e09644fdc6ed862be2371887eee54901999e8f6792a8 \ + --hash=sha256:41878cb7a75477e62fdd45e7e9155b3af1b7a5332844021e2511deaf99ac9e6c \ + --hash=sha256:459c8f5e00e390aecd5b89de67deb3ec7188a274bc6cb50e43cef35ab3a3f45d \ + --hash=sha256:48debc879570972d28bfe98e4970eff25bb26da3f383e0e49829b2d2cd35ad87 \ + --hash=sha256:541a756276c8a55dec991f6c0106ae20c8c8f5ce8d0bdbfcb01e2338d1a8192b \ + --hash=sha256:56ecd6cc89b5e5eed1de5eb9cafce86c9c9043ee3840888cc464d16200290b53 \ + --hash=sha256:57e3e2544c306b60ef2d76570bac4e977be1ad548641c9eec130c3bc47e80141 \ + --hash=sha256:580ac88141c9815557e63c9c04f5b1cdb19b4db8d0cb792b573354bde1ee8b12 \ + --hash=sha256:61c0409d5bdac57a7bd0ce0ab01c1c916728fe4c8a03d77a25135ad481eb505c \ + --hash=sha256:64bdb291df61cf570b5256777ad5fe2b1db6d67bc46e55dc56a0a862722ae329 \ + --hash=sha256:65aa082f4435571d65d5ce07fc444f23c3eff4f3e34abef599ef8c9e1f6f360f \ + --hash=sha256:6693a7d3ba138b0e693b3d1f687cdd9db9e68976c3fa2b951c17a072fea8b583 \ + --hash=sha256:682e958b476049ccc14c71bedf3f979bced01f6e0c04852efc5887841a32ad6b \ + --hash=sha256:6ae5f2efa9e644c10bf1021600bfc099dfbd8e02b184d2d25dc31fcd6c2bc59e \ + --hash=sha256:6d11ed3ff7b6023b5c72a8654975324bb98c1092426ba5b481af406ff559df00 \ + --hash=sha256:753270e2d06d37e6d7af8967d1d059ec635ad215882041a36294f4e2fd502b2e \ + --hash=sha256:77fe6db1334e0ce318b2cb4e70afa94e0c173ed1a533d37aea69ad9f61ae8ea9 \ + --hash=sha256:82c430edd939bb863550ee0fecf067d78feff828908a1b529bbe33cc57f2419c \ + --hash=sha256:834959b6eceb85de5217a411aba1643b5f782798680c122202d6a06177226644 \ + --hash=sha256:83e90724e3f02415c628e4ead1d6ffe063820aaaa078d9a39176793df958cd5a \ + --hash=sha256:870c0097700d13c403e5517cb7750ab5b4a791ce3e71791c411a38c5468b64bd \ + --hash=sha256:8b93b9f6adc7491d4c10144c0643409db298e5e63c997106a804f6f0248dbaf4 \ + --hash=sha256:8dd9795e982d77a4b496f7278b943c2563d9afde2069cdee78c111a40cc4d675 \ + --hash=sha256:8e6cdbba4dae7b37b0d25d074614be9936fb720144420f03d9f142a80be69ba2 \ + --hash=sha256:8f987d0053351217954543b174b0bddbf51d45b3cfcf8d6de97b0a43d264d753 \ + --hash=sha256:989ee9da61098230d3d4c8f8f8e27c2de796f1ff21b1c90110e636d9acd9432b \ + --hash=sha256:9a78d07d6c301a25ef5ede962920a522556a1dfee1ccc05795994ceb867f766c \ + --hash=sha256:abd57f615e88bf93c3c6fd31f923106e3beb12f8cd2df95b0d256fa07a7a0a57 \ + --hash=sha256:af39e245fa56f7f5c2fe86b7d6c1b78f395c07e54d5613cbdbb3c24769a92b6e \ + --hash=sha256:bfe3888c3bbe16a5aa39409bc38744a31c0c3d2daa2b0095978c56e106c85b42 \ + --hash=sha256:c1b5860c41a36b26fec4f52998f1a451d0525a5c9a4fb06b6ea3e9211abdb925 \ + --hash=sha256:d3adc8b229e60c77bab5a5d62b415667133bd5ced7d59b5f71d6317c9143631e \ + --hash=sha256:e3ae9556e2a1cd70e7d7b0e0459c35af71d51a7dae4cf36075068011a69f13ec \ + --hash=sha256:e52a041afc20ab2431d756b6295d727bd7adee813b21b06a3483f4a7a15ea15f \ + --hash=sha256:edab7e6518de01196be37f96cb1e138c3819986bf5e2a6c9e1519b4d716b2f5a \ + --hash=sha256:f360981b215b1d5aff9235b37e7e1826246e35bbac32a53e41d4e990a37b8f4c \ + --hash=sha256:f4ad7f0d756546902597053d70b3af2606fbd70d7972876cd75c1e241d22ae00 \ + --hash=sha256:f68334d28a267fabec6e70cb5986e9999cfbfd14db654094ddf9aedd804a293a \ + --hash=sha256:f7c678e68ece0ae908ecae1c4314a0c2c7f83e26e281738b9609860cc2c82d96 \ + --hash=sha256:ffff9bc5eacb34dd26b487194f7d44a3e64e752fc2cf049d798021bf25053b87 # via -r tools/requirements.in +protobuf==5.29.1 \ + --hash=sha256:012ce28d862ff417fd629285aca5d9772807f15ceb1a0dbd15b88f58c776c98c \ + --hash=sha256:027fbcc48cea65a6b17028510fdd054147057fa78f4772eb547b9274e5219331 \ + --hash=sha256:1fc55267f086dd4050d18ef839d7bd69300d0d08c2a53ca7df3920cc271a3c34 \ + --hash=sha256:22c1f539024241ee545cbcb00ee160ad1877975690b16656ff87dde107b5f110 \ + --hash=sha256:32600ddb9c2a53dedc25b8581ea0f1fd8ea04956373c0c07577ce58d312522e0 \ + --hash=sha256:50879eb0eb1246e3a5eabbbe566b44b10348939b7cc1b267567e8c3d07213853 \ + --hash=sha256:5a41deccfa5e745cef5c65a560c76ec0ed8e70908a67cc8f4da5fce588b50d57 \ + --hash=sha256:683be02ca21a6ffe80db6dd02c0b5b2892322c59ca57fd6c872d652cb80549cb \ + --hash=sha256:8ee1461b3af56145aca2800e6a3e2f928108c749ba8feccc6f5dd0062c410c0d \ + --hash=sha256:b5ba1d0e4c8a40ae0496d0e2ecfdbb82e1776928a205106d14ad6985a09ec155 \ + --hash=sha256:d473655e29c0c4bbf8b69e9a8fb54645bc289dead6d753b952e7aa660254ae18 + # via + # -r tools/requirements.in + # grpcio-tools +setuptools==76.1.0 \ + --hash=sha256:34750dcb17d046929f545dec9b8349fe42bf4ba13ddffee78428aec422dbfb73 \ + --hash=sha256:4959b9ad482ada2ba2320c8f1a8d8481d4d8d668908a7a1b84d987375cd7f5bd + # via grpcio-tools diff --git a/examples/tools/toolchains/BUILD.bazel b/examples/tools/toolchains/BUILD.bazel index ccb0c72..7d6074a 100644 --- a/examples/tools/toolchains/BUILD.bazel +++ b/examples/tools/toolchains/BUILD.bazel @@ -1,5 +1,7 @@ load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain") load("@rules_rust_prost//:defs.bzl", "rust_prost_toolchain") +load("@rules_proto//proto:proto_toolchain.bzl", "proto_toolchain") +load("@rules_proto_grpc//:defs.bzl", "proto_plugin") # Configure protoc to have the right arguments for generating Python stubs. # NB: the protobuf team intends to remove --python_out and instead use a protoc plugin for Python stub emit. @@ -34,3 +36,36 @@ toolchain( toolchain = "prost_toolchain_impl", toolchain_type = "@rules_rust_prost//:toolchain_type", ) + +proto_plugin( + name = "proto_plugin", + exclusions = [ + "google/protobuf", + ], + outputs = ["{protopath|python}_pb2.py"], + protoc_plugin_name = "python", + visibility = ["//visibility:public"], +) + +proto_plugin( + name = "grpc_plugin", + exclusions = [ + "google/protobuf", + ], + outputs = ["{protopath|python_grpc}_pb2_grpc.py"], + protoc_plugin_name = "grpc_python", + visibility = ["//visibility:public"], +) + +proto_toolchain( + name = "prebuilt_protoc_toolchain_with_grpc_plugin", + proto_compiler = "//tools/grpcio_tools:protoc", +) + +# https://github.com/aspect-build/toolchains_protoc/blob/e6ce32673fce191c6a0dd4a7752d0fcce73788f7/protoc/private/protoc_toolchains.bzl#L42 +toolchain( + name = "prebuilt_protoc_toolchain_with_grpc_plugin_proto_toolchain", + # Note _toolchain suffix + toolchain = ":prebuilt_protoc_toolchain_with_grpc_plugin", + toolchain_type = "@rules_proto//proto:toolchain_type", +)