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.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_encoder_test", 121 ":codegen_message_test", 122 ":decoder_test", 123 ":encoder_test", 124 ":find_test", 125 ":map_utils_test", 126 ":message_test", 127 ":serialized_size_test", 128 ":stream_decoder_test", 129 ":varint_size_test", 130 ] 131 group_deps = [ ":fuzzers" ] 132} 133 134pw_fuzzer_group("fuzzers") { 135 fuzzers = [ 136 ":decoder_fuzzer", 137 ":encoder_fuzzer", 138 ] 139} 140 141pw_test("decoder_test") { 142 deps = [ ":pw_protobuf" ] 143 sources = [ "decoder_test.cc" ] 144 145 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 146 configs = [ "$dir_pw_build:conversion_warnings" ] 147} 148 149pw_test("encoder_test") { 150 deps = [ ":pw_protobuf" ] 151 sources = [ "encoder_test.cc" ] 152 153 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 154 configs = [ "$dir_pw_build:conversion_warnings" ] 155} 156 157pw_test("find_test") { 158 deps = [ 159 ":pw_protobuf", 160 dir_pw_string, 161 ] 162 sources = [ "find_test.cc" ] 163 164 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 165 configs = [ "$dir_pw_build:conversion_warnings" ] 166} 167 168pw_test("codegen_decoder_test") { 169 deps = [ ":codegen_test_protos.pwpb" ] 170 sources = [ "codegen_decoder_test.cc" ] 171 172 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 173 configs = [ "$dir_pw_build:conversion_warnings" ] 174} 175 176pw_test("codegen_encoder_test") { 177 deps = [ ":codegen_test_protos.pwpb" ] 178 sources = [ "codegen_encoder_test.cc" ] 179 180 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 181 configs = [ "$dir_pw_build:conversion_warnings" ] 182} 183 184pw_test("codegen_message_test") { 185 deps = [ 186 ":codegen_test_protos.pwpb", 187 dir_pw_string, 188 ] 189 sources = [ "codegen_message_test.cc" ] 190 191 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 192 configs = [ "$dir_pw_build:conversion_warnings" ] 193} 194 195pw_test("serialized_size_test") { 196 deps = [ ":pw_protobuf" ] 197 sources = [ "serialized_size_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("stream_decoder_test") { 204 deps = [ ":pw_protobuf" ] 205 sources = [ "stream_decoder_test.cc" ] 206 207 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 208 configs = [ "$dir_pw_build:conversion_warnings" ] 209} 210 211pw_test("map_utils_test") { 212 deps = [ ":pw_protobuf" ] 213 sources = [ "map_utils_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("message_test") { 220 deps = [ ":pw_protobuf" ] 221 sources = [ "message_test.cc" ] 222 223 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 224 configs = [ "$dir_pw_build:conversion_warnings" ] 225} 226 227group("perf_tests") { 228 deps = [ ":encoder_perf_test" ] 229} 230 231pw_perf_test("encoder_perf_test") { 232 enable_if = pw_perf_test_TIMER_INTERFACE_BACKEND != "" 233 deps = [ ":pw_protobuf" ] 234 sources = [ "encoder_perf_test.cc" ] 235 236 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 237 configs = [ "$dir_pw_build:conversion_warnings" ] 238} 239 240config("one_byte_varint") { 241 defines = [ "PW_PROTOBUF_CFG_MAX_VARINT_SIZE=1" ] 242 visibility = [ ":*" ] 243} 244 245pw_source_set("varint_size_test_config") { 246 public_configs = [ ":one_byte_varint" ] 247 visibility = [ ":*" ] 248} 249 250pw_facade_test("varint_size_test") { 251 build_args = { 252 pw_protobuf_CONFIG = ":varint_size_test_config" 253 } 254 deps = [ ":pw_protobuf" ] 255 sources = [ "varint_size_test.cc" ] 256 257 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 258 configs = [ "$dir_pw_build:conversion_warnings" ] 259} 260 261pw_proto_library("codegen_protos") { 262 sources = [ "pw_protobuf_codegen_protos/codegen_options.proto" ] 263} 264 265pw_proto_library("common_protos") { 266 sources = [ 267 "pw_protobuf_protos/common.proto", 268 "pw_protobuf_protos/field_options.proto", 269 "pw_protobuf_protos/status.proto", 270 ] 271} 272 273pw_proto_library("codegen_test_deps_protos") { 274 sources = [ "pw_protobuf_test_deps_protos/imported.proto" ] 275 inputs = [ "pw_protobuf_test_deps_protos/imported.options" ] 276} 277 278pw_proto_library("codegen_test_deps_protos_prefix") { 279 sources = [ "pw_protobuf_test_deps_protos/test_prefix_imported.proto" ] 280 inputs = [ "pw_protobuf_test_deps_protos/test_prefix_imported.options" ] 281 prefix = "test_prefix" 282 strip_prefix = "pw_protobuf_test_deps_protos" 283} 284 285pw_proto_library("codegen_test_protos") { 286 sources = [ 287 "pw_protobuf_test_protos/full_test.proto", 288 "pw_protobuf_test_protos/imported.proto", 289 "pw_protobuf_test_protos/importer.proto", 290 "pw_protobuf_test_protos/non_pw_package.proto", 291 "pw_protobuf_test_protos/optional.proto", 292 "pw_protobuf_test_protos/proto2.proto", 293 "pw_protobuf_test_protos/repeated.proto", 294 "pw_protobuf_test_protos/size_report.proto", 295 ] 296 inputs = [ 297 "pw_protobuf_test_protos/full_test.options", 298 "pw_protobuf_test_protos/optional.options", 299 "pw_protobuf_test_protos/imported.options", 300 "pw_protobuf_test_protos/repeated.options", 301 ] 302 deps = [ 303 ":codegen_test_deps_protos", 304 ":codegen_test_deps_protos_prefix", 305 ":common_protos", 306 ] 307} 308 309# The tests below have a large amount of global and static data. 310# TODO: b/234883746 - Replace this with a better size-based check. 311_small_executable_target_types = [ 312 "stm32f429i_executable", 313 "lm3s6965evb_executable", 314 "arduino_executable", # Fails for Teensy 3.2 315] 316_supports_large_tests = 317 _small_executable_target_types + [ pw_build_EXECUTABLE_TARGET_TYPE ] - 318 _small_executable_target_types != [] 319 320pw_fuzzer("encoder_fuzzer") { 321 sources = [ 322 "encoder_fuzzer.cc", 323 "fuzz.h", 324 ] 325 deps = [ 326 ":pw_protobuf", 327 dir_pw_span, 328 ] 329 enable_test_if = _supports_large_tests 330 331 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 332 configs = [ "$dir_pw_build:conversion_warnings" ] 333} 334 335pw_fuzzer("decoder_fuzzer") { 336 sources = [ 337 "decoder_fuzzer.cc", 338 "fuzz.h", 339 ] 340 deps = [ 341 ":pw_protobuf", 342 dir_pw_span, 343 dir_pw_status, 344 dir_pw_stream, 345 ] 346 enable_test_if = _supports_large_tests 347 348 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 349 configs = [ "$dir_pw_build:conversion_warnings" ] 350} 351