| // Copyright 2022 The Pigweed Authors |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| // use this file except in compliance with the License. You may obtain a copy of |
| // the License at |
| // |
| // https://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| // License for the specific language governing permissions and limitations under |
| // the License. |
| |
| package { |
| default_applicable_licenses: ["external_pigweed_license"], |
| } |
| |
| java_library { |
| name: "pw_rpc_java_client", |
| srcs: ["java/main/dev/pigweed/pw_rpc/*.java"], |
| visibility: ["//visibility:public"], |
| static_libs: [ |
| "pw_log_android_java", |
| "pw_rpc_packet_proto_java_lite", |
| ], |
| libs: [ |
| "auto_value_annotations", |
| "guava", |
| "jsr305", |
| "libprotobuf-java-lite", |
| ], |
| plugins: ["auto_value_plugin"], |
| sdk_version: "current", |
| } |
| |
| java_library_static { |
| name: "pw_rpc_packet_proto_java_lite", |
| host_supported: true, |
| proto: { |
| type: "lite", |
| }, |
| srcs: ["internal/packet.proto"], |
| sdk_version: "current", |
| } |
| |
| java_library_static { |
| name: "pw_rpc_echo_proto_java_lite", |
| visibility: ["//visibility:public"], |
| host_supported: true, |
| proto: { |
| type: "lite", |
| }, |
| srcs: ["echo.proto"], |
| sdk_version: "current", |
| } |
| |
| filegroup { |
| name: "pw_rpc_src_files", |
| srcs: [ |
| "call.cc", |
| "channel.cc", |
| "channel_list.cc", |
| "client.cc", |
| "client_call.cc", |
| "client_server.cc", |
| "endpoint.cc", |
| "fake_channel_output.cc", |
| "packet.cc", |
| "packet_meta.cc", |
| "server.cc", |
| "server_call.cc", |
| "service.cc", |
| ], |
| } |
| |
| // Do not use this directly. It is used by the pw_rpc_defaults to keep the |
| // path to the "public" directory relative to this module. |
| cc_library_headers { |
| name: "pw_rpc_include_dirs", |
| export_include_dirs: [ |
| "public", |
| ], |
| vendor_available: true, |
| host_supported: true, |
| } |
| |
| // This rule must be instantiated, i.e. |
| // |
| // cc_library_static { |
| // name: "pw_rpc_<instance_name>", |
| // defaults: [ |
| // "pw_rpc_cflags_<instance_name>", |
| // "pw_rpc_defaults", |
| // ], |
| // } |
| // |
| // where pw_rpc_cflags_<instance_name> defines your flags, i.e. |
| // |
| // cc_defaults { |
| // name: "pw_rpc_cflags_<instance_name>", |
| // cflags: [ |
| // "-DPW_RPC_USE_GLOBAL_MUTEX=0", |
| // "-DPW_RPC_COMPLETION_REQUEST_CALLBACK", |
| // "-DPW_RPC_DYNAMIC_ALLOCATION", |
| // ], |
| // } |
| // |
| // see pw_rpc_nanopb_defaults, pw_rpc_raw_defaults |
| cc_defaults { |
| name: "pw_rpc_defaults", |
| cpp_std: "c++20", |
| defaults: [ |
| "pw_android_common_backends", |
| ], |
| header_libs: [ |
| "fuchsia_sdk_lib_fit", |
| "fuchsia_sdk_lib_stdcompat", |
| "pw_assert", |
| "pw_log", |
| "pw_rpc_include_dirs", |
| "pw_sync", |
| ], |
| export_header_lib_headers: [ |
| "fuchsia_sdk_lib_fit", |
| "fuchsia_sdk_lib_stdcompat", |
| "pw_assert", |
| "pw_log", |
| "pw_rpc_include_dirs", |
| "pw_sync", |
| ], |
| static_libs: [ |
| "pw_bytes", |
| "pw_containers", |
| "pw_function", |
| "pw_polyfill", |
| "pw_preprocessor", |
| "pw_protobuf", |
| "pw_result", |
| "pw_span", |
| "pw_status", |
| "pw_stream", |
| "pw_string", |
| "pw_sync_baremetal", |
| "pw_toolchain", |
| "pw_varint", |
| ], |
| export_static_lib_headers: [ |
| "pw_bytes", |
| "pw_containers", |
| "pw_function", |
| "pw_polyfill", |
| "pw_preprocessor", |
| "pw_protobuf", |
| "pw_result", |
| "pw_span", |
| "pw_status", |
| "pw_stream", |
| "pw_string", |
| "pw_sync_baremetal", |
| "pw_toolchain", |
| "pw_varint", |
| ], |
| generated_headers: [ |
| "pw_rpc_internal_packet_pwpb_h", |
| ], |
| export_generated_headers: [ |
| "pw_rpc_internal_packet_pwpb_h", |
| ], |
| srcs: [ |
| ":pw_rpc_src_files", |
| ], |
| } |
| |
| genrule { |
| name: "pw_rpc_internal_packet_pwpb_h", |
| srcs: ["internal/packet.proto"], |
| cmd: "python3 $(location pw_protobuf_compiler_py) " + |
| "--out-dir=$$(dirname $(location pw_rpc/internal/packet.pwpb.h)) " + |
| "--plugin-path=$(location pw_protobuf_plugin_py) " + |
| "--compile-dir=$$(dirname $(in)) " + |
| "--sources $(in) " + |
| "--language pwpb " + |
| "--no-experimental-proto3-optional " + |
| "--protoc=$(location aprotoc) ", |
| out: [ |
| "pw_rpc/internal/packet.pwpb.h", |
| ], |
| tools: [ |
| "aprotoc", |
| "pw_protobuf_plugin_py", |
| "pw_protobuf_compiler_py", |
| ], |
| } |
| |
| genrule { |
| name: "pw_rpc_internal_packet_py", |
| srcs: ["internal/packet.proto"], |
| cmd: "python3 $(location pw_protobuf_compiler_py) " + |
| "--out-dir=$(genDir) " + |
| "--compile-dir=$$(dirname $(in)) " + |
| "--sources $(in) " + |
| "--language python " + |
| "--no-generate-type-hints " + |
| "--no-experimental-proto3-optional " + |
| "--protoc=$(location aprotoc)", |
| out: [ |
| "packet_pb2.py", |
| ], |
| tools: [ |
| "aprotoc", |
| "pw_protobuf_compiler_py", |
| ], |
| } |
| |
| // Generates .pb.c and .pb.h nanopb files. |
| // The output file name is based on the srcs file name with an added extension. |
| // All dependencies, including .options files, must be listed in srcs and cannot |
| // be prefixed. Use the _with_prefix rules if prefixed. Only .proto files are |
| // passed to the compile script. |
| // |
| // Args: |
| // srcs: The list of source files without a prefix. |
| // out: A one-element list with the output file without a prefix. |
| genrule_defaults { |
| name: "pw_rpc_generate_nanopb_proto", |
| cmd: "in_files=($(in)); compile_dir=$$(dirname $${in_files[0]}); " + |
| "proto_files=(); " + |
| "for f in \"$${in_files[@]}\"; do " + |
| "if [[ \"$${f##*.}\" == \"proto\" ]]; then " + |
| "proto_files+=(\"$${f}\"); " + |
| "fi; done; " + |
| "python3 $(location pw_protobuf_compiler_py) " + |
| "--plugin-path=$(location protoc-gen-nanopb) " + |
| "--out-dir=$(genDir) " + |
| "--compile-dir=$${compile_dir} " + |
| "--language nanopb " + |
| "--sources $${proto_files} " + |
| "--no-experimental-proto3-optional " + |
| "--protoc=$(location aprotoc)", |
| tools: [ |
| "aprotoc", |
| "protoc-gen-nanopb", |
| "pw_protobuf_compiler_py", |
| ], |
| } |
| |
| // Same as pw_rpc_generate_nanopb_proto but the proto files are compiled with a |
| // single prefix, which can be added with pw_rpc_add_prefix_to_proto. |
| // Since pw_rpc_add_prefix_to_proto may include .option files as an input, only |
| // .proto files are passed to the compile script. Make sure .option files are |
| // prefixed in the same rule as their .proto files. All dependencies must also |
| // be listed in srcs and have a single prefix. |
| // |
| // See the pw_rpc_echo_service_nanopb target for an example. The echo.proto file |
| // is compiled with "pw_rpc" as the prefix. |
| // |
| // Args: |
| // srcs: The list of source files all with one prefix folder. |
| // out: A one-element list with the output file with a prefix folder. The |
| // prefix is based on the parent name of the first item in srcs. |
| genrule_defaults { |
| name: "pw_rpc_generate_nanopb_proto_with_prefix", |
| cmd: "in_files=($(in)); prefix_dir=$$(dirname $${in_files[0]}); " + |
| "compile_dir=$$(dirname $${prefix_dir}); " + |
| "proto_files=(); " + |
| "proto_paths_args=\"\"; " + |
| "for f in \"$${in_files[@]}\"; do " + |
| "if [[ \"$${f##*.}\" == \"proto\" ]]; then " + |
| "proto_files+=(\"$${f}\"); " + |
| "proto_path_args+=\"--proto-path=$$(dirname $$(dirname $${f})) \"; " + |
| "fi; done; " + |
| "python3 $(location pw_protobuf_compiler_py) " + |
| "--plugin-path=$(location protoc-gen-nanopb) " + |
| "$${proto_path_args} " + |
| "--out-dir=$(genDir) " + |
| "--compile-dir=$${compile_dir} " + |
| "--language nanopb " + |
| "--sources $${proto_files} " + |
| "--no-experimental-proto3-optional " + |
| "--protoc=$(location aprotoc)", |
| tools: [ |
| "aprotoc", |
| "protoc-gen-nanopb", |
| "pw_protobuf_compiler_py", |
| ], |
| } |
| |
| // Generate the header nanopb RPC file (.rpc.pb.h). |
| // |
| // Args: |
| // srcs: The list of source files without a prefix. |
| // out: A one-element list with the output file without a prefix. The name is |
| // based on the srcs file name with a .rpc.pb.h extension. |
| genrule_defaults { |
| name: "pw_rpc_generate_nanopb_rpc_header", |
| cmd: "in_files=($(in)); compile_dir=$$(dirname $${in_files[0]}); " + |
| "python3 $(location pw_protobuf_compiler_py) " + |
| "--plugin-path=$(location pw_rpc_plugin_nanopb_py) " + |
| "--out-dir=$(genDir) " + |
| "--compile-dir=$${compile_dir} " + |
| "--language nanopb_rpc " + |
| "--sources $(in) " + |
| "--no-experimental-proto3-optional " + |
| "--protoc=$(location aprotoc)", |
| tools: [ |
| "aprotoc", |
| "pw_protobuf_compiler_py", |
| "pw_rpc_plugin_nanopb_py", |
| ], |
| } |
| |
| // Same as pw_rpc_generate_nanopb_rpc_header but the proto files are compiled |
| // with a single prefix, which can be added with pw_rpc_add_prefix_to_proto. |
| // Since pw_rpc_add_prefix_to_proto may include .option files as an input, only |
| // .proto files are passed to the compile script. Make sure .option files are |
| // prefixed in the same rule as their .proto files. All dependencies must also |
| // be listed in srcs and have a single prefix. |
| // |
| // See the pw_rpc_echo_service_nanopb target for an example. The echo.proto file |
| // is compiled with "pw_rpc" as the prefix. |
| // |
| // Args: |
| // srcs: The list of source files all with one prefix folder. |
| // out: A one-element list with the output file with a prefix folder. The |
| // prefix is based on the parent name of the first item in srcs. |
| genrule_defaults { |
| name: "pw_rpc_generate_nanopb_rpc_header_with_prefix", |
| cmd: "in_files=($(in)); prefix_dir=$$(dirname $${in_files[0]}); " + |
| "compile_dir=$$(dirname $${prefix_dir}); " + |
| "proto_files=(); " + |
| "proto_paths_args=\"\"; " + |
| "for f in \"$${in_files[@]}\"; do " + |
| "if [[ \"$${f##*.}\" == \"proto\" ]]; then " + |
| "proto_files+=(\"$${f}\"); " + |
| "proto_path_args+=\"--proto-path=$$(dirname $$(dirname $${f})) \"; " + |
| "fi; done; " + |
| "python3 $(location pw_protobuf_compiler_py) " + |
| "--plugin-path=$(location pw_rpc_plugin_nanopb_py) " + |
| "$${proto_path_args} " + |
| "--out-dir=$(genDir) " + |
| "--compile-dir=$${compile_dir} " + |
| "--language nanopb_rpc " + |
| "--sources $${proto_files} " + |
| "--no-experimental-proto3-optional " + |
| "--protoc=$(location aprotoc)", |
| tools: [ |
| "aprotoc", |
| "pw_protobuf_compiler_py", |
| "pw_rpc_plugin_nanopb_py", |
| ], |
| } |
| |
| // Generate the header raw RPC file. |
| // The output file name is based on the srcs file name with a .raw_rpc.pb.h extension. |
| genrule_defaults { |
| name: "pw_rpc_generate_raw_rpc_header", |
| cmd: "in_files=($(in)); compile_dir=$$(dirname $${in_files[0]}); " + |
| "python3 $(location pw_protobuf_compiler_py) " + |
| "--plugin-path=$(location pw_rpc_plugin_rawpb_py) " + |
| "--out-dir=$(genDir) " + |
| "--compile-dir=$${compile_dir} " + |
| "--language raw_rpc " + |
| "--sources $(in) " + |
| "--no-experimental-proto3-optional " + |
| "--protoc=$(location aprotoc)", |
| tools: [ |
| "aprotoc", |
| "pw_protobuf_compiler_py", |
| "pw_rpc_plugin_rawpb_py", |
| ], |
| } |
| |
| // Same as pw_rpc_generate_raw_rpc_header but the proto files are compiled with |
| // a single prefix, which can be added with pw_rpc_add_prefix_to_proto. |
| // Since pw_rpc_add_prefix_to_proto may include .option files as an input, only |
| // .proto files are passed to the compile script. Make sure .option files are |
| // prefixed in the same rule as their .proto files. |
| // |
| // See the pw_rpc_echo_service_pwpb target for an example. The echo.proto file |
| // is compiled with "pw_rpc" as the prefix. |
| genrule_defaults { |
| name: "pw_rpc_generate_raw_rpc_header_with_prefix", |
| cmd: "in_files=($(in)); prefix_dir=$$(dirname $${in_files[0]}); " + |
| "compile_dir=$$(dirname $${prefix_dir}); proto_files=(); " + |
| "for f in \"$${in_files[@]}\"; do " + |
| "if [[ \"$${f##*.}\" == \"proto\" ]]; then " + |
| "proto_files+=(\"$${f}\"); fi; done; " + |
| "python3 $(location pw_protobuf_compiler_py) " + |
| "--plugin-path=$(location pw_rpc_plugin_rawpb_py) " + |
| "--out-dir=$(genDir) " + |
| "--compile-dir=$${compile_dir} " + |
| "--language raw_rpc " + |
| "--sources $${proto_files} " + |
| "--no-experimental-proto3-optional " + |
| "--protoc=$(location aprotoc)", |
| tools: [ |
| "aprotoc", |
| "pw_protobuf_compiler_py", |
| "pw_rpc_plugin_rawpb_py", |
| ], |
| } |
| |
| // Generate header pwpb files. |
| // The output file names are based on the srcs file name with a .pwpb.h extension. |
| genrule_defaults { |
| name: "pw_rpc_generate_pwpb_proto", |
| cmd: "in_files=($(in)); compile_dir=$$(dirname $${in_files[0]}); " + |
| "python3 $(location pw_protobuf_compiler_py) " + |
| "--plugin-path=$(location pw_protobuf_plugin_py) " + |
| "--out-dir=$(genDir) " + |
| "--compile-dir=$${compile_dir} " + |
| "--language pwpb " + |
| "--sources $(in) " + |
| "--no-experimental-proto3-optional " + |
| "--protoc=$(location aprotoc)", |
| tools: [ |
| "aprotoc", |
| "pw_protobuf_plugin_py", |
| "pw_protobuf_compiler_py", |
| ], |
| } |
| |
| // Same as pw_rpc_generate_pwpb_proto but the proto files are compiled with a |
| // single prefix, which can be added with pw_rpc_add_prefix_to_proto. |
| // Since pw_rpc_add_prefix_to_proto may include .option files as an input, only |
| // .proto files are passed to the compile script. Make sure .option files are |
| // prefixed in the same rule as their .proto files. |
| // |
| // See the pw_rpc_echo_service_pwpb target for an example. The echo.proto file |
| // is compiled with "pw_rpc" as the prefix. |
| genrule_defaults { |
| name: "pw_rpc_generate_pwpb_proto_with_prefix", |
| cmd: "in_files=($(in)); prefix_dir=$$(dirname $${in_files[0]}); " + |
| "compile_dir=$$(dirname $${prefix_dir}); proto_files=(); " + |
| "for f in \"$${in_files[@]}\"; do " + |
| "if [[ \"$${f##*.}\" == \"proto\" ]]; then " + |
| "proto_files+=(\"$${f}\"); fi; done; " + |
| "python3 $(location pw_protobuf_compiler_py) " + |
| "--plugin-path=$(location pw_protobuf_plugin_py) " + |
| "--out-dir=$(genDir) " + |
| "--compile-dir=$${compile_dir} " + |
| "--language pwpb " + |
| "--sources $${proto_files} " + |
| "--no-experimental-proto3-optional " + |
| "--protoc=$(location aprotoc)", |
| tools: [ |
| "aprotoc", |
| "pw_protobuf_plugin_py", |
| "pw_protobuf_compiler_py", |
| ], |
| } |
| |
| // Generate the header pwpb RPC file. |
| // The output file name is based on the srcs file name with a .rpc.pwpb.h extension. |
| genrule_defaults { |
| name: "pw_rpc_generate_pwpb_rpc_header", |
| cmd: "in_files=($(in)); compile_dir=$$(dirname $${in_files[0]}); " + |
| "python3 $(location pw_protobuf_compiler_py) " + |
| "--plugin-path=$(location pw_rpc_plugin_pwpb_py) " + |
| "--out-dir=$(genDir) " + |
| "--compile-dir=$${compile_dir} " + |
| "--language pwpb_rpc " + |
| "--sources $(in) " + |
| "--no-experimental-proto3-optional " + |
| "--protoc=$(location aprotoc)", |
| tools: [ |
| "aprotoc", |
| "pw_protobuf_compiler_py", |
| "pw_rpc_plugin_pwpb_py", |
| ], |
| } |
| |
| // Same as pw_rpc_generate_pwpb_rpc_header but the proto files are compiled |
| // with a single prefix, which can be added with pw_rpc_add_prefix_to_proto. |
| // Since pw_rpc_add_prefix_to_proto may include .option files as an input, only |
| // .proto files are passed to the compile script. Make sure .option files are |
| // prefixed in the same rule as their .proto files. |
| // |
| // See the pw_rpc_echo_service_pwpb target for an example. The echo.proto file |
| // is compiled with "pw_rpc" as the prefix. |
| genrule_defaults { |
| name: "pw_rpc_generate_pwpb_rpc_header_with_prefix", |
| cmd: "in_files=($(in)); prefix_dir=$$(dirname $${in_files[0]}); " + |
| "compile_dir=$$(dirname $${prefix_dir}); proto_files=(); " + |
| "for f in \"$${in_files[@]}\"; do " + |
| "if [[ \"$${f##*.}\" == \"proto\" ]]; then " + |
| "proto_files+=(\"$${f}\"); fi; done; " + |
| "python3 $(location pw_protobuf_compiler_py) " + |
| "--plugin-path=$(location pw_rpc_plugin_pwpb_py) " + |
| "--out-dir=$(genDir) " + |
| "--compile-dir=$${compile_dir} " + |
| "--language pwpb_rpc " + |
| "--sources $${proto_files} " + |
| "--no-experimental-proto3-optional " + |
| "--protoc=$(location aprotoc)", |
| tools: [ |
| "aprotoc", |
| "pw_protobuf_compiler_py", |
| "pw_rpc_plugin_pwpb_py", |
| ], |
| } |
| |
| // Copies the proto files to a prefix directory to add the prefix to the |
| // compiled proto. The prefix is taken from the directory name of the first |
| // item listen in out. |
| genrule_defaults { |
| name: "pw_rpc_add_prefix_to_proto", |
| cmd: "out_files=($(out)); prefix=$$(dirname $${out_files[0]}); " + |
| "mkdir -p $${prefix}; cp -t $${prefix} $(in);", |
| } |
| |
| genrule { |
| name: "pw_rpc_echo_proto_with_prefix", |
| defaults: ["pw_rpc_add_prefix_to_proto"], |
| srcs: [ |
| "echo.options", |
| "echo.proto", |
| ], |
| out: [ |
| "pw_rpc/echo.options", |
| "pw_rpc/echo.proto", |
| ], |
| } |
| |
| genrule { |
| name: "pw_rpc_echo_rpc_header", |
| defaults: ["pw_rpc_generate_nanopb_rpc_header_with_prefix"], |
| srcs: [":pw_rpc_echo_proto_with_prefix"], |
| out: ["pw_rpc/echo.rpc.pb.h"], |
| } |
| |
| genrule { |
| name: "pw_rpc_echo_proto_header", |
| defaults: ["pw_rpc_generate_nanopb_proto_with_prefix"], |
| srcs: [":pw_rpc_echo_proto_with_prefix"], |
| out: ["pw_rpc/echo.pb.h"], |
| } |
| |
| genrule { |
| name: "pw_rpc_echo_proto_source", |
| defaults: ["pw_rpc_generate_nanopb_proto_with_prefix"], |
| srcs: [":pw_rpc_echo_proto_with_prefix"], |
| out: ["pw_rpc/echo.pb.c"], |
| } |
| |
| // This is a copy of the echo.pb.h header, since the generated echo.pb.c |
| // includes it by file name, while pw_rpc/nanopb/echo_service_nanopb.h includes |
| // it with a prefix. |
| // Soong makes it very hard to add include directories when they don't come from |
| // modules, so this is a kludge to add an include directory path without a |
| // prefix. |
| genrule { |
| name: "pw_rpc_echo_proto_header_copy", |
| cmd: "cp $(in) $(out)", |
| srcs: [":pw_rpc_echo_proto_header"], |
| out: ["echo.pb.h"], |
| } |
| |
| cc_library_static { |
| name: "pw_rpc_echo_service_nanopb", |
| cpp_std: "c++20", |
| vendor_available: true, |
| host_supported: true, |
| export_include_dirs: ["public/pw_rpc"], |
| generated_headers: [ |
| "pw_rpc_echo_proto_header", |
| "pw_rpc_echo_proto_header_copy", |
| "pw_rpc_echo_rpc_header", |
| ], |
| export_generated_headers: [ |
| "pw_rpc_echo_proto_header", |
| "pw_rpc_echo_proto_header_copy", |
| "pw_rpc_echo_rpc_header", |
| ], |
| generated_sources: ["pw_rpc_echo_proto_source"], |
| static_libs: ["libprotobuf-c-nano"], |
| } |
| |
| genrule { |
| name: "pw_rpc_echo_pwpb_rpc_header", |
| defaults: ["pw_rpc_generate_pwpb_rpc_header_with_prefix"], |
| srcs: [":pw_rpc_echo_proto_with_prefix"], |
| out: ["pw_rpc/echo.rpc.pwpb.h"], |
| } |
| |
| genrule { |
| name: "pw_rpc_echo_pwpb_proto_header", |
| defaults: ["pw_rpc_generate_pwpb_proto_with_prefix"], |
| srcs: [":pw_rpc_echo_proto_with_prefix"], |
| out: ["pw_rpc/echo.pwpb.h"], |
| } |
| |
| cc_library_static { |
| name: "pw_rpc_echo_service_pwpb", |
| cpp_std: "c++20", |
| vendor_available: true, |
| host_supported: true, |
| export_include_dirs: ["public/pw_rpc"], |
| generated_headers: [ |
| "pw_rpc_echo_pwpb_proto_header", |
| "pw_rpc_echo_pwpb_rpc_header", |
| ], |
| export_generated_headers: [ |
| "pw_rpc_echo_pwpb_proto_header", |
| "pw_rpc_echo_pwpb_rpc_header", |
| ], |
| } |
| |
| python_library_host { |
| name: "pw_rpc_internal_packet_py_lib", |
| srcs: [ |
| ":pw_rpc_internal_packet_py", |
| ], |
| pkg_path: "pw_rpc/internal", |
| } |