blob: 404429cc93d3f8cf4b6716d8d5bee329640d6ae6 [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
Alexei Frolovedd2f142020-06-09 19:11:27 -070015import("$dir_pw_build/target_types.gni")
Alexei Frolov26e3ae62020-05-04 17:06:17 -070016import("$dir_pw_docgen/docs.gni")
Alexei Frolov5d6d3922020-05-08 13:57:02 -070017import("$dir_pw_protobuf_compiler/proto.gni")
Alexei Frolov26e3ae62020-05-04 17:06:17 -070018import("$dir_pw_unit_test/test.gni")
19
20config("default_config") {
21 include_dirs = [ "public" ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070022 visibility = [ ":*" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -070023}
24
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070025# pw_rpc servers depend on the protobuf library used to encode and decode
26# requests and responses when invoking methods. This template is used to create
27# instances of the pw_rpc server library with different implementations.
28#
29# The implementation parameter must refer to a library that provides the
30# definition of the Method class in pw_rpc/internal/method.h. The Method class
31# provides the Invoke function, which handles the server use to call into the
32# RPC functions themselves.
33template("_pw_rpc_server_library") {
34 assert(defined(invoker.implementation),
35 "_pw_rpc_server_library requires an implementation to be set")
Wyatt Hepler7da973a2020-06-09 10:04:48 -070036 _target_name = target_name
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070037
Alexei Frolovedd2f142020-06-09 19:11:27 -070038 pw_source_set(_target_name) {
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070039 forward_variables_from(invoker, "*")
40
41 public_configs = [ ":default_config" ]
42 public_deps = [
43 ":common",
44 dir_pw_span,
45 dir_pw_status,
46 implementation,
47 ]
48 deps = [
49 dir_pw_assert,
50 dir_pw_log,
51 ]
52 public = [
53 "public/pw_rpc/server.h",
54 "public/pw_rpc/server_context.h",
55 ]
56 sources = [
Wyatt Heplercb9d9572020-06-01 11:25:58 -070057 "base_server_writer.cc",
58 "public/pw_rpc/internal/base_server_writer.h",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070059 "public/pw_rpc/internal/service.h",
60 "public/pw_rpc/internal/service_registry.h",
61 "server.cc",
62 "service.cc",
63 "service_registry.cc",
64 ]
65 allow_circular_includes_from = [ implementation ]
Wyatt Hepler948f5472020-06-02 16:52:28 -070066 friend = [ "./*" ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070067 }
Wyatt Hepler7da973a2020-06-09 10:04:48 -070068
69 source_set("test_utils_$_target_name") {
70 public = [ "pw_rpc_private/test_utils.h" ]
71 public_configs = [ ":private_includes" ]
72 public_deps = [
73 ":$_target_name",
74 ":common",
75 dir_pw_span,
76 ]
77 visibility = [ "./*" ]
78 }
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070079}
80
81# Classes with no dependencies on the protobuf library for method invocations.
Alexei Frolovedd2f142020-06-09 19:11:27 -070082pw_source_set("common") {
Alexei Frolov26e3ae62020-05-04 17:06:17 -070083 public_configs = [ ":default_config" ]
84 public_deps = [
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070085 ":protos_pwpb",
Alexei Frolov26e3ae62020-05-04 17:06:17 -070086 dir_pw_assert,
87 dir_pw_span,
Alexei Frolov5d6d3922020-05-08 13:57:02 -070088 dir_pw_status,
Alexei Frolov26e3ae62020-05-04 17:06:17 -070089 ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070090 public = [ "public/pw_rpc/channel.h" ]
Alexei Frolov5d6d3922020-05-08 13:57:02 -070091 sources = [
92 "channel.cc",
93 "packet.cc",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070094 "public/pw_rpc/internal/base_method.h",
Wyatt Hepler7da973a2020-06-09 10:04:48 -070095 "public/pw_rpc/internal/call.h",
Alexei Frolov5d6d3922020-05-08 13:57:02 -070096 "public/pw_rpc/internal/packet.h",
Alexei Frolov5d6d3922020-05-08 13:57:02 -070097 ]
Wyatt Hepler948f5472020-06-02 16:52:28 -070098 friend = [ "./*" ]
99 visibility = [ "./*" ]
100}
101
102# RPC server that uses Nanopb to encode and decode protobufs. RPCs use Nanopb
103# structs as their requests and responses.
104_pw_rpc_server_library("nanopb_server") {
105 implementation = "nanopb"
106}
107
108config("private_includes") {
109 include_dirs = [ "." ]
Wyatt Hepler7da973a2020-06-09 10:04:48 -0700110 visibility = [ ":*" ]
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700111}
112
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700113pw_proto_library("protos") {
114 sources = [ "pw_rpc_protos/packet.proto" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700115}
116
117pw_doc_group("docs") {
118 sources = [ "docs.rst" ]
119}
120
121pw_test_group("tests") {
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700122 tests = [
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700123 ":base_server_writer_test",
Wyatt Hepler948f5472020-06-02 16:52:28 -0700124 "nanopb:method_test",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700125 ":packet_test",
126 ":server_test",
127 ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700128}
129
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700130# RPC server for tests only. A mock method implementation is used.
131_pw_rpc_server_library("test_server") {
Wyatt Hepler948f5472020-06-02 16:52:28 -0700132 implementation = "test_impl"
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700133 visibility = [ ":*" ]
134}
135
Wyatt Hepler948f5472020-06-02 16:52:28 -0700136pw_proto_library("test_protos") {
137 sources = [ "pw_rpc_test_protos/test.proto" ]
138 visibility = [ "./*" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700139}
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700140
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700141pw_test("base_server_writer_test") {
142 deps = [
143 ":test_server",
Wyatt Hepler7da973a2020-06-09 10:04:48 -0700144 ":test_utils_test_server",
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700145 ]
146 sources = [ "base_server_writer_test.cc" ]
147}
148
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700149pw_test("packet_test") {
150 deps = [
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700151 ":common",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700152 dir_pw_protobuf,
153 ]
154 sources = [ "packet_test.cc" ]
155}
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700156
157pw_test("server_test") {
158 deps = [
159 ":protos_pwpb",
160 ":test_server",
Wyatt Hepler7da973a2020-06-09 10:04:48 -0700161 ":test_utils_test_server",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700162 dir_pw_assert,
163 ]
164 sources = [ "server_test.cc" ]
165}