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