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