1# Copyright 2020 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 15load("@com_google_protobuf//bazel:java_lite_proto_library.bzl", "java_lite_proto_library") 16load("@com_google_protobuf//bazel:java_proto_library.bzl", "java_proto_library") 17load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") 18load("@rules_cc//cc:cc_library.bzl", "cc_library") 19load("@rules_python//python:proto.bzl", "py_proto_library") 20load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library") 21load("//pw_build:compatibility.bzl", "incompatible_with_mcu") 22load("//pw_build:copy_to_bin.bzl", "copy_to_bin") 23load( 24 "//pw_protobuf_compiler:pw_proto_library.bzl", 25 "nanopb_proto_library", 26 "nanopb_rpc_proto_library", 27 "pw_proto_filegroup", 28 "pwpb_proto_library", 29 "pwpb_rpc_proto_library", 30 "raw_rpc_proto_library", 31) 32load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test") 33 34package( 35 default_visibility = ["//visibility:public"], 36 features = ["-layering_check"], 37) 38 39licenses(["notice"]) 40 41pw_proto_filegroup( 42 name = "benchmark_proto_and_options", 43 srcs = ["benchmark.proto"], 44 options_files = [ 45 "benchmark.options", 46 "benchmark.pwpb_options", 47 ], 48) 49 50proto_library( 51 name = "benchmark_proto", 52 srcs = [":benchmark_proto_and_options"], 53) 54 55pwpb_proto_library( 56 name = "benchmark_pwpb", 57 deps = [":benchmark_proto"], 58) 59 60raw_rpc_proto_library( 61 name = "benchmark_raw_rpc", 62 deps = [":benchmark_proto"], 63) 64 65cc_library( 66 name = "benchmark", 67 srcs = ["benchmark.cc"], 68 hdrs = ["public/pw_rpc/benchmark.h"], 69 strip_include_prefix = "public", 70 deps = [ 71 ":benchmark_pwpb", 72 ":benchmark_raw_rpc", 73 ], 74) 75 76# TODO: b/242059613 - Build this as a cc_binary and use it in integration tests. 77filegroup( 78 name = "test_rpc_server", 79 srcs = ["test_rpc_server.cc"], 80 # deps = [ 81 # "system_server", 82 # ":benchmark", 83 # "//pw_log", 84 # ], 85) 86 87cc_library( 88 name = "client_server", 89 srcs = ["client_server.cc"], 90 hdrs = ["public/pw_rpc/client_server.h"], 91 strip_include_prefix = "public", 92 deps = [":pw_rpc"], 93) 94 95# See https://pigweed.dev/pw_rpc/cpp.html#c.PW_RPC_YIELD_MODE for documentation. 96constraint_setting( 97 name = "yield_mode", 98 default_constraint_value = ":yield_mode_sleep", 99) 100 101constraint_value( 102 name = "yield_mode_busy_loop", 103 constraint_setting = ":yield_mode", 104) 105 106constraint_value( 107 name = "yield_mode_sleep", 108 constraint_setting = ":yield_mode", 109) 110 111constraint_value( 112 name = "yield_mode_yield", 113 constraint_setting = ":yield_mode", 114) 115 116cc_library( 117 name = "pw_rpc", 118 srcs = [ 119 "call.cc", 120 "channel.cc", 121 "channel_list.cc", 122 "client.cc", 123 "client_call.cc", 124 "endpoint.cc", 125 "packet.cc", 126 "packet_meta.cc", 127 "server.cc", 128 "server_call.cc", 129 "service.cc", 130 ], 131 hdrs = [ 132 "public/pw_rpc/channel.h", 133 "public/pw_rpc/client.h", 134 "public/pw_rpc/internal/call.h", 135 "public/pw_rpc/internal/call_context.h", 136 "public/pw_rpc/internal/channel_list.h", 137 "public/pw_rpc/internal/client_call.h", 138 "public/pw_rpc/internal/config.h", 139 "public/pw_rpc/internal/encoding_buffer.h", 140 "public/pw_rpc/internal/endpoint.h", 141 "public/pw_rpc/internal/grpc.h", 142 "public/pw_rpc/internal/hash.h", 143 "public/pw_rpc/internal/lock.h", 144 "public/pw_rpc/internal/log_config.h", 145 "public/pw_rpc/internal/method.h", 146 "public/pw_rpc/internal/method_info.h", 147 "public/pw_rpc/internal/method_lookup.h", 148 "public/pw_rpc/internal/method_union.h", 149 "public/pw_rpc/internal/packet.h", 150 "public/pw_rpc/internal/server_call.h", 151 "public/pw_rpc/internal/service_client.h", 152 "public/pw_rpc/method_id.h", 153 "public/pw_rpc/method_info.h", 154 "public/pw_rpc/method_type.h", 155 "public/pw_rpc/packet_meta.h", 156 "public/pw_rpc/server.h", 157 "public/pw_rpc/service.h", 158 "public/pw_rpc/service_id.h", 159 "public/pw_rpc/writer.h", 160 ], 161 # LINT.IfChange 162 defines = select({ 163 ":yield_mode_busy_loop": ["PW_RPC_YIELD_MODE=PW_RPC_YIELD_MODE_BUSY_LOOP"], 164 ":yield_mode_sleep": ["PW_RPC_YIELD_MODE=PW_RPC_YIELD_MODE_SLEEP"], 165 ":yield_mode_yield": ["PW_RPC_YIELD_MODE=PW_RPC_YIELD_MODE_YIELD"], 166 }), 167 # LINT.ThenChange(//pw_rpc/public/pw_rpc/internal/config.h) 168 implementation_deps = ["//pw_assert:check"], 169 strip_include_prefix = "public", 170 deps = [ 171 ":config_override", 172 ":internal_packet_pwpb", 173 "//pw_assert:assert", 174 "//pw_bytes", 175 "//pw_containers:intrusive_list", 176 "//pw_function", 177 "//pw_log", 178 "//pw_polyfill", 179 "//pw_preprocessor", 180 "//pw_result", 181 "//pw_span", 182 "//pw_status", 183 "//pw_sync:lock_annotations", 184 "//pw_sync:mutex", 185 "//pw_toolchain:no_destructor", 186 ] + select({ 187 ":yield_mode_busy_loop": [], 188 ":yield_mode_sleep": ["//pw_thread:sleep"], 189 ":yield_mode_yield": ["//pw_thread:yield"], 190 }), 191) 192 193label_flag( 194 name = "config_override", 195 build_setting_default = "//pw_build:default_module_config", 196) 197 198cc_library( 199 name = "completion_request_callback_config_enabled", 200 defines = [ 201 "PW_RPC_COMPLETION_REQUEST_CALLBACK=1", 202 ], 203) 204 205config_setting( 206 name = "completion_request_callback_config_setting", 207 flag_values = { 208 ":config_override": ":completion_request_callback_config_enabled", 209 }, 210) 211 212cc_library( 213 name = "synchronous_client_api", 214 hdrs = [ 215 "public/pw_rpc/internal/synchronous_call_impl.h", 216 "public/pw_rpc/synchronous_call.h", 217 "public/pw_rpc/synchronous_call_result.h", 218 ], 219 strip_include_prefix = "public", 220 tags = ["noclangtidy"], 221 deps = [ 222 ":pw_rpc", 223 "//pw_assert:assert", 224 "//pw_chrono:system_clock", 225 "//pw_sync:timed_thread_notification", 226 ], 227) 228 229cc_library( 230 name = "client_server_testing", 231 hdrs = ["public/pw_rpc/internal/client_server_testing.h"], 232 strip_include_prefix = "public", 233 deps = [ 234 ":client_server", 235 ":internal_test_utils", 236 "//pw_bytes", 237 "//pw_result", 238 ], 239) 240 241cc_library( 242 name = "client_server_testing_threaded", 243 hdrs = ["public/pw_rpc/internal/client_server_testing_threaded.h"], 244 strip_include_prefix = "public", 245 deps = [ 246 ":client_server_testing", 247 "//pw_bytes", 248 "//pw_result", 249 "//pw_sync:binary_semaphore", 250 "//pw_sync:lock_annotations", 251 "//pw_sync:mutex", 252 "//pw_thread:thread", 253 ], 254) 255 256cc_library( 257 name = "test_helpers", 258 hdrs = ["public/pw_rpc/test_helpers.h"], 259 strip_include_prefix = "public", 260 deps = [ 261 ":internal_test_utils", 262 ":pw_rpc", 263 "//pw_assert:assert", 264 "//pw_chrono:system_clock", 265 "//pw_status", 266 "//pw_sync:counting_semaphore", 267 "//pw_thread:yield", 268 ], 269) 270 271# thread_testing target is kept for backward compatibility. 272# New code should use test_helpers instead. 273cc_library( 274 name = "thread_testing", 275 hdrs = ["public/pw_rpc/thread_testing.h"], 276 strip_include_prefix = "public", 277 deps = [":test_helpers"], 278) 279 280cc_library( 281 name = "internal_test_utils", 282 srcs = ["fake_channel_output.cc"], 283 hdrs = [ 284 "public/pw_rpc/internal/fake_channel_output.h", 285 "public/pw_rpc/internal/method_impl_tester.h", 286 "public/pw_rpc/internal/method_info_tester.h", 287 "public/pw_rpc/internal/test_method_context.h", 288 "public/pw_rpc/internal/test_utils.h", 289 "public/pw_rpc/payloads_view.h", 290 "pw_rpc_private/fake_server_reader_writer.h", 291 "pw_rpc_private/test_method.h", 292 ], 293 implementation_deps = ["//pw_assert:check"], 294 includes = [ 295 ".", 296 "public", 297 ], 298 tags = ["noclangtidy"], 299 visibility = [":__subpackages__"], 300 deps = [ 301 ":pw_rpc", 302 "//pw_assert:assert", 303 "//pw_bytes", 304 "//pw_containers:filtered_view", 305 "//pw_containers:vector", 306 "//pw_containers:wrapped_iterator", 307 "//pw_rpc/raw:fake_channel_output", 308 "//pw_span", 309 "//pw_sync:mutex", 310 ], 311) 312 313cc_library( 314 name = "integration_testing", 315 testonly = True, 316 srcs = [ 317 "integration_testing.cc", 318 ], 319 hdrs = [ 320 "public/pw_rpc/integration_test_socket_client.h", 321 "public/pw_rpc/integration_testing.h", 322 ], 323 strip_include_prefix = "public", 324 deps = [ 325 ":pw_rpc", 326 "//pw_hdlc", 327 "//pw_hdlc:default_addresses", 328 "//pw_hdlc:rpc_channel_output", 329 "//pw_log", 330 "//pw_stream:socket_stream", 331 "//pw_unit_test", 332 "//pw_unit_test:logging", 333 ], 334) 335 336# TODO: b/242059613 - Add the client integration test to the build. 337filegroup( 338 name = "client_integration_test", 339 srcs = ["client_integration_test.cc"], 340) 341 342pw_cc_test( 343 name = "call_test", 344 srcs = [ 345 "call_test.cc", 346 ], 347 deps = [ 348 ":internal_test_utils", 349 ":pw_rpc", 350 ], 351) 352 353pw_cc_test( 354 name = "callback_test", 355 srcs = ["callback_test.cc"], 356 deps = [ 357 ":pw_rpc", 358 ":pw_rpc_test_raw_rpc", 359 "//pw_rpc/raw:client_testing", 360 "//pw_sync:binary_semaphore", 361 "//pw_thread:non_portable_test_thread_options", 362 "//pw_thread:sleep", 363 "//pw_thread:yield", 364 "//pw_thread_stl:non_portable_test_thread_options", 365 ], 366) 367 368pw_cc_test( 369 name = "channel_test", 370 srcs = ["channel_test.cc"], 371 deps = [ 372 ":internal_test_utils", 373 ":pw_rpc", 374 ], 375) 376 377pw_cc_test( 378 name = "method_test", 379 srcs = ["method_test.cc"], 380 deps = [ 381 ":internal_test_utils", 382 ":pw_rpc", 383 ], 384) 385 386pw_cc_test( 387 name = "packet_test", 388 srcs = [ 389 "packet_test.cc", 390 ], 391 deps = [ 392 ":pw_rpc", 393 "//pw_fuzzer:fuzztest", 394 ], 395) 396 397pw_cc_test( 398 name = "packet_meta_test", 399 srcs = [ 400 "packet_meta_test.cc", 401 ], 402 deps = [ 403 ":pw_rpc", 404 "//pw_fuzzer:fuzztest", 405 ], 406) 407 408pw_cc_test( 409 name = "client_server_test", 410 srcs = ["client_server_test.cc"], 411 deps = [ 412 ":client_server", 413 ":internal_test_utils", 414 "//pw_rpc/raw:server_api", 415 ], 416) 417 418pw_cc_test( 419 name = "server_test", 420 srcs = [ 421 "server_test.cc", 422 ], 423 deps = [ 424 ":internal_test_utils", 425 ":pw_rpc", 426 "//pw_assert:check", 427 ], 428) 429 430pw_cc_test( 431 name = "service_test", 432 srcs = [ 433 "service_test.cc", 434 ], 435 deps = [ 436 ":internal_test_utils", 437 ":pw_rpc", 438 ], 439) 440 441pw_cc_test( 442 name = "fake_channel_output_test", 443 srcs = ["fake_channel_output_test.cc"], 444 deps = [":internal_test_utils"], 445) 446 447pw_cc_test( 448 name = "test_helpers_test", 449 srcs = ["test_helpers_test.cc"], 450 deps = [ 451 ":test_helpers", 452 "//pw_containers:vector", 453 "//pw_result", 454 "//pw_rpc/pwpb:client_testing", 455 "//pw_rpc/pwpb:echo_service", 456 "//pw_rpc/pwpb:server_api", 457 "//pw_status", 458 "//pw_sync:interrupt_spin_lock", 459 "//pw_sync:lock_annotations", 460 "//pw_sync:timed_thread_notification", 461 ], 462) 463 464proto_library( 465 name = "internal_packet_proto", 466 srcs = ["internal/packet.proto"], 467) 468 469java_proto_library( 470 name = "packet_proto_java", 471 deps = [":internal_packet_proto"], 472) 473 474java_lite_proto_library( 475 name = "packet_proto_java_lite", 476 deps = [":internal_packet_proto"], 477) 478 479py_proto_library( 480 name = "internal_packet_proto_pb2", 481 deps = [":internal_packet_proto"], 482) 483 484pwpb_proto_library( 485 name = "internal_packet_pwpb", 486 deps = [":internal_packet_proto"], 487) 488 489proto_library( 490 name = "pw_rpc_test_proto", 491 srcs = [ 492 "pw_rpc_test_protos/no_package.proto", 493 "pw_rpc_test_protos/test.proto", 494 ], 495 strip_import_prefix = "/pw_rpc", 496) 497 498nanopb_proto_library( 499 name = "pw_rpc_test_nanopb", 500 deps = [":pw_rpc_test_proto"], 501) 502 503nanopb_rpc_proto_library( 504 name = "pw_rpc_test_nanopb_rpc", 505 nanopb_proto_library_deps = [":pw_rpc_test_nanopb"], 506 deps = [":pw_rpc_test_proto"], 507) 508 509pwpb_proto_library( 510 name = "pw_rpc_test_pwpb", 511 deps = [":pw_rpc_test_proto"], 512) 513 514pwpb_rpc_proto_library( 515 name = "pw_rpc_test_pwpb_rpc", 516 pwpb_proto_library_deps = [":pw_rpc_test_pwpb"], 517 deps = [":pw_rpc_test_proto"], 518) 519 520raw_rpc_proto_library( 521 name = "pw_rpc_test_raw_rpc", 522 deps = [":pw_rpc_test_proto"], 523) 524 525pw_proto_filegroup( 526 name = "echo_proto_and_options", 527 srcs = ["echo.proto"], 528 options_files = [ 529 "echo.options", 530 "echo.pwpb_options", 531 ], 532) 533 534proto_library( 535 name = "echo_proto", 536 srcs = [":echo_proto_and_options"], 537) 538 539py_proto_library( 540 name = "echo_py_pb2", 541 deps = [":echo_proto"], 542) 543 544nanopb_proto_library( 545 name = "echo_nanopb", 546 deps = [":echo_proto"], 547) 548 549nanopb_rpc_proto_library( 550 name = "echo_nanopb_rpc", 551 nanopb_proto_library_deps = [":echo_nanopb"], 552 deps = [":echo_proto"], 553) 554 555pwpb_proto_library( 556 name = "echo_pwpb", 557 deps = [":echo_proto"], 558) 559 560pwpb_rpc_proto_library( 561 name = "echo_pwpb_rpc", 562 pwpb_proto_library_deps = [":echo_pwpb"], 563 deps = [":echo_proto"], 564) 565 566filegroup( 567 name = "doxygen", 568 srcs = [ 569 "public/pw_rpc/channel.h", 570 "public/pw_rpc/internal/config.h", 571 "public/pw_rpc/synchronous_call.h", 572 ], 573) 574 575sphinx_docs_library( 576 name = "docs", 577 srcs = [ 578 "Kconfig", 579 "benchmark.proto", 580 "cpp.rst", 581 "design.rst", 582 "docs.rst", 583 "echo.proto", 584 "guides.rst", 585 "internal/packet.proto", 586 "libraries.rst", 587 "protocol.rst", 588 "//pw_rpc/nanopb:docs", 589 "//pw_rpc/pwpb:docs", 590 "//pw_rpc/py:docs", 591 "//pw_rpc/ts:docs", 592 ], 593 prefix = "pw_rpc/", 594 target_compatible_with = incompatible_with_mcu(), 595) 596 597copy_to_bin( 598 name = "js_protos", 599 srcs = [ 600 "echo.proto", 601 "internal/packet.proto", 602 ], 603) 604