@@ -65,6 +65,9 @@ def _PyOuts(srcs, use_grpc_plugin = False):
6565def _RubyOuts (srcs ):
6666 return [s [:- len (".proto" )] + "_pb.rb" for s in srcs ]
6767
68+ def _RBSOuts (srcs ):
69+ return [s [:- len (".proto" )] + "_pb.rbs" for s in srcs ]
70+
6871def _CsharpOuts (srcs ):
6972 return [
7073 "" .join ([token .capitalize () for token in src [:- len (".proto" )].split ("_" )]) + ".cs"
@@ -158,6 +161,8 @@ def _proto_gen_impl(ctx):
158161 outs .extend (_PyOuts ([src .basename ], use_grpc_plugin = use_grpc_plugin ))
159162 elif lang == "ruby" :
160163 outs .extend (_RubyOuts ([src .basename ]))
164+ elif lang == "rbs" :
165+ outs .extend (_RBSOuts ([src .basename ]))
161166
162167 # Otherwise, rely on user-supplied outs.
163168 args .append (("--%s_out=" + path_tpl ) % (lang , gen_dir ))
@@ -526,8 +531,6 @@ def internal_ruby_proto_library(
526531
527532 """
528533
529- # Note: we need to run the protoc build twice to get separate targets for
530- # the generated header and the source files.
531534 _proto_gen (
532535 name = name + "_genproto" ,
533536 srcs = srcs ,
@@ -552,6 +555,58 @@ def internal_ruby_proto_library(
552555 ** kwargs
553556 )
554557
558+ def internal_rbs_proto_library (
559+ name ,
560+ ruby_library ,
561+ srcs = [],
562+ deps = [],
563+ includes = ["." ],
564+ protoc = "@com_google_protobuf//:protoc" ,
565+ testonly = None ,
566+ visibility = ["//visibility:public" ],
567+ ** kwargs ):
568+ """Bazel rule to create an RBS type definitions for the Ruby protobuf library
569+ from proto source files
570+
571+ NOTE: the rule is only an internal workaround to generate protos. The
572+ interface may change and the rule may be removed when bazel has introduced
573+ the native rule.
574+
575+ Args:
576+ name: the name of the ruby_proto_library.
577+ srcs: the .proto files to compile.
578+ deps: a list of dependency labels; must be a internal_rbs_proto_library.
579+ includes: a string indicating the include path of the .proto files.
580+ protoc: the label of the protocol compiler to generate the sources.
581+ testonly: common rule attribute (see:
582+ https://bazel.build/reference/be/common-definitions#common-attributes)
583+ visibility: the visibility of the generated files.
584+ **kwargs: other keyword arguments that are passed to ruby_library.
585+
586+ """
587+
588+ _proto_gen (
589+ name = name + "_genproto_rbs" ,
590+ srcs = srcs ,
591+ deps = [s + "_genproto_rbs" for s in deps ],
592+ langs = ["rbs" ],
593+ includes = includes ,
594+ protoc = protoc ,
595+ testonly = testonly ,
596+ visibility = visibility ,
597+ tags = ["manual" ],
598+ )
599+
600+ ruby_library (
601+ name = name ,
602+ srcs = [name + "_genproto_rbs" ],
603+ deps = [],
604+ testonly = testonly ,
605+ visibility = visibility ,
606+ includes = includes ,
607+ ** kwargs
608+ )
609+
555610# When canonical labels are in use, use additional "@" prefix
556611_canonical_label_prefix = "@" if str (Label ("//:protoc" )).startswith ("@@" ) else ""
557612
0 commit comments