• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 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
15load("@rules_proto//proto:defs.bzl", "proto_library")
16load(
17    "//pw_build:pigweed.bzl",
18    "pw_cc_library",
19    "pw_cc_test",
20)
21load("//pw_fuzzer:fuzzer.bzl", "pw_cc_fuzz_test")
22load("@rules_proto_grpc//:defs.bzl", "proto_plugin")
23load("//pw_protobuf_compiler:proto.bzl", "pw_proto_library")
24
25package(default_visibility = ["//visibility:public"])
26
27licenses(["notice"])
28
29pw_cc_library(
30    name = "config",
31    hdrs = ["public/pw_protobuf/config.h"],
32    includes = ["public"],
33)
34
35pw_cc_library(
36    name = "pw_protobuf",
37    srcs = [
38        "decoder.cc",
39        "encoder.cc",
40        "find.cc",
41        "map_utils.cc",
42        "message.cc",
43        "stream_decoder.cc",
44    ],
45    hdrs = [
46        "public/pw_protobuf/decoder.h",
47        "public/pw_protobuf/encoder.h",
48        "public/pw_protobuf/find.h",
49        "public/pw_protobuf/internal/proto_integer_base.h",
50        "public/pw_protobuf/map_utils.h",
51        "public/pw_protobuf/message.h",
52        "public/pw_protobuf/serialized_size.h",
53        "public/pw_protobuf/stream_decoder.h",
54        "public/pw_protobuf/wire_format.h",
55    ],
56    includes = ["public"],
57    deps = [
58        ":config",
59        "//pw_assert",
60        "//pw_bytes",
61        "//pw_containers:vector",
62        "//pw_polyfill:bit",
63        "//pw_polyfill:overrides",
64        "//pw_result",
65        "//pw_span",
66        "//pw_status",
67        "//pw_stream",
68        "//pw_stream:interval_reader",
69        "//pw_varint",
70        "//pw_varint:stream",
71    ],
72)
73
74pw_cc_library(
75    name = "bytes_utils",
76    hdrs = ["public/pw_protobuf/bytes_utils.h"],
77    includes = ["public"],
78    deps = [
79        ":pw_protobuf",
80        "//pw_bytes",
81        "//pw_result",
82        "//pw_status",
83    ],
84)
85
86pw_cc_test(
87    name = "decoder_test",
88    srcs = ["decoder_test.cc"],
89    deps = [
90        ":pw_protobuf",
91        "//pw_preprocessor",
92        "//pw_unit_test",
93    ],
94)
95
96pw_cc_test(
97    name = "encoder_test",
98    srcs = ["encoder_test.cc"],
99    deps = [
100        ":pw_protobuf",
101        "//pw_unit_test",
102    ],
103)
104
105pw_cc_fuzz_test(
106    name = "encoder_fuzz_test",
107    srcs = ["encoder_fuzzer.cc"],
108    deps = [
109        "//pw_fuzzer",
110        "//pw_protobuf",
111        "//pw_span",
112    ],
113)
114
115pw_cc_test(
116    name = "find_test",
117    srcs = ["find_test.cc"],
118    deps = [
119        ":pw_protobuf",
120        "//pw_unit_test",
121    ],
122)
123
124pw_cc_test(
125    name = "serialized_size_test",
126    srcs = ["serialized_size_test.cc"],
127    deps = [
128        ":pw_protobuf",
129        "//pw_unit_test",
130    ],
131)
132
133pw_cc_test(
134    name = "stream_decoder_test",
135    srcs = ["stream_decoder_test.cc"],
136    deps = [
137        ":pw_protobuf",
138        "//pw_unit_test",
139    ],
140)
141
142pw_cc_test(
143    name = "map_utils_test",
144    srcs = ["map_utils_test.cc"],
145    deps = [
146        ":pw_protobuf",
147        "//pw_unit_test",
148    ],
149)
150
151pw_cc_test(
152    name = "message_test",
153    srcs = ["message_test.cc"],
154    deps = [
155        ":pw_protobuf",
156        "//pw_unit_test",
157    ],
158)
159
160proto_library(
161    name = "common_protos",
162    srcs = [
163        "pw_protobuf_protos/common.proto",
164        "pw_protobuf_protos/status.proto",
165    ],
166    strip_import_prefix = "//pw_protobuf",
167)
168
169proto_library(
170    name = "codegen_test_proto",
171    srcs = [
172        "pw_protobuf_test_protos/full_test.proto",
173        "pw_protobuf_test_protos/imported.proto",
174        "pw_protobuf_test_protos/importer.proto",
175        "pw_protobuf_test_protos/non_pw_package.proto",
176        "pw_protobuf_test_protos/proto2.proto",
177        "pw_protobuf_test_protos/repeated.proto",
178    ],
179    strip_import_prefix = "//pw_protobuf",
180    deps = [":common_protos"],
181)
182
183pw_proto_library(
184    name = "codegen_test_proto_cc",
185    deps = [
186        ":codegen_test_proto",
187        ":common_protos",
188    ],
189)
190
191pw_cc_test(
192    name = "codegen_decoder_test",
193    srcs = [
194        "codegen_decoder_test.cc",
195    ],
196    deps = [
197        ":codegen_test_proto_cc.pwpb",
198        ":pw_protobuf",
199        "//pw_span",
200        "//pw_unit_test",
201    ],
202)
203
204pw_cc_test(
205    name = "codegen_encoder_test",
206    srcs = [
207        "codegen_encoder_test.cc",
208    ],
209    deps = [
210        ":codegen_test_proto_cc.pwpb",
211        ":pw_protobuf",
212        "//pw_span",
213        "//pw_unit_test",
214    ],
215)
216
217# TODO(frolv): Figure out how to add facade tests to Bazel.
218filegroup(
219    name = "varint_size_test",
220    srcs = [
221        "varint_size_test.cc",
222    ],
223)
224
225# TODO(frolv): Figure out what to do about size reports in Bazel.
226filegroup(
227    name = "size_reports",
228    srcs = glob([
229        "size_report/*.cc",
230    ]),
231)
232
233proto_plugin(
234    name = "pw_cc_plugin",
235    outputs = [
236        "{protopath}.pwpb.h",
237    ],
238    protoc_plugin_name = "pwpb",
239    tool = "@pigweed//pw_protobuf/py:plugin",
240    use_built_in_shell_environment = True,
241    visibility = ["//visibility:public"],
242)
243