• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 C++ proto RPC libraries using pw_protobuf."""
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 pwpb_rpc_proto_library(*, name, deps, pwpb_proto_library_deps, **kwargs):
22    """A pwpb_rpc proto library target.
23
24    Attributes:
25      deps: proto_library targets for which to generate this library.
26      pwpb_proto_library_deps: A pwpb_proto_library generated
27        from the same proto_library. Required.
28    """
29    _pw_pwpb_rpc_proto_library(
30        name = name,
31        protos = deps,
32        deps = [
33            Label("//pw_protobuf"),
34            Label("//pw_rpc"),
35            Label("//pw_rpc/pwpb:client_api"),
36            Label("//pw_rpc/pwpb:server_api"),
37        ] + pwpb_proto_library_deps,
38        **kwargs
39    )
40
41_pw_pwpb_rpc_proto_compiler_aspect = proto_compiler_aspect(
42    ["rpc.pwpb.h"],
43    "//pw_rpc/py:plugin_pwpb",
44    ["--no-legacy-namespace"],
45)
46
47_pw_pwpb_rpc_proto_library = rule(
48    implementation = compile_proto,
49    attrs = {
50        "deps": attr.label_list(
51            providers = [CcInfo],
52        ),
53        "protos": attr.label_list(
54            providers = [ProtoInfo],
55            aspects = [_pw_pwpb_rpc_proto_compiler_aspect],
56        ),
57    },
58    fragments = ["cpp"],
59    toolchains = use_cpp_toolchain(),
60)
61