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_bloat/bloat.gni") 18import("$dir_pw_build/python.gni") 19import("$dir_pw_build/python_action.gni") 20import("$dir_pw_build/target_types.gni") 21import("$dir_pw_docgen/docs.gni") 22import("$dir_pw_protobuf_compiler/proto.gni") 23import("$dir_pw_sync/backend.gni") 24import("$dir_pw_third_party/nanopb/nanopb.gni") 25import("$dir_pw_unit_test/test.gni") 26import("config.gni") 27import("internal/integration_test_ports.gni") 28 29config("public_include_path") { 30 include_dirs = [ "public" ] 31 visibility = [ ":*" ] 32} 33 34config("global_mutex_config") { 35 defines = [ "PW_RPC_USE_GLOBAL_MUTEX=1" ] 36 visibility = [ ":*" ] 37} 38 39# Set pw_rpc_CONFIG to this to enable the global mutex. If additional options 40# are needed, a config target that sets those can depend on this. 41group("use_global_mutex") { 42 public_configs = [ ":global_mutex_config" ] 43} 44 45pw_source_set("config") { 46 sources = [ "public/pw_rpc/internal/config.h" ] 47 public_configs = [ ":public_include_path" ] 48 public_deps = [ pw_rpc_CONFIG ] 49 visibility = [ "./*" ] 50 friend = [ "./*" ] 51} 52 53pw_source_set("log_config") { 54 sources = [ "public/pw_rpc/internal/log_config.h" ] 55 public_configs = [ ":public_include_path" ] 56 public_deps = [ ":config" ] 57 visibility = [ "./*" ] 58 friend = [ "./*" ] 59} 60 61pw_source_set("server") { 62 public_configs = [ ":public_include_path" ] 63 public_deps = [ ":common" ] 64 deps = [ 65 ":log_config", 66 dir_pw_log, 67 ] 68 public = [ 69 "public/pw_rpc/server.h", 70 "public/pw_rpc/service.h", 71 ] 72 sources = [ 73 "public/pw_rpc/internal/hash.h", 74 "public/pw_rpc/internal/method.h", 75 "public/pw_rpc/internal/method_lookup.h", 76 "public/pw_rpc/internal/method_union.h", 77 "public/pw_rpc/internal/server_call.h", 78 "server.cc", 79 "server_call.cc", 80 "service.cc", 81 ] 82 friend = [ "./*" ] 83 allow_circular_includes_from = [ ":common" ] 84} 85 86pw_source_set("client") { 87 public_configs = [ ":public_include_path" ] 88 public_deps = [ 89 ":common", 90 dir_pw_result, 91 ] 92 deps = [ 93 ":log_config", 94 dir_pw_log, 95 ] 96 public = [ 97 "public/pw_rpc/client.h", 98 "public/pw_rpc/internal/client_call.h", 99 "public/pw_rpc/internal/service_client.h", 100 ] 101 sources = [ 102 "client.cc", 103 "client_call.cc", 104 ] 105 allow_circular_includes_from = [ ":common" ] 106} 107 108pw_source_set("client_server") { 109 public_configs = [ ":public_include_path" ] 110 public_deps = [ 111 ":client", 112 ":server", 113 ] 114 public = [ "public/pw_rpc/client_server.h" ] 115 sources = [ "client_server.cc" ] 116} 117 118# Classes shared by the server and client. 119pw_source_set("common") { 120 public_configs = [ ":public_include_path" ] 121 public_deps = [ 122 ":config", 123 ":protos.pwpb", 124 "$dir_pw_containers:intrusive_list", 125 "$dir_pw_sync:lock_annotations", 126 dir_pw_assert, 127 dir_pw_bytes, 128 dir_pw_function, 129 dir_pw_status, 130 ] 131 132 if (pw_sync_MUTEX_BACKEND != "") { 133 public_deps += [ "$dir_pw_sync:mutex" ] 134 } 135 136 deps = [ 137 ":log_config", 138 dir_pw_log, 139 ] 140 public = [ 141 "public/pw_rpc/channel.h", 142 "public/pw_rpc/writer.h", 143 ] 144 sources = [ 145 "call.cc", 146 "channel.cc", 147 "channel_list.cc", 148 "endpoint.cc", 149 "packet.cc", 150 "public/pw_rpc/internal/call.h", 151 "public/pw_rpc/internal/call_context.h", 152 "public/pw_rpc/internal/channel.h", 153 "public/pw_rpc/internal/channel_list.h", 154 "public/pw_rpc/internal/endpoint.h", 155 "public/pw_rpc/internal/lock.h", 156 "public/pw_rpc/internal/method_info.h", 157 "public/pw_rpc/internal/packet.h", 158 "public/pw_rpc/method_type.h", 159 ] 160 friend = [ "./*" ] 161} 162 163pw_source_set("benchmark") { 164 public_configs = [ ":public_include_path" ] 165 public_deps = [ ":protos.raw_rpc" ] 166 public = [ "public/pw_rpc/benchmark.h" ] 167 sources = [ "benchmark.cc" ] 168} 169 170pw_source_set("fake_channel_output") { 171 public = [ 172 "public/pw_rpc/internal/fake_channel_output.h", 173 "public/pw_rpc/payloads_view.h", 174 ] 175 sources = [ "fake_channel_output.cc" ] 176 public_configs = [ ":public_include_path" ] 177 public_deps = [ 178 ":common", 179 "$dir_pw_containers:filtered_view", 180 "$dir_pw_containers:vector", 181 "$dir_pw_containers:wrapped_iterator", 182 "$dir_pw_sync:mutex", 183 dir_pw_assert, 184 dir_pw_bytes, 185 dir_pw_function, 186 ] 187 deps = [ ":log_config" ] 188 visibility = [ "./*" ] 189} 190 191pw_source_set("thread_testing") { 192 public = [ "public/pw_rpc/thread_testing.h" ] 193 public_deps = [ 194 ":fake_channel_output", 195 "$dir_pw_sync:counting_semaphore", 196 dir_pw_assert, 197 ] 198} 199 200pw_source_set("test_utils") { 201 public = [ 202 "public/pw_rpc/internal/fake_channel_output.h", 203 "public/pw_rpc/internal/method_impl_tester.h", 204 "public/pw_rpc/internal/method_info_tester.h", 205 "public/pw_rpc/internal/test_method.h", 206 "public/pw_rpc/internal/test_method_context.h", 207 "public/pw_rpc/internal/test_utils.h", 208 "pw_rpc_private/fake_server_reader_writer.h", 209 ] 210 public_configs = [ ":public_include_path" ] 211 public_deps = [ 212 ":client", 213 ":server", 214 "$dir_pw_containers:vector", 215 "raw:fake_channel_output", 216 "raw:server_api", 217 dir_pw_assert, 218 dir_pw_bytes, 219 ] 220 visibility = [ "./*" ] 221} 222 223pw_source_set("integration_testing") { 224 public = [ 225 "public/pw_rpc/integration_test_socket_client.h", 226 "public/pw_rpc/integration_testing.h", 227 ] 228 sources = [ "integration_testing.cc" ] 229 public_deps = [ 230 ":client", 231 "$dir_pw_hdlc:pw_rpc", 232 "$dir_pw_hdlc:rpc_channel_output", 233 "$dir_pw_stream:socket_stream", 234 "$dir_pw_unit_test:logging_event_handler", 235 dir_pw_assert, 236 dir_pw_unit_test, 237 ] 238 deps = [ dir_pw_log ] 239} 240 241pw_executable("test_rpc_server") { 242 sources = [ "test_rpc_server.cc" ] 243 deps = [ 244 ":benchmark", 245 ":log_config", 246 "system_server", 247 "system_server:socket", 248 dir_pw_log, 249 ] 250} 251 252pw_executable("client_integration_test") { 253 sources = [ "client_integration_test.cc" ] 254 deps = [ 255 ":client", 256 ":integration_testing", 257 ":protos.raw_rpc", 258 "$dir_pw_sync:binary_semaphore", 259 dir_pw_log, 260 dir_pw_unit_test, 261 ] 262 263 if (dir_pw_third_party_nanopb != "") { 264 deps += [ "nanopb:client_integration_test" ] 265 } 266} 267 268pw_python_action("cpp_client_server_integration_test") { 269 script = "py/pw_rpc/testing.py" 270 args = [ 271 "--server", 272 "<TARGET_FILE(:test_rpc_server)>", 273 "--client", 274 "<TARGET_FILE(:client_integration_test)>", 275 "--", 276 "$pw_rpc_CPP_CLIENT_INTEGRATION_TEST_PORT", 277 ] 278 deps = [ 279 ":client_integration_test", 280 ":test_rpc_server", 281 ] 282 283 stamp = true 284} 285 286pw_proto_library("protos") { 287 sources = [ 288 "benchmark.proto", 289 "echo.proto", 290 "internal/packet.proto", 291 ] 292 inputs = [ 293 "echo.options", 294 "benchmark.options", 295 ] 296 deps = [ "$dir_pw_protobuf:common_protos" ] 297 python_package = "py" 298 prefix = "pw_rpc" 299} 300 301pw_doc_group("docs") { 302 sources = [ 303 "benchmark.rst", 304 "docs.rst", 305 ] 306 inputs = [ 307 "benchmark.proto", 308 "echo.proto", 309 "internal/packet.proto", 310 "unary_rpc.svg", 311 "unary_rpc_cancelled.svg", 312 "server_streaming_rpc.svg", 313 "server_streaming_rpc_cancelled.svg", 314 "client_streaming_rpc.svg", 315 "client_streaming_rpc_cancelled.svg", 316 "bidirectional_streaming_rpc.svg", 317 "bidirectional_streaming_rpc_cancelled.svg", 318 "request_packets.svg", 319 "response_packets.svg", 320 ] 321 group_deps = [ 322 "nanopb:docs", 323 "py:docs", 324 "ts:docs", 325 ] 326 report_deps = [ ":server_size" ] 327} 328 329pw_size_report("server_size") { 330 title = "Pigweed RPC server size report" 331 332 binaries = [ 333 { 334 target = "size_report:server_only" 335 base = "size_report:base" 336 label = "Server by itself" 337 }, 338 ] 339 340 if (dir_pw_third_party_nanopb != "") { 341 binaries += [ 342 { 343 target = "size_report:server_with_echo_service" 344 base = "size_report:base_with_nanopb" 345 label = "Server with a registered nanopb EchoService" 346 }, 347 ] 348 } 349} 350 351pw_test_group("tests") { 352 tests = [ 353 ":call_test", 354 ":channel_test", 355 ":client_server_test", 356 ":fake_channel_output_test", 357 ":method_test", 358 ":ids_test", 359 ":packet_test", 360 ":server_test", 361 ":service_test", 362 ] 363 group_deps = [ 364 "nanopb:tests", 365 "raw:tests", 366 ] 367} 368 369pw_proto_library("test_protos") { 370 sources = [ "pw_rpc_test_protos/test.proto" ] 371 inputs = [ "pw_rpc_test_protos/test.options" ] 372 visibility = [ "./*" ] 373} 374 375pw_test("call_test") { 376 deps = [ 377 ":server", 378 ":test_utils", 379 ] 380 sources = [ "call_test.cc" ] 381} 382 383pw_test("channel_test") { 384 deps = [ 385 ":server", 386 ":test_utils", 387 ] 388 sources = [ "channel_test.cc" ] 389} 390 391pw_python_action("generate_ids_test") { 392 outputs = [ "$target_gen_dir/generated_ids_test.cc" ] 393 394 script = "py/tests/ids_test.py" 395 args = [ "--generate-cc-test" ] + rebase_path(outputs, root_build_dir) 396 python_deps = [ 397 "$dir_pw_build/py", 398 "py", 399 ] 400} 401 402pw_test("ids_test") { 403 deps = [ 404 ":generate_ids_test", 405 ":server", 406 ] 407 sources = get_target_outputs(":generate_ids_test") 408} 409 410pw_test("packet_test") { 411 deps = [ 412 ":server", 413 dir_pw_bytes, 414 dir_pw_protobuf, 415 ] 416 sources = [ "packet_test.cc" ] 417} 418 419pw_test("service_test") { 420 deps = [ 421 ":protos.pwpb", 422 ":server", 423 dir_pw_assert, 424 ] 425 sources = [ "service_test.cc" ] 426} 427 428pw_test("client_server_test") { 429 deps = [ 430 ":client_server", 431 ":test_utils", 432 "raw:server_api", 433 ] 434 sources = [ "client_server_test.cc" ] 435} 436 437pw_test("method_test") { 438 deps = [ 439 ":server", 440 ":test_utils", 441 ] 442 sources = [ "method_test.cc" ] 443} 444 445pw_test("server_test") { 446 deps = [ 447 ":protos.pwpb", 448 ":server", 449 ":test_utils", 450 dir_pw_assert, 451 ] 452 sources = [ "server_test.cc" ] 453} 454 455pw_test("fake_channel_output_test") { 456 deps = [ ":test_utils" ] 457 sources = [ "fake_channel_output_test.cc" ] 458} 459