• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2022 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"""Old home of proto compilation rules.
15
16This file is DEPRECATED. Prefer to load the specific rules you need from the
17other .bzl files in this directory.
18"""
19
20load("//pw_protobuf_compiler:nanopb_proto_library.bzl", _nanopb_proto_library = "nanopb_proto_library")
21load("//pw_protobuf_compiler:nanopb_rpc_proto_library.bzl", _nanopb_rpc_proto_library = "nanopb_rpc_proto_library")
22load("//pw_protobuf_compiler:pw_proto_filegroup.bzl", _pw_proto_filegroup = "pw_proto_filegroup")
23load("//pw_protobuf_compiler:pwpb_proto_library.bzl", _pwpb_proto_library = "pwpb_proto_library")
24load("//pw_protobuf_compiler:pwpb_rpc_proto_library.bzl", _pwpb_rpc_proto_library = "pwpb_rpc_proto_library")
25load("//pw_protobuf_compiler:raw_rpc_proto_library.bzl", _raw_rpc_proto_library = "raw_rpc_proto_library")
26
27# These rules are re-exported here for backwards compatibility, but in new code
28# prefer loading them directly from the corresponding bzl file.
29pw_proto_filegroup = _pw_proto_filegroup
30pwpb_proto_library = _pwpb_proto_library
31pwpb_rpc_proto_library = _pwpb_rpc_proto_library
32raw_rpc_proto_library = _raw_rpc_proto_library
33nanopb_proto_library = _nanopb_proto_library
34nanopb_rpc_proto_library = _nanopb_rpc_proto_library
35
36def pw_proto_library(
37        *,
38        name,
39        deps,
40        enabled_targets = None,
41        **kwargs):
42    """Generate Pigweed proto C++ code.
43
44    DEPRECATED. This macro is deprecated and will be removed in a future
45    Pigweed version. Please use the single-target macros above.
46
47    Args:
48      name: The name of the target.
49      deps: proto_library targets from which to generate Pigweed C++.
50      enabled_targets: Specifies which libraries should be generated. Libraries
51        will only be generated as needed, but unnecessary outputs may conflict
52        with other build rules and thus cause build failures. This filter allows
53        manual selection of which libraries should be supported by this build
54        target in order to prevent such conflicts. The argument, if provided,
55        should be a subset of ["pwpb", "nanopb", "raw_rpc", "nanopb_rpc"]. All
56        are enabled by default. Note that "nanopb_rpc" relies on "nanopb".
57      **kwargs: Passed on to all proto generation rules.
58
59    Example usage:
60
61      proto_library(
62        name = "benchmark_proto",
63        srcs = [
64          "benchmark.proto",
65        ],
66      )
67
68      pw_proto_library(
69        name = "benchmark_pw_proto",
70        deps = [":benchmark_proto"],
71      )
72
73      pw_cc_binary(
74        name = "proto_user",
75        srcs = ["proto_user.cc"],
76        deps = [":benchmark_pw_proto.pwpb"],
77      )
78
79    The pw_proto_library generates the following targets in this example:
80
81    "benchmark_pw_proto.pwpb": C++ library exposing the "benchmark.pwpb.h" header.
82    "benchmark_pw_proto.pwpb_rpc": C++ library exposing the
83        "benchmark.rpc.pwpb.h" header.
84    "benchmark_pw_proto.raw_rpc": C++ library exposing the "benchmark.raw_rpc.h"
85        header.
86    "benchmark_pw_proto.nanopb": C++ library exposing the "benchmark.pb.h"
87        header.
88    "benchmark_pw_proto.nanopb_rpc": C++ library exposing the
89        "benchmark.rpc.pb.h" header.
90    """
91
92    def is_plugin_enabled(plugin):
93        return (enabled_targets == None or plugin in enabled_targets)
94
95    if is_plugin_enabled("nanopb"):
96        # Use nanopb to generate the pb.h and pb.c files, and the target
97        # exposing them.
98        nanopb_proto_library(
99            name = name + ".nanopb",
100            deps = deps,
101            **kwargs
102        )
103
104    if is_plugin_enabled("pwpb"):
105        pwpb_proto_library(
106            name = name + ".pwpb",
107            deps = deps,
108            **kwargs
109        )
110
111    if is_plugin_enabled("pwpb_rpc"):
112        pwpb_rpc_proto_library(
113            name = name + ".pwpb_rpc",
114            deps = deps,
115            pwpb_proto_library_deps = [":" + name + ".pwpb"],
116            **kwargs
117        )
118
119    if is_plugin_enabled("raw_rpc"):
120        raw_rpc_proto_library(
121            name = name + ".raw_rpc",
122            deps = deps,
123            **kwargs
124        )
125
126    if is_plugin_enabled("nanopb_rpc"):
127        nanopb_rpc_proto_library(
128            name = name + ".nanopb_rpc",
129            deps = deps,
130            nanopb_proto_library_deps = [":" + name + ".nanopb"],
131            **kwargs
132        )
133