• 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
15load("@rules_proto//proto:defs.bzl", "proto_library")
16load(
17    "//pw_build:pigweed.bzl",
18    "pw_cc_library",
19    "pw_cc_perf_test",
20    "pw_cc_test",
21)
22load("//pw_fuzzer:fuzzer.bzl", "pw_cc_fuzz_test")
23load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")
24load("@rules_proto_grpc//:defs.bzl", "proto_plugin")
25load("//pw_protobuf_compiler:proto.bzl", "pw_proto_library")
26
27package(default_visibility = ["//visibility:public"])
28
29licenses(["notice"])
30
31pw_cc_library(
32    name = "config",
33    hdrs = ["public/pw_protobuf/config.h"],
34    includes = ["public"],
35)
36
37pw_cc_library(
38    name = "pw_protobuf",
39    srcs = [
40        "decoder.cc",
41        "encoder.cc",
42        "find.cc",
43        "map_utils.cc",
44        "message.cc",
45        "stream_decoder.cc",
46    ],
47    hdrs = [
48        "public/pw_protobuf/decoder.h",
49        "public/pw_protobuf/encoder.h",
50        "public/pw_protobuf/find.h",
51        "public/pw_protobuf/internal/codegen.h",
52        "public/pw_protobuf/internal/proto_integer_base.h",
53        "public/pw_protobuf/map_utils.h",
54        "public/pw_protobuf/message.h",
55        "public/pw_protobuf/serialized_size.h",
56        "public/pw_protobuf/stream_decoder.h",
57        "public/pw_protobuf/wire_format.h",
58    ],
59    includes = ["public"],
60    deps = [
61        ":config",
62        "//pw_assert",
63        "//pw_bytes",
64        "//pw_bytes:bit",
65        "//pw_containers:vector",
66        "//pw_function",
67        "//pw_preprocessor",
68        "//pw_result",
69        "//pw_span",
70        "//pw_status",
71        "//pw_stream",
72        "//pw_stream:interval_reader",
73        "//pw_string:string",
74        "//pw_varint",
75        "//pw_varint:stream",
76    ],
77)
78
79pw_cc_library(
80    name = "bytes_utils",
81    hdrs = ["public/pw_protobuf/bytes_utils.h"],
82    includes = ["public"],
83    deps = [
84        ":pw_protobuf",
85        "//pw_bytes",
86        "//pw_result",
87        "//pw_status",
88    ],
89)
90
91pw_cc_test(
92    name = "decoder_test",
93    srcs = ["decoder_test.cc"],
94    deps = [
95        ":pw_protobuf",
96        "//pw_preprocessor",
97        "//pw_unit_test",
98    ],
99)
100
101pw_cc_test(
102    name = "encoder_test",
103    srcs = ["encoder_test.cc"],
104    deps = [
105        ":pw_protobuf",
106        "//pw_unit_test",
107    ],
108)
109
110pw_cc_fuzz_test(
111    name = "encoder_fuzz_test",
112    srcs = [
113        "encoder_fuzzer.cc",
114        "fuzz.h",
115    ],
116    deps = [
117        "//pw_fuzzer",
118        "//pw_protobuf",
119        "//pw_span",
120    ],
121)
122
123pw_cc_fuzz_test(
124    name = "decoder_fuzz_test",
125    srcs = [
126        "decoder_fuzzer.cc",
127        "fuzz.h",
128    ],
129    deps = [
130        "//pw_fuzzer",
131        "//pw_protobuf",
132        "//pw_span",
133    ],
134)
135
136pw_cc_test(
137    name = "find_test",
138    srcs = ["find_test.cc"],
139    deps = [
140        ":pw_protobuf",
141        "//pw_unit_test",
142    ],
143)
144
145pw_cc_test(
146    name = "serialized_size_test",
147    srcs = ["serialized_size_test.cc"],
148    deps = [
149        ":pw_protobuf",
150        "//pw_unit_test",
151    ],
152)
153
154pw_cc_test(
155    name = "stream_decoder_test",
156    srcs = ["stream_decoder_test.cc"],
157    deps = [
158        ":pw_protobuf",
159        "//pw_unit_test",
160    ],
161)
162
163pw_cc_test(
164    name = "map_utils_test",
165    srcs = ["map_utils_test.cc"],
166    deps = [
167        ":pw_protobuf",
168        "//pw_unit_test",
169    ],
170)
171
172pw_cc_test(
173    name = "message_test",
174    srcs = ["message_test.cc"],
175    deps = [
176        ":pw_protobuf",
177        "//pw_unit_test",
178    ],
179)
180
181pw_cc_perf_test(
182    name = "encoder_perf_test",
183    srcs = ["encoder_perf_test.cc"],
184    deps = [
185        ":pw_protobuf",
186        "//pw_unit_test",
187    ],
188)
189
190proto_library(
191    name = "codegen_protos",
192    srcs = [
193        "pw_protobuf_codegen_protos/codegen_options.proto",
194    ],
195    strip_import_prefix = "/pw_protobuf",
196)
197
198py_proto_library(
199    name = "codegen_protos_pb2",
200    srcs = [
201        "pw_protobuf_codegen_protos/codegen_options.proto",
202    ],
203)
204
205proto_library(
206    name = "common_proto",
207    srcs = [
208        "pw_protobuf_protos/common.proto",
209    ],
210    strip_import_prefix = "/pw_protobuf",
211)
212
213proto_library(
214    name = "field_options_proto",
215    srcs = [
216        "pw_protobuf_protos/field_options.proto",
217    ],
218    strip_import_prefix = "/pw_protobuf",
219    deps = [
220        "@com_google_protobuf//:descriptor_proto",
221    ],
222)
223
224py_proto_library(
225    name = "field_options_proto_pb2",
226    srcs = [
227        "pw_protobuf_protos/field_options.proto",
228    ],
229    deps = [
230        "@com_google_protobuf//:protobuf_python",
231    ],
232)
233
234proto_library(
235    name = "status_proto",
236    srcs = [
237        "pw_protobuf_protos/status.proto",
238    ],
239    strip_import_prefix = "/pw_protobuf",
240)
241
242py_proto_library(
243    name = "status_proto_pb2",
244    srcs = [
245        "pw_protobuf_protos/status.proto",
246    ],
247)
248
249proto_library(
250    name = "codegen_test_deps_protos",
251    srcs = [
252        "pw_protobuf_test_deps_protos/imported.proto",
253    ],
254    strip_import_prefix = "/pw_protobuf",
255)
256
257proto_library(
258    name = "codegen_test_proto",
259    srcs = [
260        "pw_protobuf_test_protos/full_test.proto",
261        "pw_protobuf_test_protos/imported.proto",
262        "pw_protobuf_test_protos/importer.proto",
263        "pw_protobuf_test_protos/non_pw_package.proto",
264        "pw_protobuf_test_protos/optional.proto",
265        "pw_protobuf_test_protos/proto2.proto",
266        "pw_protobuf_test_protos/repeated.proto",
267        "pw_protobuf_test_protos/size_report.proto",
268    ],
269    strip_import_prefix = "/pw_protobuf",
270    deps = [
271        ":codegen_test_deps_protos",
272        ":common_proto",
273    ],
274)
275
276pw_proto_library(
277    name = "codegen_test_proto_cc",
278    deps = [
279        ":codegen_test_proto",
280        ":common_proto",
281    ],
282)
283
284pw_cc_test(
285    name = "codegen_decoder_test",
286    srcs = [
287        "codegen_decoder_test.cc",
288    ],
289    deps = [
290        ":codegen_test_proto_cc.pwpb",
291        ":pw_protobuf",
292        "//pw_span",
293        "//pw_unit_test",
294    ],
295)
296
297pw_cc_test(
298    name = "codegen_encoder_test",
299    srcs = [
300        "codegen_encoder_test.cc",
301    ],
302    deps = [
303        ":codegen_test_proto_cc.pwpb",
304        ":pw_protobuf",
305        "//pw_span",
306        "//pw_unit_test",
307    ],
308)
309
310# TODO(tpudlik): Figure out how to add options file support to Bazel.
311filegroup(
312    name = "codegen_message_test",
313    srcs = [
314        "codegen_message_test.cc",
315    ],
316)
317
318# TODO(frolv): Figure out how to add facade tests to Bazel.
319filegroup(
320    name = "varint_size_test",
321    srcs = [
322        "varint_size_test.cc",
323    ],
324)
325
326# TODO(frolv): Figure out what to do about size reports in Bazel.
327filegroup(
328    name = "size_reports",
329    srcs = glob([
330        "size_report/*.cc",
331    ]),
332)
333
334proto_plugin(
335    name = "pw_cc_plugin",
336    outputs = [
337        "{protopath}.pwpb.h",
338    ],
339    protoc_plugin_name = "pwpb",
340    tool = "@pigweed//pw_protobuf/py:plugin",
341    use_built_in_shell_environment = True,
342    visibility = ["//visibility:public"],
343)
344