• 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
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pw_build/input_group.gni")
18import("$dir_pw_build/module_config.gni")
19import("$dir_pw_build/target_types.gni")
20import("$dir_pw_docgen/docs.gni")
21import("$dir_pw_fuzzer/fuzzer.gni")
22import("$dir_pw_perf_test/perf_test.gni")
23import("$dir_pw_protobuf_compiler/proto.gni")
24import("$dir_pw_unit_test/facade_test.gni")
25import("$dir_pw_unit_test/test.gni")
26
27declare_args() {
28  # The build target that overrides the default configuration options for this
29  # module. This should point to a source set that provides defines through a
30  # public config (which may -include a file or add defines directly).
31  pw_protobuf_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
32}
33
34config("public_include_path") {
35  include_dirs = [ "public" ]
36}
37
38pw_source_set("config") {
39  public = [ "public/pw_protobuf/config.h" ]
40  public_configs = [ ":public_include_path" ]
41  public_deps = [ pw_protobuf_CONFIG ]
42  visibility = [ ":*" ]
43}
44
45pw_source_set("pw_protobuf") {
46  public_configs = [ ":public_include_path" ]
47  public_deps = [
48    ":config",
49    "$dir_pw_bytes:bit",
50    "$dir_pw_containers:vector",
51    "$dir_pw_stream:interval_reader",
52    "$dir_pw_varint:stream",
53    dir_pw_assert,
54    dir_pw_bytes,
55    dir_pw_function,
56    dir_pw_log,
57    dir_pw_preprocessor,
58    dir_pw_result,
59    dir_pw_span,
60    dir_pw_status,
61    dir_pw_stream,
62    dir_pw_varint,
63  ]
64  public = [
65    "public/pw_protobuf/decoder.h",
66    "public/pw_protobuf/encoder.h",
67    "public/pw_protobuf/find.h",
68    "public/pw_protobuf/internal/codegen.h",
69    "public/pw_protobuf/internal/proto_integer_base.h",
70    "public/pw_protobuf/map_utils.h",
71    "public/pw_protobuf/message.h",
72    "public/pw_protobuf/serialized_size.h",
73    "public/pw_protobuf/stream_decoder.h",
74    "public/pw_protobuf/wire_format.h",
75  ]
76  sources = [
77    "decoder.cc",
78    "encoder.cc",
79    "find.cc",
80    "map_utils.cc",
81    "message.cc",
82    "stream_decoder.cc",
83  ]
84  deps = [ "$dir_pw_string:string" ]
85}
86
87pw_source_set("bytes_utils") {
88  public_configs = [ ":public_include_path" ]
89  public = [ "public/pw_protobuf/bytes_utils.h" ]
90  public_deps = [
91    ":pw_protobuf",
92    dir_pw_bytes,
93    dir_pw_result,
94    dir_pw_status,
95  ]
96}
97
98pw_doc_group("docs") {
99  sources = [
100    "docs.rst",
101    "size_report.rst",
102  ]
103  inputs = [
104    "pw_protobuf_test_protos/size_report.options",
105    "pw_protobuf_test_protos/size_report.proto",
106  ]
107  report_deps = [
108    "size_report:decoder_incremental",
109    "size_report:decoder_partial",
110    "size_report:oneof_codegen_size_comparison",
111    "size_report:protobuf_overview",
112    "size_report:simple_codegen_size_comparison",
113  ]
114}
115
116pw_test_group("tests") {
117  tests = [
118    ":codegen_decoder_test",
119    ":codegen_encoder_test",
120    ":codegen_message_test",
121    ":decoder_test",
122    ":encoder_test",
123    ":encoder_fuzzer_test",
124    ":decoder_fuzzer_test",
125    ":find_test",
126    ":map_utils_test",
127    ":message_test",
128    ":serialized_size_test",
129    ":stream_decoder_test",
130    ":varint_size_test",
131  ]
132}
133
134group("fuzzers") {
135  deps = [
136    ":decoder_fuzzer",
137    ":encoder_fuzzer",
138  ]
139}
140
141pw_test("decoder_test") {
142  deps = [ ":pw_protobuf" ]
143  sources = [ "decoder_test.cc" ]
144}
145
146pw_test("encoder_test") {
147  deps = [ ":pw_protobuf" ]
148  sources = [ "encoder_test.cc" ]
149}
150
151pw_test("find_test") {
152  deps = [ ":pw_protobuf" ]
153  sources = [ "find_test.cc" ]
154}
155
156pw_test("codegen_decoder_test") {
157  deps = [ ":codegen_test_protos.pwpb" ]
158  sources = [ "codegen_decoder_test.cc" ]
159}
160
161pw_test("codegen_encoder_test") {
162  deps = [ ":codegen_test_protos.pwpb" ]
163  sources = [ "codegen_encoder_test.cc" ]
164}
165
166pw_test("codegen_message_test") {
167  deps = [
168    ":codegen_test_protos.pwpb",
169    dir_pw_string,
170  ]
171  sources = [ "codegen_message_test.cc" ]
172}
173
174pw_test("serialized_size_test") {
175  deps = [ ":pw_protobuf" ]
176  sources = [ "serialized_size_test.cc" ]
177}
178
179pw_test("stream_decoder_test") {
180  deps = [ ":pw_protobuf" ]
181  sources = [ "stream_decoder_test.cc" ]
182}
183
184pw_test("map_utils_test") {
185  deps = [ ":pw_protobuf" ]
186  sources = [ "map_utils_test.cc" ]
187}
188
189pw_test("message_test") {
190  deps = [ ":pw_protobuf" ]
191  sources = [ "message_test.cc" ]
192}
193
194group("perf_tests") {
195  deps = [ ":encoder_perf_test" ]
196}
197
198pw_perf_test("encoder_perf_test") {
199  enable_if = pw_perf_test_TIMER_INTERFACE_BACKEND != ""
200  deps = [ ":pw_protobuf" ]
201  sources = [ "encoder_perf_test.cc" ]
202}
203
204config("one_byte_varint") {
205  defines = [ "PW_PROTOBUF_CFG_MAX_VARINT_SIZE=1" ]
206  visibility = [ ":*" ]
207}
208
209pw_source_set("varint_size_test_config") {
210  public_configs = [ ":one_byte_varint" ]
211  visibility = [ ":*" ]
212}
213
214pw_facade_test("varint_size_test") {
215  build_args = {
216    pw_protobuf_CONFIG = ":varint_size_test_config"
217  }
218  deps = [ ":pw_protobuf" ]
219  sources = [ "varint_size_test.cc" ]
220}
221
222pw_proto_library("codegen_protos") {
223  sources = [ "pw_protobuf_codegen_protos/codegen_options.proto" ]
224}
225
226pw_proto_library("common_protos") {
227  sources = [
228    "pw_protobuf_protos/common.proto",
229    "pw_protobuf_protos/field_options.proto",
230    "pw_protobuf_protos/status.proto",
231  ]
232}
233
234pw_proto_library("codegen_test_deps_protos") {
235  sources = [ "pw_protobuf_test_deps_protos/imported.proto" ]
236  inputs = [ "pw_protobuf_test_deps_protos/imported.options" ]
237}
238
239pw_proto_library("codegen_test_protos") {
240  sources = [
241    "pw_protobuf_test_protos/full_test.proto",
242    "pw_protobuf_test_protos/imported.proto",
243    "pw_protobuf_test_protos/importer.proto",
244    "pw_protobuf_test_protos/non_pw_package.proto",
245    "pw_protobuf_test_protos/optional.proto",
246    "pw_protobuf_test_protos/proto2.proto",
247    "pw_protobuf_test_protos/repeated.proto",
248    "pw_protobuf_test_protos/size_report.proto",
249  ]
250  inputs = [
251    "pw_protobuf_test_protos/full_test.options",
252    "pw_protobuf_test_protos/optional.options",
253    "pw_protobuf_test_protos/imported.options",
254    "pw_protobuf_test_protos/repeated.options",
255  ]
256  deps = [
257    ":codegen_test_deps_protos",
258    ":common_protos",
259  ]
260}
261
262# The tests below have a large amount of global and static data.
263# TODO(b/234883746): Replace this with a better size-based check.
264_small_executable_target_types = [
265  "stm32f429i_executable",
266  "lm3s6965evb_executable",
267]
268_supports_large_tests =
269    _small_executable_target_types + [ pw_build_EXECUTABLE_TARGET_TYPE ] -
270    _small_executable_target_types != []
271
272pw_fuzzer("encoder_fuzzer") {
273  sources = [
274    "encoder_fuzzer.cc",
275    "fuzz.h",
276  ]
277  deps = [
278    ":pw_protobuf",
279    dir_pw_fuzzer,
280    dir_pw_span,
281  ]
282  enable_test_if = _supports_large_tests
283}
284
285pw_fuzzer("decoder_fuzzer") {
286  sources = [
287    "decoder_fuzzer.cc",
288    "fuzz.h",
289  ]
290  deps = [
291    ":pw_protobuf",
292    dir_pw_fuzzer,
293    dir_pw_span,
294    dir_pw_status,
295    dir_pw_stream,
296  ]
297  enable_test_if = _supports_large_tests
298}
299