Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 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 | |
Armando Montanez | fb3d3fb | 2020-06-09 18:12:12 -0700 | [diff] [blame] | 15 | # gn-format disable |
| 16 | import("//build_overrides/pigweed.gni") |
| 17 | |
Alexei Frolov | edd2f14 | 2020-06-09 19:11:27 -0700 | [diff] [blame] | 18 | import("$dir_pw_build/target_types.gni") |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 19 | import("$dir_pw_docgen/docs.gni") |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 20 | import("$dir_pw_protobuf_compiler/proto.gni") |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 21 | import("$dir_pw_unit_test/test.gni") |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 22 | config("default_config") { |
| 23 | include_dirs = [ "public" ] |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 24 | visibility = [ ":*" ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 25 | } |
| 26 | |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 27 | # pw_rpc servers depend on the protobuf library used to encode and decode |
| 28 | # requests and responses when invoking methods. This template is used to create |
| 29 | # instances of the pw_rpc server library with different implementations. |
| 30 | # |
| 31 | # The implementation parameter must refer to a library that provides the |
| 32 | # definition of the Method class in pw_rpc/internal/method.h. The Method class |
| 33 | # provides the Invoke function, which handles the server use to call into the |
| 34 | # RPC functions themselves. |
| 35 | template("_pw_rpc_server_library") { |
| 36 | assert(defined(invoker.implementation), |
| 37 | "_pw_rpc_server_library requires an implementation to be set") |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 38 | _target_name = target_name |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 39 | |
Alexei Frolov | edd2f14 | 2020-06-09 19:11:27 -0700 | [diff] [blame] | 40 | pw_source_set(_target_name) { |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 41 | forward_variables_from(invoker, "*") |
| 42 | |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 43 | public_deps = [ |
Wyatt Hepler | 3e2d719 | 2020-06-11 08:28:21 -0700 | [diff] [blame] | 44 | ":server_library_deps", |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 45 | implementation, |
| 46 | ] |
| 47 | deps = [ |
| 48 | dir_pw_assert, |
| 49 | dir_pw_log, |
| 50 | ] |
| 51 | public = [ |
| 52 | "public/pw_rpc/server.h", |
| 53 | "public/pw_rpc/server_context.h", |
| 54 | ] |
| 55 | sources = [ |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 56 | "base_server_writer.cc", |
| 57 | "public/pw_rpc/internal/base_server_writer.h", |
Wyatt Hepler | 671946e | 2020-06-09 14:39:33 -0700 | [diff] [blame] | 58 | "public/pw_rpc/internal/server.h", |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 59 | "server.cc", |
| 60 | "service.cc", |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 61 | ] |
| 62 | allow_circular_includes_from = [ implementation ] |
Wyatt Hepler | 948f547 | 2020-06-02 16:52:28 -0700 | [diff] [blame] | 63 | friend = [ "./*" ] |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 64 | } |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 65 | |
Wyatt Hepler | 8aa0292 | 2020-07-17 08:54:37 -0700 | [diff] [blame] | 66 | pw_source_set("internal_test_utils_$_target_name") { |
| 67 | public = [ "pw_rpc_private/internal_test_utils.h" ] |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 68 | public_configs = [ ":private_includes" ] |
| 69 | public_deps = [ |
| 70 | ":$_target_name", |
| 71 | ":common", |
| 72 | dir_pw_span, |
Wyatt Hepler | 712d367 | 2020-07-13 15:52:11 -0700 | [diff] [blame] | 73 | dir_pw_unit_test, |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 74 | ] |
| 75 | visibility = [ "./*" ] |
| 76 | } |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Alexei Frolov | 9a4d6bf | 2020-08-04 10:33:26 -0700 | [diff] [blame] | 79 | # Provides the public RPC service definition (but not implementation). Can be |
| 80 | # used to expose global service registration without depending on the complete |
| 81 | # RPC library. |
| 82 | pw_source_set("service") { |
| 83 | public_configs = [ ":default_config" ] |
| 84 | public_deps = [ "$dir_pw_containers:intrusive_list" ] |
| 85 | public = [ "public/pw_rpc/service.h" ] |
| 86 | } |
| 87 | |
Wyatt Hepler | 3e2d719 | 2020-06-11 08:28:21 -0700 | [diff] [blame] | 88 | # Put these dependencies into a group since they need to be shared by the server |
| 89 | # library and its implementation library. |
| 90 | group("server_library_deps") { |
| 91 | public_configs = [ ":default_config" ] |
| 92 | public_deps = [ |
| 93 | ":common", |
Alexei Frolov | 9a4d6bf | 2020-08-04 10:33:26 -0700 | [diff] [blame] | 94 | ":service", |
Wyatt Hepler | 3e2d719 | 2020-06-11 08:28:21 -0700 | [diff] [blame] | 95 | dir_pw_span, |
| 96 | dir_pw_status, |
| 97 | ] |
| 98 | visibility = [ "./*" ] |
| 99 | } |
| 100 | |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 101 | # Classes with no dependencies on the protobuf library for method invocations. |
Alexei Frolov | edd2f14 | 2020-06-09 19:11:27 -0700 | [diff] [blame] | 102 | pw_source_set("common") { |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 103 | public_configs = [ ":default_config" ] |
| 104 | public_deps = [ |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 105 | ":protos_pwpb", |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 106 | dir_pw_assert, |
Wyatt Hepler | 671946e | 2020-06-09 14:39:33 -0700 | [diff] [blame] | 107 | dir_pw_log, |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 108 | dir_pw_span, |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 109 | dir_pw_status, |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 110 | ] |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 111 | public = [ "public/pw_rpc/channel.h" ] |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 112 | sources = [ |
| 113 | "channel.cc", |
| 114 | "packet.cc", |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 115 | "public/pw_rpc/internal/base_method.h", |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 116 | "public/pw_rpc/internal/call.h", |
Wyatt Hepler | 671946e | 2020-06-09 14:39:33 -0700 | [diff] [blame] | 117 | "public/pw_rpc/internal/channel.h", |
Wyatt Hepler | 1532e52 | 2020-07-30 11:44:58 -0700 | [diff] [blame] | 118 | "public/pw_rpc/internal/hash.h", |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 119 | "public/pw_rpc/internal/packet.h", |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 120 | ] |
Wyatt Hepler | 948f547 | 2020-06-02 16:52:28 -0700 | [diff] [blame] | 121 | friend = [ "./*" ] |
| 122 | visibility = [ "./*" ] |
| 123 | } |
| 124 | |
| 125 | # RPC server that uses Nanopb to encode and decode protobufs. RPCs use Nanopb |
| 126 | # structs as their requests and responses. |
| 127 | _pw_rpc_server_library("nanopb_server") { |
| 128 | implementation = "nanopb" |
| 129 | } |
| 130 | |
| 131 | config("private_includes") { |
| 132 | include_dirs = [ "." ] |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 133 | visibility = [ ":*" ] |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 136 | pw_proto_library("protos") { |
| 137 | sources = [ "pw_rpc_protos/packet.proto" ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Alexei Frolov | 7c7a386 | 2020-07-16 15:36:02 -0700 | [diff] [blame] | 140 | pw_proto_library("echo_service_proto") { |
| 141 | sources = [ "pw_rpc_protos/echo.proto" ] |
| 142 | inputs = [ "pw_rpc_protos/echo.options" ] |
| 143 | } |
| 144 | |
Alexei Frolov | 79b7cb0 | 2020-07-06 13:51:43 -0700 | [diff] [blame] | 145 | # Source files for pw_protobuf's protoc plugin. |
| 146 | pw_input_group("nanopb_protoc_plugin") { |
| 147 | inputs = [ |
| 148 | "py/pw_rpc/codegen_nanopb.py", |
| 149 | "py/pw_rpc/plugin.py", |
| 150 | "py/pw_rpc/ids.py", |
| 151 | ] |
Alexei Frolov | 15255c5 | 2020-07-17 08:25:49 -0700 | [diff] [blame] | 152 | deps = [ "$dir_pw_protobuf:codegen_protoc_lib" ] |
Alexei Frolov | 79b7cb0 | 2020-07-06 13:51:43 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 155 | pw_doc_group("docs") { |
| 156 | sources = [ "docs.rst" ] |
Alexei Frolov | 7c7a386 | 2020-07-16 15:36:02 -0700 | [diff] [blame] | 157 | inputs = [ |
| 158 | "pw_rpc_protos/echo.proto", |
| 159 | "pw_rpc_protos/packet.proto", |
| 160 | ] |
| 161 | group_deps = [ "nanopb:docs" ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | pw_test_group("tests") { |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 165 | tests = [ |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 166 | ":base_server_writer_test", |
Wyatt Hepler | 671946e | 2020-06-09 14:39:33 -0700 | [diff] [blame] | 167 | ":channel_test", |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 168 | ":packet_test", |
| 169 | ":server_test", |
| 170 | ] |
Wyatt Hepler | af83568 | 2020-06-17 11:42:53 -0700 | [diff] [blame] | 171 | group_deps = [ "nanopb:tests" ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 174 | # RPC server for tests only. A mock method implementation is used. |
| 175 | _pw_rpc_server_library("test_server") { |
Wyatt Hepler | 948f547 | 2020-06-02 16:52:28 -0700 | [diff] [blame] | 176 | implementation = "test_impl" |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 177 | visibility = [ ":*" ] |
| 178 | } |
| 179 | |
Wyatt Hepler | 948f547 | 2020-06-02 16:52:28 -0700 | [diff] [blame] | 180 | pw_proto_library("test_protos") { |
| 181 | sources = [ "pw_rpc_test_protos/test.proto" ] |
| 182 | visibility = [ "./*" ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 183 | } |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 184 | |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 185 | pw_test("base_server_writer_test") { |
| 186 | deps = [ |
Wyatt Hepler | 8aa0292 | 2020-07-17 08:54:37 -0700 | [diff] [blame] | 187 | ":internal_test_utils_test_server", |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 188 | ":test_server", |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 189 | ] |
| 190 | sources = [ "base_server_writer_test.cc" ] |
| 191 | } |
| 192 | |
Wyatt Hepler | 671946e | 2020-06-09 14:39:33 -0700 | [diff] [blame] | 193 | pw_test("channel_test") { |
| 194 | deps = [ |
| 195 | ":common", |
Wyatt Hepler | 8aa0292 | 2020-07-17 08:54:37 -0700 | [diff] [blame] | 196 | ":internal_test_utils_test_server", |
Wyatt Hepler | 671946e | 2020-06-09 14:39:33 -0700 | [diff] [blame] | 197 | ] |
| 198 | sources = [ "channel_test.cc" ] |
| 199 | } |
| 200 | |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 201 | pw_test("packet_test") { |
| 202 | deps = [ |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 203 | ":common", |
Wyatt Hepler | 0f26235 | 2020-07-29 09:51:27 -0700 | [diff] [blame^] | 204 | dir_pw_bytes, |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 205 | dir_pw_protobuf, |
| 206 | ] |
| 207 | sources = [ "packet_test.cc" ] |
| 208 | } |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 209 | |
| 210 | pw_test("server_test") { |
| 211 | deps = [ |
Wyatt Hepler | 8aa0292 | 2020-07-17 08:54:37 -0700 | [diff] [blame] | 212 | ":internal_test_utils_test_server", |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 213 | ":protos_pwpb", |
| 214 | ":test_server", |
| 215 | dir_pw_assert, |
| 216 | ] |
| 217 | sources = [ "server_test.cc" ] |
| 218 | } |