1# Copyright 2024 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14"""Rule for generating a C++ RPC proto library using nanopb.""" 15 16load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "use_cpp_toolchain") 17load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo") 18load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") 19load("//pw_protobuf_compiler/private:proto.bzl", "compile_proto", "proto_compiler_aspect") 20 21def nanopb_rpc_proto_library(*, name, deps, nanopb_proto_library_deps, tags = [], **kwargs): 22 """A C++ RPC proto library using nanopb. 23 24 Attributes: 25 deps: proto_library targets for which to generate this library. 26 nanopb_proto_library_deps: A nanopb_proto_library generated 27 from the same proto_library. Required. 28 """ 29 30 # See comment in nanopb_proto_library. 31 extra_tags = ["manual"] 32 _pw_nanopb_rpc_proto_library( 33 name = name, 34 protos = deps, 35 # TODO: b/339280821 - This is required to avoid breaking internal 36 # Google builds but shouldn't matter for any external user. Remove this 37 # when possible. 38 features = ["-layering_check"], 39 deps = [ 40 Label("//pw_rpc"), 41 Label("//pw_rpc/nanopb:client_api"), 42 Label("//pw_rpc/nanopb:server_api"), 43 ] + nanopb_proto_library_deps, 44 tags = tags + extra_tags, 45 **kwargs 46 ) 47 48_pw_nanopb_rpc_proto_compiler_aspect = proto_compiler_aspect( 49 ["rpc.pb.h"], 50 "//pw_rpc/py:plugin_nanopb", 51 ["--no-legacy-namespace"], 52) 53 54_pw_nanopb_rpc_proto_library = rule( 55 implementation = compile_proto, 56 attrs = { 57 "deps": attr.label_list( 58 providers = [CcInfo], 59 ), 60 "protos": attr.label_list( 61 providers = [ProtoInfo], 62 aspects = [_pw_nanopb_rpc_proto_compiler_aspect], 63 ), 64 }, 65 fragments = ["cpp"], 66 toolchains = use_cpp_toolchain(), 67) 68