• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2023 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/fuzz_test.gni")
22import("$dir_pw_fuzzer/fuzzer.gni")
23import("$dir_pw_perf_test/perf_test.gni")
24import("$dir_pw_protobuf_compiler/proto.gni")
25import("$dir_pw_unit_test/facade_test.gni")
26import("$dir_pw_unit_test/test.gni")
27
28declare_args() {
29  # The build target that overrides the default configuration options for this
30  # module. This should point to a source set that provides defines through a
31  # public config (which may -include a file or add defines directly).
32  pw_protobuf_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
33}
34
35config("public_include_path") {
36  include_dirs = [ "public" ]
37}
38
39pw_source_set("config") {
40  public = [ "public/pw_protobuf/config.h" ]
41  public_configs = [ ":public_include_path" ]
42  public_deps = [ pw_protobuf_CONFIG ]
43  visibility = [ ":*" ]
44}
45
46pw_source_set("pw_protobuf") {
47  public_configs = [ ":public_include_path" ]
48  public_deps = [
49    ":config",
50    "$dir_pw_bytes:bit",
51    "$dir_pw_containers:vector",
52    "$dir_pw_stream:interval_reader",
53    "$dir_pw_string:string",
54    "$dir_pw_toolchain:sibling_cast",
55    "$dir_pw_varint:stream",
56    dir_pw_assert,
57    dir_pw_bytes,
58    dir_pw_function,
59    dir_pw_log,
60    dir_pw_preprocessor,
61    dir_pw_result,
62    dir_pw_span,
63    dir_pw_status,
64    dir_pw_stream,
65    dir_pw_varint,
66  ]
67  public = [
68    "public/pw_protobuf/decoder.h",
69    "public/pw_protobuf/encoder.h",
70    "public/pw_protobuf/find.h",
71    "public/pw_protobuf/internal/codegen.h",
72    "public/pw_protobuf/internal/proto_integer_base.h",
73    "public/pw_protobuf/map_utils.h",
74    "public/pw_protobuf/message.h",
75    "public/pw_protobuf/serialized_size.h",
76    "public/pw_protobuf/stream_decoder.h",
77    "public/pw_protobuf/wire_format.h",
78  ]
79  sources = [
80    "decoder.cc",
81    "encoder.cc",
82    "find.cc",
83    "map_utils.cc",
84    "message.cc",
85    "stream_decoder.cc",
86  ]
87}
88
89pw_source_set("bytes_utils") {
90  public_configs = [ ":public_include_path" ]
91  public = [ "public/pw_protobuf/bytes_utils.h" ]
92  public_deps = [
93    ":pw_protobuf",
94    dir_pw_bytes,
95    dir_pw_result,
96    dir_pw_status,
97  ]
98}
99
100pw_doc_group("docs") {
101  sources = [
102    "docs.rst",
103    "size_report.rst",
104  ]
105  inputs = [
106    "pw_protobuf_test_protos/size_report.pwpb_options",
107    "pw_protobuf_test_protos/size_report.proto",
108  ]
109  report_deps = [
110    "size_report:decoder_incremental",
111    "size_report:decoder_partial",
112    "size_report:oneof_codegen_size_comparison",
113    "size_report:protobuf_overview",
114    "size_report:simple_codegen_size_comparison",
115  ]
116}
117
118pw_test_group("tests") {
119  tests = [
120    ":codegen_decoder_test",
121    ":codegen_editions_test",
122    ":codegen_encoder_test",
123    ":codegen_message_test",
124    ":decoder_test",
125    ":encoder_test",
126    ":find_test",
127    ":map_utils_test",
128    ":message_test",
129    ":serialized_size_test",
130    ":stream_decoder_test",
131    ":varint_size_test",
132  ]
133  group_deps = [ ":fuzzers" ]
134}
135
136pw_fuzzer_group("fuzzers") {
137  fuzzers = [
138    ":decoder_fuzzer",
139    ":encoder_fuzzer",
140  ]
141}
142
143pw_fuzz_test("decoder_test") {
144  deps = [
145    ":pw_protobuf",
146    "$dir_pw_fuzzer:libfuzzer",
147  ]
148  sources = [ "decoder_test.cc" ]
149
150  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
151  configs = [ "$dir_pw_build:conversion_warnings" ]
152}
153
154pw_test("encoder_test") {
155  deps = [ ":pw_protobuf" ]
156  sources = [ "encoder_test.cc" ]
157
158  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
159  configs = [ "$dir_pw_build:conversion_warnings" ]
160}
161
162pw_test("find_test") {
163  deps = [
164    ":pw_protobuf",
165    dir_pw_string,
166  ]
167  sources = [ "find_test.cc" ]
168
169  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
170  configs = [ "$dir_pw_build:conversion_warnings" ]
171}
172
173pw_test("codegen_decoder_test") {
174  deps = [ ":codegen_test_protos.pwpb" ]
175  sources = [ "codegen_decoder_test.cc" ]
176
177  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
178  configs = [ "$dir_pw_build:conversion_warnings" ]
179}
180
181pw_test("codegen_encoder_test") {
182  deps = [
183    ":codegen_test_protos.pwpb",
184    dir_pw_bytes,
185  ]
186  sources = [ "codegen_encoder_test.cc" ]
187
188  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
189  configs = [ "$dir_pw_build:conversion_warnings" ]
190}
191
192pw_test("codegen_message_test") {
193  deps = [
194    ":codegen_test_protos.pwpb",
195    dir_pw_string,
196  ]
197  sources = [ "codegen_message_test.cc" ]
198
199  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
200  configs = [ "$dir_pw_build:conversion_warnings" ]
201}
202
203pw_test("codegen_editions_test") {
204  deps = [
205    ":codegen_test_protos.pwpb",
206    dir_pw_string,
207  ]
208  sources = [ "codegen_editions_test.cc" ]
209}
210
211pw_test("serialized_size_test") {
212  deps = [ ":pw_protobuf" ]
213  sources = [ "serialized_size_test.cc" ]
214
215  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
216  configs = [ "$dir_pw_build:conversion_warnings" ]
217}
218
219pw_test("stream_decoder_test") {
220  deps = [ ":pw_protobuf" ]
221  sources = [ "stream_decoder_test.cc" ]
222
223  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
224  configs = [ "$dir_pw_build:conversion_warnings" ]
225}
226
227pw_test("map_utils_test") {
228  deps = [ ":pw_protobuf" ]
229  sources = [ "map_utils_test.cc" ]
230
231  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
232  configs = [ "$dir_pw_build:conversion_warnings" ]
233}
234
235pw_test("message_test") {
236  deps = [ ":pw_protobuf" ]
237  sources = [ "message_test.cc" ]
238
239  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
240  configs = [ "$dir_pw_build:conversion_warnings" ]
241}
242
243group("perf_tests") {
244  deps = [ ":encoder_perf_test" ]
245}
246
247pw_perf_test("encoder_perf_test") {
248  enable_if = pw_perf_test_TIMER_INTERFACE_BACKEND != ""
249  deps = [ ":pw_protobuf" ]
250  sources = [ "encoder_perf_test.cc" ]
251
252  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
253  configs = [ "$dir_pw_build:conversion_warnings" ]
254}
255
256config("one_byte_varint") {
257  defines = [ "PW_PROTOBUF_CFG_MAX_VARINT_SIZE=1" ]
258  visibility = [ ":*" ]
259}
260
261pw_source_set("varint_size_test_config") {
262  public_configs = [ ":one_byte_varint" ]
263  visibility = [ ":*" ]
264}
265
266pw_facade_test("varint_size_test") {
267  build_args = {
268    pw_protobuf_CONFIG = ":varint_size_test_config"
269  }
270  deps = [
271    ":codegen_test_protos.pwpb",
272    ":pw_protobuf",
273  ]
274  sources = [ "varint_size_test.cc" ]
275
276  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
277  configs = [ "$dir_pw_build:conversion_warnings" ]
278}
279
280pw_proto_library("codegen_protos") {
281  sources = [ "pw_protobuf_codegen_protos/codegen_options.proto" ]
282}
283
284pw_proto_library("common_protos") {
285  sources = [
286    "pw_protobuf_protos/common.proto",
287    "pw_protobuf_protos/field_options.proto",
288    "pw_protobuf_protos/status.proto",
289  ]
290}
291
292pw_proto_library("codegen_test_deps_protos") {
293  sources = [ "pw_protobuf_test_deps_protos/imported.proto" ]
294  inputs = [ "pw_protobuf_test_deps_protos/imported.pwpb_options" ]
295}
296
297pw_proto_library("codegen_test_deps_protos_prefix") {
298  sources = [ "pw_protobuf_test_deps_protos/test_prefix_imported.proto" ]
299  inputs = [ "pw_protobuf_test_deps_protos/test_prefix_imported.pwpb_options" ]
300  prefix = "test_prefix"
301  strip_prefix = "pw_protobuf_test_deps_protos"
302}
303
304pw_proto_library("codegen_test_protos") {
305  sources = [
306    "pw_protobuf_test_protos/edition.proto",
307    "pw_protobuf_test_protos/edition_file_options.proto",
308    "pw_protobuf_test_protos/full_test.proto",
309    "pw_protobuf_test_protos/imported.proto",
310    "pw_protobuf_test_protos/importer.proto",
311    "pw_protobuf_test_protos/non_pw_package.proto",
312    "pw_protobuf_test_protos/optional.proto",
313    "pw_protobuf_test_protos/proto2.proto",
314    "pw_protobuf_test_protos/repeated.proto",
315    "pw_protobuf_test_protos/size_report.proto",
316  ]
317  inputs = [
318    "pw_protobuf_test_protos/edition.pwpb_options",
319    "pw_protobuf_test_protos/edition_file_options.pwpb_options",
320    "pw_protobuf_test_protos/full_test.pwpb_options",
321    "pw_protobuf_test_protos/optional.pwpb_options",
322    "pw_protobuf_test_protos/imported.pwpb_options",
323    "pw_protobuf_test_protos/repeated.pwpb_options",
324  ]
325  deps = [
326    ":codegen_test_deps_protos",
327    ":codegen_test_deps_protos_prefix",
328    ":common_protos",
329  ]
330}
331
332# The tests below have a large amount of global and static data.
333# TODO: b/234883746 - Replace this with a better size-based check.
334_small_executable_target_types = [
335  "stm32f429i_executable",
336  "lm3s6965evb_executable",
337  "arduino_executable",  # Fails for Teensy 3.2
338]
339_supports_large_tests =
340    _small_executable_target_types + [ pw_build_EXECUTABLE_TARGET_TYPE ] -
341    _small_executable_target_types != []
342
343pw_fuzzer("encoder_fuzzer") {
344  sources = [
345    "encoder_fuzzer.cc",
346    "fuzz.h",
347  ]
348  deps = [
349    ":pw_protobuf",
350    dir_pw_span,
351  ]
352  enable_test_if = _supports_large_tests
353
354  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
355  configs = [ "$dir_pw_build:conversion_warnings" ]
356}
357
358pw_fuzzer("decoder_fuzzer") {
359  sources = [
360    "decoder_fuzzer.cc",
361    "fuzz.h",
362  ]
363  deps = [
364    ":pw_protobuf",
365    dir_pw_span,
366    dir_pw_status,
367    dir_pw_stream,
368  ]
369  enable_test_if = _supports_large_tests
370
371  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
372  configs = [ "$dir_pw_build:conversion_warnings" ]
373}
374