blob: 2c7f67e37cdaca6b71cde525fa71e2c21b9123e6 [file] [log] [blame]
Alexei Frolov26e3ae62020-05-04 17:06:17 -07001# 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 Montanezfb3d3fb2020-06-09 18:12:12 -070015# gn-format disable
16import("//build_overrides/pigweed.gni")
17
Alexei Frolovedd2f142020-06-09 19:11:27 -070018import("$dir_pw_build/target_types.gni")
Alexei Frolov26e3ae62020-05-04 17:06:17 -070019import("$dir_pw_docgen/docs.gni")
Alexei Frolov5d6d3922020-05-08 13:57:02 -070020import("$dir_pw_protobuf_compiler/proto.gni")
Alexei Frolov26e3ae62020-05-04 17:06:17 -070021import("$dir_pw_unit_test/test.gni")
Alexei Frolov26e3ae62020-05-04 17:06:17 -070022config("default_config") {
23 include_dirs = [ "public" ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070024 visibility = [ ":*" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -070025}
26
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070027# 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.
35template("_pw_rpc_server_library") {
36 assert(defined(invoker.implementation),
37 "_pw_rpc_server_library requires an implementation to be set")
Wyatt Hepler7da973a2020-06-09 10:04:48 -070038 _target_name = target_name
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070039
Alexei Frolovedd2f142020-06-09 19:11:27 -070040 pw_source_set(_target_name) {
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070041 forward_variables_from(invoker, "*")
42
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070043 public_deps = [
Wyatt Hepler3e2d7192020-06-11 08:28:21 -070044 ":server_library_deps",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070045 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 Heplercb9d9572020-06-01 11:25:58 -070056 "base_server_writer.cc",
57 "public/pw_rpc/internal/base_server_writer.h",
Wyatt Hepler671946e2020-06-09 14:39:33 -070058 "public/pw_rpc/internal/server.h",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070059 "server.cc",
60 "service.cc",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070061 ]
62 allow_circular_includes_from = [ implementation ]
Wyatt Hepler948f5472020-06-02 16:52:28 -070063 friend = [ "./*" ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070064 }
Wyatt Hepler7da973a2020-06-09 10:04:48 -070065
Wyatt Hepler8aa02922020-07-17 08:54:37 -070066 pw_source_set("internal_test_utils_$_target_name") {
67 public = [ "pw_rpc_private/internal_test_utils.h" ]
Wyatt Hepler7da973a2020-06-09 10:04:48 -070068 public_configs = [ ":private_includes" ]
69 public_deps = [
70 ":$_target_name",
71 ":common",
72 dir_pw_span,
Wyatt Hepler712d3672020-07-13 15:52:11 -070073 dir_pw_unit_test,
Wyatt Hepler7da973a2020-06-09 10:04:48 -070074 ]
75 visibility = [ "./*" ]
76 }
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070077}
78
Alexei Frolov9a4d6bf2020-08-04 10:33:26 -070079# 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.
Wyatt Heplerd1591422020-09-15 10:04:41 -070082# TODO(hepler): Remove this after making the RPC implementation classes fully
83# independent of the particular implementation. Targets needing the service
84# should be able to depend on the main RPC library.
85group("service") {
86 deps = [ ":common" ]
Alexei Frolov9a4d6bf2020-08-04 10:33:26 -070087}
88
Wyatt Hepler3e2d7192020-06-11 08:28:21 -070089# Put these dependencies into a group since they need to be shared by the server
90# library and its implementation library.
91group("server_library_deps") {
92 public_configs = [ ":default_config" ]
93 public_deps = [
94 ":common",
Alexei Frolov9a4d6bf2020-08-04 10:33:26 -070095 ":service",
Wyatt Hepler3e2d7192020-06-11 08:28:21 -070096 dir_pw_span,
97 dir_pw_status,
98 ]
99 visibility = [ "./*" ]
100}
101
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700102# Classes with no dependencies on the protobuf library for method invocations.
Alexei Frolovedd2f142020-06-09 19:11:27 -0700103pw_source_set("common") {
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700104 public_configs = [ ":default_config" ]
105 public_deps = [
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700106 ":protos_pwpb",
Wyatt Heplerd1591422020-09-15 10:04:41 -0700107 "$dir_pw_containers:intrusive_list",
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700108 dir_pw_assert,
109 dir_pw_span,
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700110 dir_pw_status,
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700111 ]
Wyatt Heplerd1591422020-09-15 10:04:41 -0700112 public = [
113 "public/pw_rpc/channel.h",
114 "public/pw_rpc/service.h",
115 ]
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700116 sources = [
117 "channel.cc",
118 "packet.cc",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700119 "public/pw_rpc/internal/base_method.h",
Wyatt Hepler7da973a2020-06-09 10:04:48 -0700120 "public/pw_rpc/internal/call.h",
Wyatt Hepler671946e2020-06-09 14:39:33 -0700121 "public/pw_rpc/internal/channel.h",
Wyatt Hepler1532e522020-07-30 11:44:58 -0700122 "public/pw_rpc/internal/hash.h",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700123 "public/pw_rpc/internal/packet.h",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700124 ]
Wyatt Heplerd1591422020-09-15 10:04:41 -0700125 deps = [ dir_pw_log ]
Wyatt Hepler948f5472020-06-02 16:52:28 -0700126 friend = [ "./*" ]
Wyatt Hepler948f5472020-06-02 16:52:28 -0700127}
128
129# RPC server that uses Nanopb to encode and decode protobufs. RPCs use Nanopb
130# structs as their requests and responses.
131_pw_rpc_server_library("nanopb_server") {
132 implementation = "nanopb"
133}
134
135config("private_includes") {
136 include_dirs = [ "." ]
Wyatt Hepler7da973a2020-06-09 10:04:48 -0700137 visibility = [ ":*" ]
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700138}
139
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700140pw_proto_library("protos") {
141 sources = [ "pw_rpc_protos/packet.proto" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700142}
143
Alexei Frolov7c7a3862020-07-16 15:36:02 -0700144pw_proto_library("echo_service_proto") {
145 sources = [ "pw_rpc_protos/echo.proto" ]
146 inputs = [ "pw_rpc_protos/echo.options" ]
147}
148
Alexei Frolov79b7cb02020-07-06 13:51:43 -0700149# Source files for pw_protobuf's protoc plugin.
150pw_input_group("nanopb_protoc_plugin") {
151 inputs = [
152 "py/pw_rpc/codegen_nanopb.py",
153 "py/pw_rpc/plugin.py",
154 "py/pw_rpc/ids.py",
155 ]
Alexei Frolov15255c52020-07-17 08:25:49 -0700156 deps = [ "$dir_pw_protobuf:codegen_protoc_lib" ]
Alexei Frolov79b7cb02020-07-06 13:51:43 -0700157}
158
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700159pw_doc_group("docs") {
160 sources = [ "docs.rst" ]
Alexei Frolov7c7a3862020-07-16 15:36:02 -0700161 inputs = [
162 "pw_rpc_protos/echo.proto",
163 "pw_rpc_protos/packet.proto",
164 ]
165 group_deps = [ "nanopb:docs" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700166}
167
168pw_test_group("tests") {
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700169 tests = [
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700170 ":base_server_writer_test",
Wyatt Hepler671946e2020-06-09 14:39:33 -0700171 ":channel_test",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700172 ":packet_test",
173 ":server_test",
Wyatt Heplerd1591422020-09-15 10:04:41 -0700174 ":service_test",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700175 ]
Wyatt Hepleraf835682020-06-17 11:42:53 -0700176 group_deps = [ "nanopb:tests" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700177}
178
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700179# RPC server for tests only. A mock method implementation is used.
180_pw_rpc_server_library("test_server") {
Wyatt Hepler948f5472020-06-02 16:52:28 -0700181 implementation = "test_impl"
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700182 visibility = [ ":*" ]
183}
184
Wyatt Hepler948f5472020-06-02 16:52:28 -0700185pw_proto_library("test_protos") {
186 sources = [ "pw_rpc_test_protos/test.proto" ]
187 visibility = [ "./*" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700188}
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700189
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700190pw_test("base_server_writer_test") {
191 deps = [
Wyatt Hepler8aa02922020-07-17 08:54:37 -0700192 ":internal_test_utils_test_server",
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700193 ":test_server",
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700194 ]
195 sources = [ "base_server_writer_test.cc" ]
196}
197
Wyatt Hepler671946e2020-06-09 14:39:33 -0700198pw_test("channel_test") {
199 deps = [
200 ":common",
Wyatt Hepler8aa02922020-07-17 08:54:37 -0700201 ":internal_test_utils_test_server",
Wyatt Hepler671946e2020-06-09 14:39:33 -0700202 ]
203 sources = [ "channel_test.cc" ]
204}
205
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700206pw_test("packet_test") {
207 deps = [
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700208 ":common",
Wyatt Hepler0f262352020-07-29 09:51:27 -0700209 dir_pw_bytes,
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700210 dir_pw_protobuf,
211 ]
212 sources = [ "packet_test.cc" ]
213}
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700214
Wyatt Heplerd1591422020-09-15 10:04:41 -0700215pw_test("service_test") {
216 deps = [
217 ":common",
218 ":protos_pwpb",
219 ":test_server",
220 dir_pw_assert,
221 ]
222 sources = [ "service_test.cc" ]
223}
224
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700225pw_test("server_test") {
226 deps = [
Wyatt Hepler8aa02922020-07-17 08:54:37 -0700227 ":internal_test_utils_test_server",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700228 ":protos_pwpb",
229 ":test_server",
230 dir_pw_assert,
231 ]
232 sources = [ "server_test.cc" ]
233}