blob: 32b5877fbdf4ba3a5bd05ff8ddd2dbe0825376f6 [file] [log] [blame]
Nathaniel Brough9d9a20d2020-08-04 16:46:56 +08001# Copyright 2021 The Pigweed Authors
Alexei Frolovbbf164c2019-12-16 12:51:59 -08002#
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
Nathaniel Brough9d9a20d2020-08-04 16:46:56 +080015load("@rules_proto//proto:defs.bzl", "proto_library")
Alexei Frolovbbf164c2019-12-16 12:51:59 -080016load(
17 "//pw_build:pigweed.bzl",
18 "pw_cc_library",
19 "pw_cc_test",
20)
Nathaniel Brough9d9a20d2020-08-04 16:46:56 +080021load("@rules_python//python:defs.bzl", "py_binary")
22load("@rules_proto_grpc//:plugin.bzl", "proto_plugin")
23load("//pw_protobuf_compiler:proto.bzl", "pw_proto_library")
Alexei Frolovbbf164c2019-12-16 12:51:59 -080024
25package(default_visibility = ["//visibility:public"])
26
27licenses(["notice"]) # Apache License 2.0
28
29pw_cc_library(
Alexei Frolovf9ae1892021-04-01 18:24:27 -070030 name = "config",
31 hdrs = ["public/pw_protobuf/config.h"],
32 includes = ["public"],
33)
34
35pw_cc_library(
Alexei Frolovbbf164c2019-12-16 12:51:59 -080036 name = "pw_protobuf",
37 srcs = [
Alexei Frolovdea46f72020-01-07 13:28:24 -080038 "decoder.cc",
Alexei Frolovbbf164c2019-12-16 12:51:59 -080039 "encoder.cc",
Alexei Frolovbbbedff2020-03-11 14:21:38 -070040 "find.cc",
Armando Montanez0ed221c2021-04-02 18:33:01 -070041 "streaming_encoder.cc",
Alexei Frolovbbf164c2019-12-16 12:51:59 -080042 ],
43 hdrs = [
44 "public/pw_protobuf/codegen.h",
Alexei Frolovdea46f72020-01-07 13:28:24 -080045 "public/pw_protobuf/decoder.h",
Alexei Frolovbbf164c2019-12-16 12:51:59 -080046 "public/pw_protobuf/encoder.h",
Alexei Frolovbbbedff2020-03-11 14:21:38 -070047 "public/pw_protobuf/find.h",
Ewout van Bekkumc76aa402020-09-23 10:58:27 -070048 "public/pw_protobuf/serialized_size.h",
Armando Montanez0ed221c2021-04-02 18:33:01 -070049 "public/pw_protobuf/streaming_encoder.h",
Alexei Frolovdea46f72020-01-07 13:28:24 -080050 "public/pw_protobuf/wire_format.h",
Alexei Frolovbbf164c2019-12-16 12:51:59 -080051 ],
Wyatt Hepler61def0a2020-01-06 10:30:14 -080052 includes = ["public"],
Alexei Frolovbbf164c2019-12-16 12:51:59 -080053 deps = [
Alexei Frolovf9ae1892021-04-01 18:24:27 -070054 ":config",
Armando Montanez0ed221c2021-04-02 18:33:01 -070055 "//pw_assert",
Nathaniel Brough9d9a20d2020-08-04 16:46:56 +080056 "//pw_bytes",
57 "//pw_result",
Rob Mohree8ce082019-12-20 10:32:16 -080058 "//pw_span",
Alexei Frolovbbf164c2019-12-16 12:51:59 -080059 "//pw_status",
Armando Montanez0ed221c2021-04-02 18:33:01 -070060 "//pw_stream",
Alexei Frolovbbf164c2019-12-16 12:51:59 -080061 "//pw_varint",
62 ],
63)
64
65pw_cc_test(
Alexei Frolovdea46f72020-01-07 13:28:24 -080066 name = "decoder_test",
67 srcs = ["decoder_test.cc"],
Rob Mohr06819482020-04-06 13:25:43 -070068 deps = [
69 ":pw_protobuf",
70 "//pw_preprocessor",
71 "//pw_unit_test",
72 ],
Alexei Frolovdea46f72020-01-07 13:28:24 -080073)
74
75pw_cc_test(
Alexei Frolovbbf164c2019-12-16 12:51:59 -080076 name = "encoder_test",
77 srcs = ["encoder_test.cc"],
Rob Mohr06819482020-04-06 13:25:43 -070078 deps = [
79 ":pw_protobuf",
80 "//pw_unit_test",
81 ],
Alexei Frolovbbf164c2019-12-16 12:51:59 -080082)
83
Alexei Frolovbbbedff2020-03-11 14:21:38 -070084pw_cc_test(
Armando Montanez0ed221c2021-04-02 18:33:01 -070085 name = "streaming_encoder_test",
86 srcs = ["streaming_encoder_test.cc"],
87 deps = [
88 ":pw_protobuf",
89 "//pw_unit_test",
90 ],
91)
92
93pw_cc_test(
Alexei Frolovbbbedff2020-03-11 14:21:38 -070094 name = "find_test",
95 srcs = ["find_test.cc"],
Rob Mohr06819482020-04-06 13:25:43 -070096 deps = [
97 ":pw_protobuf",
98 "//pw_unit_test",
99 ],
Alexei Frolovbbbedff2020-03-11 14:21:38 -0700100)
101
Nathaniel Brough9d9a20d2020-08-04 16:46:56 +0800102proto_library(
103 name = "codegen_test_proto",
104 srcs = [
105 "pw_protobuf_protos/common.proto",
106 "pw_protobuf_test_protos/full_test.proto",
107 "pw_protobuf_test_protos/imported.proto",
108 "pw_protobuf_test_protos/importer.proto",
109 "pw_protobuf_test_protos/non_pw_package.proto",
110 "pw_protobuf_test_protos/proto2.proto",
111 "pw_protobuf_test_protos/repeated.proto",
112 ],
113 strip_import_prefix = "//pw_protobuf",
114)
115
116pw_proto_library(
117 name = "codegen_test_protos_pwpb",
118 deps = [":codegen_test_proto"],
119)
120
121pw_cc_test(
Alexei Frolovbbf164c2019-12-16 12:51:59 -0800122 name = "codegen_test",
123 srcs = [
124 "codegen_test.cc",
125 ],
Nathaniel Brough9d9a20d2020-08-04 16:46:56 +0800126 deps = [
127 ":codegen_test_protos_pwpb",
128 ":pw_protobuf",
129 "//pw_span",
130 "//pw_unit_test",
131 ],
Alexei Frolovbbf164c2019-12-16 12:51:59 -0800132)
Alexei Frolov9c2ed462020-01-13 15:35:42 -0800133
Alexei Frolovf9ae1892021-04-01 18:24:27 -0700134# TODO(frolv): Figure out how to add facade tests to Bazel.
135filegroup(
136 name = "varint_size_test",
137 srcs = [
138 "varint_size_test.cc",
139 ],
140)
141
Alexei Frolov9c2ed462020-01-13 15:35:42 -0800142# TODO(frolv): Figure out what to do about size reports in Bazel.
143filegroup(
144 name = "size_reports",
145 srcs = glob([
146 "size_report/*.cc",
147 ]),
148)
Nathaniel Brough9d9a20d2020-08-04 16:46:56 +0800149
150py_binary(
151 name = "plugin",
152 srcs = glob(["py/pw_protobuf/*.py"]),
153 imports = ["py"],
154 main = "py/pw_protobuf/plugin.py",
155 python_version = "PY3",
156 deps = ["@com_google_protobuf//:protobuf_python"],
157)
158
159proto_plugin(
160 name = "pw_cc_plugin",
161 outputs = [
162 "{protopath}.pwpb.h",
163 ],
164 protoc_plugin_name = "pwpb",
165 tool = "@pigweed//pw_protobuf:plugin",
166 visibility = ["//visibility:public"],
167)