blob: 2cc9a8f196af5f44aa1de18f21c12c08aefe3346 [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 "public/pw_rpc/internal/service.h",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070060 "server.cc",
61 "service.cc",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070062 ]
63 allow_circular_includes_from = [ implementation ]
Wyatt Hepler948f5472020-06-02 16:52:28 -070064 friend = [ "./*" ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070065 }
Wyatt Hepler7da973a2020-06-09 10:04:48 -070066
Alexei Frolov2e55ee22020-06-17 17:00:10 -070067 pw_source_set("test_utils_$_target_name") {
Wyatt Hepler7da973a2020-06-09 10:04:48 -070068 public = [ "pw_rpc_private/test_utils.h" ]
69 public_configs = [ ":private_includes" ]
70 public_deps = [
71 ":$_target_name",
72 ":common",
73 dir_pw_span,
74 ]
75 visibility = [ "./*" ]
76 }
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070077}
78
Wyatt Hepler3e2d7192020-06-11 08:28:21 -070079# Put these dependencies into a group since they need to be shared by the server
80# library and its implementation library.
81group("server_library_deps") {
82 public_configs = [ ":default_config" ]
83 public_deps = [
84 ":common",
85 "$dir_pw_containers:intrusive_list",
86 dir_pw_span,
87 dir_pw_status,
88 ]
89 visibility = [ "./*" ]
90}
91
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070092# Classes with no dependencies on the protobuf library for method invocations.
Alexei Frolovedd2f142020-06-09 19:11:27 -070093pw_source_set("common") {
Alexei Frolov26e3ae62020-05-04 17:06:17 -070094 public_configs = [ ":default_config" ]
95 public_deps = [
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070096 ":protos_pwpb",
Alexei Frolov26e3ae62020-05-04 17:06:17 -070097 dir_pw_assert,
Wyatt Hepler671946e2020-06-09 14:39:33 -070098 dir_pw_log,
Alexei Frolov26e3ae62020-05-04 17:06:17 -070099 dir_pw_span,
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700100 dir_pw_status,
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700101 ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700102 public = [ "public/pw_rpc/channel.h" ]
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700103 sources = [
104 "channel.cc",
105 "packet.cc",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700106 "public/pw_rpc/internal/base_method.h",
Wyatt Hepler7da973a2020-06-09 10:04:48 -0700107 "public/pw_rpc/internal/call.h",
Wyatt Hepler671946e2020-06-09 14:39:33 -0700108 "public/pw_rpc/internal/channel.h",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700109 "public/pw_rpc/internal/packet.h",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700110 ]
Wyatt Hepler948f5472020-06-02 16:52:28 -0700111 friend = [ "./*" ]
112 visibility = [ "./*" ]
113}
114
115# RPC server that uses Nanopb to encode and decode protobufs. RPCs use Nanopb
116# structs as their requests and responses.
117_pw_rpc_server_library("nanopb_server") {
118 implementation = "nanopb"
119}
120
121config("private_includes") {
122 include_dirs = [ "." ]
Wyatt Hepler7da973a2020-06-09 10:04:48 -0700123 visibility = [ ":*" ]
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700124}
125
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700126pw_proto_library("protos") {
127 sources = [ "pw_rpc_protos/packet.proto" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700128}
129
130pw_doc_group("docs") {
131 sources = [ "docs.rst" ]
132}
133
134pw_test_group("tests") {
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700135 tests = [
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700136 ":base_server_writer_test",
Wyatt Hepler671946e2020-06-09 14:39:33 -0700137 ":channel_test",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700138 ":packet_test",
139 ":server_test",
Wyatt Hepler671946e2020-06-09 14:39:33 -0700140 "nanopb:method_test",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700141 ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700142}
143
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700144# RPC server for tests only. A mock method implementation is used.
145_pw_rpc_server_library("test_server") {
Wyatt Hepler948f5472020-06-02 16:52:28 -0700146 implementation = "test_impl"
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700147 visibility = [ ":*" ]
148}
149
Wyatt Hepler948f5472020-06-02 16:52:28 -0700150pw_proto_library("test_protos") {
151 sources = [ "pw_rpc_test_protos/test.proto" ]
152 visibility = [ "./*" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700153}
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700154
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700155pw_test("base_server_writer_test") {
156 deps = [
157 ":test_server",
Wyatt Hepler7da973a2020-06-09 10:04:48 -0700158 ":test_utils_test_server",
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700159 ]
160 sources = [ "base_server_writer_test.cc" ]
161}
162
Wyatt Hepler671946e2020-06-09 14:39:33 -0700163pw_test("channel_test") {
164 deps = [
165 ":common",
166 ":test_utils_test_server",
167 ]
168 sources = [ "channel_test.cc" ]
169}
170
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700171pw_test("packet_test") {
172 deps = [
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700173 ":common",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700174 dir_pw_protobuf,
175 ]
176 sources = [ "packet_test.cc" ]
177}
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700178
179pw_test("server_test") {
180 deps = [
181 ":protos_pwpb",
182 ":test_server",
Wyatt Hepler7da973a2020-06-09 10:04:48 -0700183 ":test_utils_test_server",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700184 dir_pw_assert,
185 ]
186 sources = [ "server_test.cc" ]
187}