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("@rules_proto//proto:defs.bzl", "proto_library") 16load("@rules_python//python:proto.bzl", "py_proto_library") 17load("//pw_build:pigweed.bzl", "pw_cc_test") 18load("//pw_protobuf_compiler:pw_proto_library.bzl", "pw_proto_filegroup", "pw_proto_library") 19 20package(default_visibility = ["//visibility:public"]) 21 22licenses(["notice"]) 23 24proto_library( 25 name = "benchmark_proto", 26 srcs = [ 27 "benchmark.proto", 28 ], 29) 30 31pw_proto_library( 32 name = "benchmark_cc", 33 deps = [":benchmark_proto"], 34) 35 36cc_library( 37 name = "benchmark", 38 srcs = ["benchmark.cc"], 39 hdrs = ["public/pw_rpc/benchmark.h"], 40 includes = ["public"], 41 deps = [ 42 ":benchmark_cc.pwpb", 43 ":benchmark_cc.raw_rpc", 44 ], 45) 46 47# TODO: b/242059613 - Build this as a cc_binary and use it in integration tests. 48filegroup( 49 name = "test_rpc_server", 50 srcs = ["test_rpc_server.cc"], 51 # deps = [ 52 # "system_server", 53 # ":benchmark", 54 # "//pw_log", 55 # ], 56) 57 58cc_library( 59 name = "client_server", 60 srcs = ["client_server.cc"], 61 hdrs = ["public/pw_rpc/client_server.h"], 62 deps = [":pw_rpc"], 63) 64 65cc_library( 66 name = "pw_rpc", 67 srcs = [ 68 "call.cc", 69 "channel.cc", 70 "channel_list.cc", 71 "client.cc", 72 "client_call.cc", 73 "endpoint.cc", 74 "packet.cc", 75 "packet_meta.cc", 76 "public/pw_rpc/internal/call.h", 77 "public/pw_rpc/internal/call_context.h", 78 "public/pw_rpc/internal/channel.h", 79 "public/pw_rpc/internal/channel_list.h", 80 "public/pw_rpc/internal/client_call.h", 81 "public/pw_rpc/internal/encoding_buffer.h", 82 "public/pw_rpc/internal/endpoint.h", 83 "public/pw_rpc/internal/grpc.h", 84 "public/pw_rpc/internal/hash.h", 85 "public/pw_rpc/internal/lock.h", 86 "public/pw_rpc/internal/log_config.h", 87 "public/pw_rpc/internal/method.h", 88 "public/pw_rpc/internal/method_union.h", 89 "public/pw_rpc/internal/packet.h", 90 "public/pw_rpc/internal/server_call.h", 91 "public/pw_rpc/method_info.h", 92 "public/pw_rpc/writer.h", 93 "server.cc", 94 "server_call.cc", 95 "service.cc", 96 ], 97 hdrs = [ 98 "public/pw_rpc/channel.h", 99 "public/pw_rpc/client.h", 100 "public/pw_rpc/internal/config.h", 101 "public/pw_rpc/internal/method_info.h", 102 "public/pw_rpc/internal/method_lookup.h", 103 "public/pw_rpc/internal/service_client.h", 104 "public/pw_rpc/method_id.h", 105 "public/pw_rpc/method_info.h", 106 "public/pw_rpc/method_type.h", 107 "public/pw_rpc/packet_meta.h", 108 "public/pw_rpc/server.h", 109 "public/pw_rpc/service.h", 110 "public/pw_rpc/service_id.h", 111 ], 112 includes = ["public"], 113 deps = [ 114 ":config_override", 115 ":internal_packet_cc.pwpb", 116 "//pw_assert", 117 "//pw_bytes", 118 "//pw_containers:intrusive_list", 119 "//pw_function", 120 "//pw_log", 121 "//pw_preprocessor", 122 "//pw_result", 123 "//pw_span", 124 "//pw_status", 125 "//pw_sync:lock_annotations", 126 "//pw_sync:mutex", 127 "//pw_thread:sleep", 128 "//pw_toolchain:no_destructor", 129 ], 130) 131 132label_flag( 133 name = "config_override", 134 build_setting_default = "//pw_build:default_module_config", 135) 136 137cc_library( 138 name = "completion_request_callback_config_enabled", 139 defines = [ 140 "PW_RPC_COMPLETION_REQUEST_CALLBACK=1", 141 ], 142) 143 144config_setting( 145 name = "completion_request_callback_config_setting", 146 flag_values = { 147 ":config_override": ":completion_request_callback_config_enabled", 148 }, 149) 150 151cc_library( 152 name = "synchronous_client_api", 153 srcs = ["public/pw_rpc/internal/synchronous_call_impl.h"], 154 hdrs = [ 155 "public/pw_rpc/synchronous_call.h", 156 "public/pw_rpc/synchronous_call_result.h", 157 ], 158 includes = ["public"], 159 deps = [ 160 ":pw_rpc", 161 "//pw_chrono:system_clock", 162 "//pw_sync:timed_thread_notification", 163 ], 164) 165 166cc_library( 167 name = "client_server_testing", 168 hdrs = ["public/pw_rpc/internal/client_server_testing.h"], 169 includes = ["public"], 170 deps = [ 171 ":client_server", 172 ":internal_test_utils", 173 "//pw_bytes", 174 "//pw_result", 175 ], 176) 177 178cc_library( 179 name = "client_server_testing_threaded", 180 hdrs = ["public/pw_rpc/internal/client_server_testing_threaded.h"], 181 includes = ["public"], 182 deps = [ 183 ":client_server_testing", 184 "//pw_bytes", 185 "//pw_result", 186 "//pw_sync:binary_semaphore", 187 "//pw_sync:lock_annotations", 188 "//pw_sync:mutex", 189 "//pw_thread:thread", 190 ], 191) 192 193cc_library( 194 name = "test_helpers", 195 hdrs = ["public/pw_rpc/test_helpers.h"], 196 includes = ["public"], 197 deps = [ 198 ":internal_test_utils", 199 ":pw_rpc", 200 "//pw_assert", 201 "//pw_chrono:system_clock", 202 "//pw_status", 203 "//pw_sync:counting_semaphore", 204 "//pw_thread:yield", 205 ], 206) 207 208# thread_testing target is kept for backward compatibility. 209# New code should use test_helpers instead. 210cc_library( 211 name = "thread_testing", 212 hdrs = ["public/pw_rpc/thread_testing.h"], 213 includes = ["public"], 214 deps = [":test_helpers"], 215) 216 217cc_library( 218 name = "internal_test_utils", 219 srcs = ["fake_channel_output.cc"], 220 hdrs = [ 221 "public/pw_rpc/internal/fake_channel_output.h", 222 "public/pw_rpc/internal/method_impl_tester.h", 223 "public/pw_rpc/internal/method_info_tester.h", 224 "public/pw_rpc/internal/test_method_context.h", 225 "public/pw_rpc/internal/test_utils.h", 226 "public/pw_rpc/payloads_view.h", 227 "pw_rpc_private/fake_server_reader_writer.h", 228 "pw_rpc_private/test_method.h", 229 ], 230 includes = [ 231 ".", 232 "public", 233 ], 234 visibility = [":__subpackages__"], 235 deps = [ 236 ":pw_rpc", 237 "//pw_assert", 238 "//pw_bytes", 239 "//pw_containers:filtered_view", 240 "//pw_containers:vector", 241 "//pw_containers:wrapped_iterator", 242 "//pw_rpc/raw:fake_channel_output", 243 "//pw_span", 244 "//pw_sync:mutex", 245 ], 246) 247 248cc_library( 249 name = "integration_testing", 250 testonly = True, 251 srcs = [ 252 "integration_testing.cc", 253 ], 254 hdrs = [ 255 "public/pw_rpc/integration_test_socket_client.h", 256 "public/pw_rpc/integration_testing.h", 257 ], 258 deps = [ 259 ":pw_rpc", 260 "//pw_assert", 261 "//pw_hdlc", 262 "//pw_hdlc:default_addresses", 263 "//pw_hdlc:rpc_channel_output", 264 "//pw_log", 265 "//pw_stream:socket_stream", 266 "//pw_unit_test", 267 "//pw_unit_test:logging", 268 ], 269) 270 271# TODO: b/242059613 - Add the client integration test to the build. 272filegroup( 273 name = "client_integration_test", 274 srcs = ["client_integration_test.cc"], 275) 276 277pw_cc_test( 278 name = "call_test", 279 srcs = [ 280 "call_test.cc", 281 ], 282 deps = [ 283 ":internal_test_utils", 284 ":pw_rpc", 285 ], 286) 287 288pw_cc_test( 289 name = "callback_test", 290 srcs = ["callback_test.cc"], 291 deps = [ 292 ":pw_rpc", 293 ":pw_rpc_test_cc.raw_rpc", 294 "//pw_rpc/raw:client_testing", 295 "//pw_sync:binary_semaphore", 296 "//pw_thread:non_portable_test_thread_options", 297 "//pw_thread:sleep", 298 "//pw_thread:yield", 299 "//pw_thread_stl:non_portable_test_thread_options", 300 ], 301) 302 303pw_cc_test( 304 name = "channel_test", 305 srcs = ["channel_test.cc"], 306 deps = [ 307 ":internal_test_utils", 308 ":pw_rpc", 309 ], 310) 311 312pw_cc_test( 313 name = "method_test", 314 srcs = ["method_test.cc"], 315 deps = [ 316 ":internal_test_utils", 317 ":pw_rpc", 318 ], 319) 320 321pw_cc_test( 322 name = "packet_test", 323 srcs = [ 324 "packet_test.cc", 325 ], 326 deps = [ 327 ":pw_rpc", 328 "//pw_fuzzer:fuzztest", 329 ], 330) 331 332pw_cc_test( 333 name = "packet_meta_test", 334 srcs = [ 335 "packet_meta_test.cc", 336 ], 337 deps = [ 338 ":pw_rpc", 339 "//pw_fuzzer:fuzztest", 340 ], 341) 342 343pw_cc_test( 344 name = "client_server_test", 345 srcs = ["client_server_test.cc"], 346 deps = [ 347 ":client_server", 348 ":internal_test_utils", 349 "//pw_rpc/raw:server_api", 350 ], 351) 352 353pw_cc_test( 354 name = "server_test", 355 srcs = [ 356 "server_test.cc", 357 ], 358 deps = [ 359 ":internal_test_utils", 360 ":pw_rpc", 361 "//pw_assert", 362 ], 363) 364 365pw_cc_test( 366 name = "service_test", 367 srcs = [ 368 "service_test.cc", 369 ], 370 deps = [ 371 ":internal_test_utils", 372 ":pw_rpc", 373 "//pw_assert", 374 ], 375) 376 377pw_cc_test( 378 name = "fake_channel_output_test", 379 srcs = ["fake_channel_output_test.cc"], 380 deps = [":internal_test_utils"], 381) 382 383pw_cc_test( 384 name = "test_helpers_test", 385 srcs = ["test_helpers_test.cc"], 386 deps = [ 387 ":test_helpers", 388 "//pw_result", 389 "//pw_rpc/pwpb:client_testing", 390 "//pw_rpc/pwpb:echo_service", 391 "//pw_rpc/pwpb:server_api", 392 "//pw_status", 393 "//pw_sync:interrupt_spin_lock", 394 "//pw_sync:lock_annotations", 395 "//pw_sync:timed_thread_notification", 396 ], 397) 398 399proto_library( 400 name = "internal_packet_proto", 401 srcs = ["internal/packet.proto"], 402 visibility = [":__subpackages__"], 403) 404 405java_proto_library( 406 name = "packet_proto_java", 407 deps = [":internal_packet_proto"], 408) 409 410java_lite_proto_library( 411 name = "packet_proto_java_lite", 412 deps = [":internal_packet_proto"], 413) 414 415py_proto_library( 416 name = "internal_packet_proto_pb2", 417 deps = [":internal_packet_proto"], 418) 419 420pw_proto_library( 421 name = "internal_packet_cc", 422 deps = [":internal_packet_proto"], 423) 424 425proto_library( 426 name = "pw_rpc_test_proto", 427 srcs = [ 428 "pw_rpc_test_protos/no_package.proto", 429 "pw_rpc_test_protos/test.proto", 430 ], 431 strip_import_prefix = "/pw_rpc", 432) 433 434pw_proto_library( 435 name = "pw_rpc_test_cc", 436 deps = [":pw_rpc_test_proto"], 437) 438 439pw_proto_filegroup( 440 name = "echo_proto_and_options", 441 srcs = ["echo.proto"], 442 options_files = ["echo.options"], 443) 444 445proto_library( 446 name = "echo_proto", 447 srcs = [":echo_proto_and_options"], 448) 449 450py_proto_library( 451 name = "echo_py_pb2", 452 deps = [":echo_proto"], 453) 454 455pw_proto_library( 456 name = "echo_cc", 457 deps = [":echo_proto"], 458) 459