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