• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2022 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
15package {
16    default_applicable_licenses: ["external_pigweed_license"],
17}
18
19java_library {
20    name: "pw_rpc_java_client",
21    srcs: ["java/main/dev/pigweed/pw_rpc/*.java"],
22    visibility: ["//visibility:public"],
23    static_libs: [
24        "pw_log_android_java",
25        "pw_rpc_packet_proto_java_lite",
26    ],
27    libs: [
28        "auto_value_annotations",
29        "guava",
30        "jsr305",
31        "libprotobuf-java-lite",
32    ],
33    plugins: ["auto_value_plugin"],
34    sdk_version: "current",
35}
36
37java_library_static {
38    name: "pw_rpc_packet_proto_java_lite",
39    host_supported: true,
40    proto: {
41        type: "lite",
42    },
43    srcs: ["internal/packet.proto"],
44    sdk_version: "current",
45}
46
47java_library_static {
48    name: "pw_rpc_echo_proto_java_lite",
49    visibility: ["//visibility:public"],
50    host_supported: true,
51    proto: {
52        type: "lite",
53    },
54    srcs: ["echo.proto"],
55    sdk_version: "current",
56}
57
58filegroup {
59    name: "pw_rpc_src_files",
60    srcs: [
61        "call.cc",
62        "channel.cc",
63        "channel_list.cc",
64        "client.cc",
65        "client_call.cc",
66        "client_server.cc",
67        "endpoint.cc",
68        "fake_channel_output.cc",
69        "packet.cc",
70        "packet_meta.cc",
71        "server.cc",
72        "server_call.cc",
73        "service.cc",
74    ],
75}
76
77// Do not use this directly. It is used by the pw_rpc_defaults to keep the
78// path to the "public" directory relative to this module.
79cc_library_headers {
80    name: "pw_rpc_include_dirs",
81    export_include_dirs: [
82        "public",
83    ],
84    vendor_available: true,
85    host_supported: true,
86}
87
88// This rule must be instantiated, i.e.
89//
90//   cc_library_static {
91//       name: "pw_rpc_<instance_name>",
92//       defaults: [
93//           "pw_rpc_cflags_<instance_name>",
94//           "pw_rpc_defaults",
95//       ],
96//   }
97//
98// where pw_rpc_cflags_<instance_name> defines your flags, i.e.
99//
100//   cc_defaults {
101//       name: "pw_rpc_cflags_<instance_name>",
102//       cflags: [
103//           "-DPW_RPC_USE_GLOBAL_MUTEX=0",
104//           "-DPW_RPC_COMPLETION_REQUEST_CALLBACK",
105//           "-DPW_RPC_DYNAMIC_ALLOCATION",
106//       ],
107//   }
108//
109// see pw_rpc_nanopb_defaults, pw_rpc_raw_defaults
110cc_defaults {
111    name: "pw_rpc_defaults",
112    cpp_std: "c++20",
113    defaults: [
114        "pw_android_common_backends",
115    ],
116    header_libs: [
117        "fuchsia_sdk_lib_fit",
118        "fuchsia_sdk_lib_stdcompat",
119        "pw_assert",
120        "pw_log",
121        "pw_rpc_include_dirs",
122        "pw_sync",
123    ],
124    export_header_lib_headers: [
125        "fuchsia_sdk_lib_fit",
126        "fuchsia_sdk_lib_stdcompat",
127        "pw_assert",
128        "pw_log",
129        "pw_rpc_include_dirs",
130        "pw_sync",
131    ],
132    static_libs: [
133        "pw_bytes",
134        "pw_containers",
135        "pw_function",
136        "pw_polyfill",
137        "pw_preprocessor",
138        "pw_protobuf",
139        "pw_result",
140        "pw_span",
141        "pw_status",
142        "pw_stream",
143        "pw_string",
144        "pw_sync_baremetal",
145        "pw_toolchain",
146        "pw_varint",
147    ],
148    export_static_lib_headers: [
149        "pw_bytes",
150        "pw_containers",
151        "pw_function",
152        "pw_polyfill",
153        "pw_preprocessor",
154        "pw_protobuf",
155        "pw_result",
156        "pw_span",
157        "pw_status",
158        "pw_stream",
159        "pw_string",
160        "pw_sync_baremetal",
161        "pw_toolchain",
162        "pw_varint",
163    ],
164    generated_headers: [
165        "pw_rpc_internal_packet_pwpb_h",
166    ],
167    export_generated_headers: [
168        "pw_rpc_internal_packet_pwpb_h",
169    ],
170    srcs: [
171        ":pw_rpc_src_files",
172    ],
173}
174
175genrule {
176    name: "pw_rpc_internal_packet_pwpb_h",
177    srcs: ["internal/packet.proto"],
178    cmd: "python3 $(location pw_protobuf_compiler_py) " +
179        "--out-dir=$$(dirname $(location pw_rpc/internal/packet.pwpb.h)) " +
180        "--plugin-path=$(location pw_protobuf_plugin_py) " +
181        "--compile-dir=$$(dirname $(in)) " +
182        "--sources $(in) " +
183        "--language pwpb " +
184        "--no-experimental-proto3-optional " +
185        "--protoc=$(location aprotoc) ",
186    out: [
187        "pw_rpc/internal/packet.pwpb.h",
188    ],
189    tools: [
190        "aprotoc",
191        "pw_protobuf_plugin_py",
192        "pw_protobuf_compiler_py",
193    ],
194}
195
196genrule {
197    name: "pw_rpc_internal_packet_py",
198    srcs: ["internal/packet.proto"],
199    cmd: "python3 $(location pw_protobuf_compiler_py) " +
200        "--out-dir=$(genDir) " +
201        "--compile-dir=$$(dirname $(in)) " +
202        "--sources $(in) " +
203        "--language python " +
204        "--no-generate-type-hints " +
205        "--no-experimental-proto3-optional " +
206        "--protoc=$(location aprotoc)",
207    out: [
208        "packet_pb2.py",
209    ],
210    tools: [
211        "aprotoc",
212        "pw_protobuf_compiler_py",
213    ],
214}
215
216// Generate cc and header nanopb files.
217// The output file names are based on the srcs file name with a .pb.c / .pb.h extension.
218genrule_defaults {
219    name: "pw_rpc_generate_nanopb_proto",
220    cmd: "in_files=($(in)); compile_dir=$$(dirname $${in_files[0]}); " +
221        "python3 $(location pw_protobuf_compiler_py) " +
222        "--plugin-path=$(location protoc-gen-nanopb) " +
223        "--out-dir=$(genDir) " +
224        "--compile-dir=$${compile_dir} " +
225        "--language nanopb " +
226        "--sources $(in) " +
227        "--no-experimental-proto3-optional " +
228        "--protoc=$(location aprotoc)",
229    tools: [
230        "aprotoc",
231        "protoc-gen-nanopb",
232        "pw_protobuf_compiler_py",
233    ],
234}
235
236// Same as pw_rpc_generate_nanopb_proto but the proto files are compiled with a
237// single prefix, which can be added with pw_rpc_add_prefix_to_proto.
238// Since pw_rpc_add_prefix_to_proto may include .option files as an input, only
239// .proto files are passed to the compile script. Make sure .option files are
240// prefixed in the same rule as their .proto files.
241//
242// See the pw_rpc_echo_service_nanopb target for an example. The echo.proto file
243// is compiled with "pw_rpc" as the prefix.
244genrule_defaults {
245    name: "pw_rpc_generate_nanopb_proto_with_prefix",
246    cmd: "in_files=($(in)); prefix_dir=$$(dirname $${in_files[0]}); " +
247        "compile_dir=$$(dirname $${prefix_dir}); proto_files=(); " +
248        "for f in \"$${in_files[@]}\"; do " +
249        "if [[ \"$${f##*.}\" == \"proto\" ]]; then " +
250        "proto_files+=(\"$${f}\"); fi; done; " +
251        "python3 $(location pw_protobuf_compiler_py) " +
252        "--plugin-path=$(location protoc-gen-nanopb) " +
253        "--out-dir=$(genDir) " +
254        "--compile-dir=$${compile_dir} " +
255        "--language nanopb " +
256        "--sources $${proto_files} " +
257        "--no-experimental-proto3-optional " +
258        "--protoc=$(location aprotoc)",
259    tools: [
260        "aprotoc",
261        "protoc-gen-nanopb",
262        "pw_protobuf_compiler_py",
263    ],
264}
265
266// Generate the header nanopb RPC file.
267// The output file name is based on the srcs file name with a .rpc.pb.h extension.
268genrule_defaults {
269    name: "pw_rpc_generate_nanopb_rpc_header",
270    cmd: "in_files=($(in)); compile_dir=$$(dirname $${in_files[0]}); " +
271        "python3 $(location pw_protobuf_compiler_py) " +
272        "--plugin-path=$(location pw_rpc_plugin_nanopb_py) " +
273        "--out-dir=$(genDir) " +
274        "--compile-dir=$${compile_dir} " +
275        "--language nanopb_rpc " +
276        "--sources $(in) " +
277        "--no-experimental-proto3-optional " +
278        "--protoc=$(location aprotoc)",
279    tools: [
280        "aprotoc",
281        "pw_protobuf_compiler_py",
282        "pw_rpc_plugin_nanopb_py",
283    ],
284}
285
286// Same as pw_rpc_generate_nanopb_rpc_header but the proto files are compiled
287// with a single prefix, which can be added with pw_rpc_add_prefix_to_proto.
288// Since pw_rpc_add_prefix_to_proto may include .option files as an input, only
289// .proto files are passed to the compile script. Make sure .option files are
290// prefixed in the same rule as their .proto files.
291//
292// See the pw_rpc_echo_service_nanopb target for an example. The echo.proto file
293// is compiled with "pw_rpc" as the prefix.
294genrule_defaults {
295    name: "pw_rpc_generate_nanopb_rpc_header_with_prefix",
296    cmd: "in_files=($(in)); prefix_dir=$$(dirname $${in_files[0]}); " +
297        "compile_dir=$$(dirname $${prefix_dir}); proto_files=(); " +
298        "for f in \"$${in_files[@]}\"; do " +
299        "if [[ \"$${f##*.}\" == \"proto\" ]]; then " +
300        "proto_files+=(\"$${f}\"); fi; done; " +
301        "python3 $(location pw_protobuf_compiler_py) " +
302        "--plugin-path=$(location pw_rpc_plugin_nanopb_py) " +
303        "--out-dir=$(genDir) " +
304        "--compile-dir=$${compile_dir} " +
305        "--language nanopb_rpc " +
306        "--sources $${proto_files} " +
307        "--no-experimental-proto3-optional " +
308        "--protoc=$(location aprotoc)",
309    tools: [
310        "aprotoc",
311        "pw_protobuf_compiler_py",
312        "pw_rpc_plugin_nanopb_py",
313    ],
314}
315
316// Generate the header raw RPC file.
317// The output file name is based on the srcs file name with a .raw_rpc.pb.h extension.
318genrule_defaults {
319    name: "pw_rpc_generate_raw_rpc_header",
320    cmd: "in_files=($(in)); compile_dir=$$(dirname $${in_files[0]}); " +
321        "python3 $(location pw_protobuf_compiler_py) " +
322        "--plugin-path=$(location pw_rpc_plugin_rawpb_py) " +
323        "--out-dir=$(genDir) " +
324        "--compile-dir=$${compile_dir} " +
325        "--language raw_rpc " +
326        "--sources $(in) " +
327        "--no-experimental-proto3-optional " +
328        "--protoc=$(location aprotoc)",
329    tools: [
330        "aprotoc",
331        "pw_protobuf_compiler_py",
332        "pw_rpc_plugin_rawpb_py",
333    ],
334}
335
336// Same as pw_rpc_generate_raw_rpc_header but the proto files are compiled with
337// a single prefix, which can be added with pw_rpc_add_prefix_to_proto.
338// Since pw_rpc_add_prefix_to_proto may include .option files as an input, only
339// .proto files are passed to the compile script. Make sure .option files are
340// prefixed in the same rule as their .proto files.
341//
342// See the pw_rpc_echo_service_pwpb target for an example. The echo.proto file
343// is compiled with "pw_rpc" as the prefix.
344genrule_defaults {
345    name: "pw_rpc_generate_raw_rpc_header_with_prefix",
346    cmd: "in_files=($(in)); prefix_dir=$$(dirname $${in_files[0]}); " +
347        "compile_dir=$$(dirname $${prefix_dir}); proto_files=(); " +
348        "for f in \"$${in_files[@]}\"; do " +
349        "if [[ \"$${f##*.}\" == \"proto\" ]]; then " +
350        "proto_files+=(\"$${f}\"); fi; done; " +
351        "python3 $(location pw_protobuf_compiler_py) " +
352        "--plugin-path=$(location pw_rpc_plugin_rawpb_py) " +
353        "--out-dir=$(genDir) " +
354        "--compile-dir=$${compile_dir} " +
355        "--language raw_rpc " +
356        "--sources $${proto_files} " +
357        "--no-experimental-proto3-optional " +
358        "--protoc=$(location aprotoc)",
359    tools: [
360        "aprotoc",
361        "pw_protobuf_compiler_py",
362        "pw_rpc_plugin_rawpb_py",
363    ],
364}
365
366// Generate header pwpb files.
367// The output file names are based on the srcs file name with a .pwpb.h extension.
368genrule_defaults {
369    name: "pw_rpc_generate_pwpb_proto",
370    cmd: "in_files=($(in)); compile_dir=$$(dirname $${in_files[0]}); " +
371        "python3 $(location pw_protobuf_compiler_py) " +
372        "--plugin-path=$(location pw_protobuf_plugin_py) " +
373        "--out-dir=$(genDir) " +
374        "--compile-dir=$${compile_dir} " +
375        "--language pwpb " +
376        "--sources $(in) " +
377        "--no-experimental-proto3-optional " +
378        "--protoc=$(location aprotoc)",
379    tools: [
380        "aprotoc",
381        "pw_protobuf_plugin_py",
382        "pw_protobuf_compiler_py",
383    ],
384}
385
386// Same as pw_rpc_generate_pwpb_proto but the proto files are compiled with a
387// single prefix, which can be added with pw_rpc_add_prefix_to_proto.
388// Since pw_rpc_add_prefix_to_proto may include .option files as an input, only
389// .proto files are passed to the compile script. Make sure .option files are
390// prefixed in the same rule as their .proto files.
391//
392// See the pw_rpc_echo_service_pwpb target for an example. The echo.proto file
393// is compiled with "pw_rpc" as the prefix.
394genrule_defaults {
395    name: "pw_rpc_generate_pwpb_proto_with_prefix",
396    cmd: "in_files=($(in)); prefix_dir=$$(dirname $${in_files[0]}); " +
397        "compile_dir=$$(dirname $${prefix_dir}); proto_files=(); " +
398        "for f in \"$${in_files[@]}\"; do " +
399        "if [[ \"$${f##*.}\" == \"proto\" ]]; then " +
400        "proto_files+=(\"$${f}\"); fi; done; " +
401        "python3 $(location pw_protobuf_compiler_py) " +
402        "--plugin-path=$(location pw_protobuf_plugin_py) " +
403        "--out-dir=$(genDir) " +
404        "--compile-dir=$${compile_dir} " +
405        "--language pwpb " +
406        "--sources $${proto_files} " +
407        "--no-experimental-proto3-optional " +
408        "--protoc=$(location aprotoc)",
409    tools: [
410        "aprotoc",
411        "pw_protobuf_plugin_py",
412        "pw_protobuf_compiler_py",
413    ],
414}
415
416// Generate the header pwpb RPC file.
417// The output file name is based on the srcs file name with a .rpc.pwpb.h extension.
418genrule_defaults {
419    name: "pw_rpc_generate_pwpb_rpc_header",
420    cmd: "in_files=($(in)); compile_dir=$$(dirname $${in_files[0]}); " +
421        "python3 $(location pw_protobuf_compiler_py) " +
422        "--plugin-path=$(location pw_rpc_plugin_pwpb_py) " +
423        "--out-dir=$(genDir) " +
424        "--compile-dir=$${compile_dir} " +
425        "--language pwpb_rpc " +
426        "--sources $(in) " +
427        "--no-experimental-proto3-optional " +
428        "--protoc=$(location aprotoc)",
429    tools: [
430        "aprotoc",
431        "pw_protobuf_compiler_py",
432        "pw_rpc_plugin_pwpb_py",
433    ],
434}
435
436// Same as pw_rpc_generate_pwpb_rpc_header but the proto files are compiled
437// with a single prefix, which can be added with pw_rpc_add_prefix_to_proto.
438// Since pw_rpc_add_prefix_to_proto may include .option files as an input, only
439// .proto files are passed to the compile script. Make sure .option files are
440// prefixed in the same rule as their .proto files.
441//
442// See the pw_rpc_echo_service_pwpb target for an example. The echo.proto file
443// is compiled with "pw_rpc" as the prefix.
444genrule_defaults {
445    name: "pw_rpc_generate_pwpb_rpc_header_with_prefix",
446    cmd: "in_files=($(in)); prefix_dir=$$(dirname $${in_files[0]}); " +
447        "compile_dir=$$(dirname $${prefix_dir}); proto_files=(); " +
448        "for f in \"$${in_files[@]}\"; do " +
449        "if [[ \"$${f##*.}\" == \"proto\" ]]; then " +
450        "proto_files+=(\"$${f}\"); fi; done; " +
451        "python3 $(location pw_protobuf_compiler_py) " +
452        "--plugin-path=$(location pw_rpc_plugin_pwpb_py) " +
453        "--out-dir=$(genDir) " +
454        "--compile-dir=$${compile_dir} " +
455        "--language pwpb_rpc " +
456        "--sources $${proto_files} " +
457        "--no-experimental-proto3-optional " +
458        "--protoc=$(location aprotoc)",
459    tools: [
460        "aprotoc",
461        "pw_protobuf_compiler_py",
462        "pw_rpc_plugin_pwpb_py",
463    ],
464}
465
466// Copies the proto files to a prefix directory to add the prefix to the
467// compiled proto. The prefix is taken from the directory name of the first
468// item listen in out.
469genrule_defaults {
470    name: "pw_rpc_add_prefix_to_proto",
471    cmd: "out_files=($(out)); prefix=$$(dirname $${out_files[0]}); " +
472        "mkdir -p $${prefix}; cp -t $${prefix} $(in);",
473}
474
475genrule {
476    name: "pw_rpc_echo_proto_with_prefix",
477    defaults: ["pw_rpc_add_prefix_to_proto"],
478    srcs: [
479        "echo.options",
480        "echo.proto",
481    ],
482    out: [
483        "pw_rpc/echo.options",
484        "pw_rpc/echo.proto",
485    ],
486}
487
488genrule {
489    name: "pw_rpc_echo_rpc_header",
490    defaults: ["pw_rpc_generate_nanopb_rpc_header_with_prefix"],
491    srcs: [":pw_rpc_echo_proto_with_prefix"],
492    out: ["pw_rpc/echo.rpc.pb.h"],
493}
494
495genrule {
496    name: "pw_rpc_echo_proto_header",
497    defaults: ["pw_rpc_generate_nanopb_proto_with_prefix"],
498    srcs: [":pw_rpc_echo_proto_with_prefix"],
499    out: ["pw_rpc/echo.pb.h"],
500}
501
502genrule {
503    name: "pw_rpc_echo_proto_source",
504    defaults: ["pw_rpc_generate_nanopb_proto_with_prefix"],
505    srcs: [":pw_rpc_echo_proto_with_prefix"],
506    out: ["pw_rpc/echo.pb.c"],
507}
508
509// This is a copy of the echo.pb.h header, since the generated echo.pb.c
510// includes it by file name, while pw_rpc/nanopb/echo_service_nanopb.h includes
511// it with a prefix.
512// Soong makes it very hard to add include directories when they don't come from
513// modules, so this is a kludge to add an include directory path without a
514// prefix.
515genrule {
516    name: "pw_rpc_echo_proto_header_copy",
517    cmd: "cp $(in) $(out)",
518    srcs: [":pw_rpc_echo_proto_header"],
519    out: ["echo.pb.h"],
520}
521
522cc_library_static {
523    name: "pw_rpc_echo_service_nanopb",
524    cpp_std: "c++20",
525    vendor_available: true,
526    host_supported: true,
527    export_include_dirs: ["public/pw_rpc"],
528    generated_headers: [
529        "pw_rpc_echo_proto_header",
530        "pw_rpc_echo_proto_header_copy",
531        "pw_rpc_echo_rpc_header",
532    ],
533    export_generated_headers: [
534        "pw_rpc_echo_proto_header",
535        "pw_rpc_echo_proto_header_copy",
536        "pw_rpc_echo_rpc_header",
537    ],
538    generated_sources: ["pw_rpc_echo_proto_source"],
539    static_libs: ["libprotobuf-c-nano"],
540}
541
542genrule {
543    name: "pw_rpc_echo_pwpb_rpc_header",
544    defaults: ["pw_rpc_generate_pwpb_rpc_header_with_prefix"],
545    srcs: [":pw_rpc_echo_proto_with_prefix"],
546    out: ["pw_rpc/echo.rpc.pwpb.h"],
547}
548
549genrule {
550    name: "pw_rpc_echo_pwpb_proto_header",
551    defaults: ["pw_rpc_generate_pwpb_proto_with_prefix"],
552    srcs: [":pw_rpc_echo_proto_with_prefix"],
553    out: ["pw_rpc/echo.pwpb.h"],
554}
555
556cc_library_static {
557    name: "pw_rpc_echo_service_pwpb",
558    cpp_std: "c++20",
559    vendor_available: true,
560    host_supported: true,
561    export_include_dirs: ["public/pw_rpc"],
562    generated_headers: [
563        "pw_rpc_echo_pwpb_proto_header",
564        "pw_rpc_echo_pwpb_rpc_header",
565    ],
566    export_generated_headers: [
567        "pw_rpc_echo_pwpb_proto_header",
568        "pw_rpc_echo_pwpb_rpc_header",
569    ],
570}
571
572python_library_host {
573    name: "pw_rpc_internal_packet_py_lib",
574    srcs: [
575        ":pw_rpc_internal_packet_py",
576    ],
577    pkg_path: "pw_rpc/internal",
578}
579