blob: c8512e1491b6be32062beb112ea07e3e69a1698e [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
15import("$dir_pw_docgen/docs.gni")
Alexei Frolov5d6d3922020-05-08 13:57:02 -070016import("$dir_pw_protobuf_compiler/proto.gni")
Alexei Frolov26e3ae62020-05-04 17:06:17 -070017import("$dir_pw_unit_test/test.gni")
18
19config("default_config") {
20 include_dirs = [ "public" ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070021 visibility = [ ":*" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -070022}
23
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070024# pw_rpc servers depend on the protobuf library used to encode and decode
25# requests and responses when invoking methods. This template is used to create
26# instances of the pw_rpc server library with different implementations.
27#
28# The implementation parameter must refer to a library that provides the
29# definition of the Method class in pw_rpc/internal/method.h. The Method class
30# provides the Invoke function, which handles the server use to call into the
31# RPC functions themselves.
32template("_pw_rpc_server_library") {
33 assert(defined(invoker.implementation),
34 "_pw_rpc_server_library requires an implementation to be set")
35
36 source_set(target_name) {
37 forward_variables_from(invoker, "*")
38
39 public_configs = [ ":default_config" ]
40 public_deps = [
41 ":common",
42 dir_pw_span,
43 dir_pw_status,
44 implementation,
45 ]
46 deps = [
47 dir_pw_assert,
48 dir_pw_log,
49 ]
50 public = [
51 "public/pw_rpc/server.h",
52 "public/pw_rpc/server_context.h",
53 ]
54 sources = [
Wyatt Heplercb9d9572020-06-01 11:25:58 -070055 "base_server_writer.cc",
56 "public/pw_rpc/internal/base_server_writer.h",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070057 "public/pw_rpc/internal/service.h",
58 "public/pw_rpc/internal/service_registry.h",
59 "server.cc",
60 "service.cc",
61 "service_registry.cc",
62 ]
63 allow_circular_includes_from = [ implementation ]
Wyatt Hepler948f5472020-06-02 16:52:28 -070064 friend = [ "./*" ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070065 }
66}
67
68# Classes with no dependencies on the protobuf library for method invocations.
69source_set("common") {
Alexei Frolov26e3ae62020-05-04 17:06:17 -070070 public_configs = [ ":default_config" ]
71 public_deps = [
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070072 ":protos_pwpb",
Alexei Frolov26e3ae62020-05-04 17:06:17 -070073 dir_pw_assert,
74 dir_pw_span,
Alexei Frolov5d6d3922020-05-08 13:57:02 -070075 dir_pw_status,
Alexei Frolov26e3ae62020-05-04 17:06:17 -070076 ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070077 public = [ "public/pw_rpc/channel.h" ]
Alexei Frolov5d6d3922020-05-08 13:57:02 -070078 sources = [
79 "channel.cc",
80 "packet.cc",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070081 "public/pw_rpc/internal/base_method.h",
Alexei Frolov5d6d3922020-05-08 13:57:02 -070082 "public/pw_rpc/internal/packet.h",
Alexei Frolov5d6d3922020-05-08 13:57:02 -070083 ]
Wyatt Hepler948f5472020-06-02 16:52:28 -070084 friend = [ "./*" ]
85 visibility = [ "./*" ]
86}
87
88# RPC server that uses Nanopb to encode and decode protobufs. RPCs use Nanopb
89# structs as their requests and responses.
90_pw_rpc_server_library("nanopb_server") {
91 implementation = "nanopb"
92}
93
94config("private_includes") {
95 include_dirs = [ "." ]
96 visibility = [ ":test_utils" ]
Alexei Frolov5d6d3922020-05-08 13:57:02 -070097}
98
Wyatt Heplercb9d9572020-06-01 11:25:58 -070099source_set("test_utils") {
100 public = [ "pw_rpc_private/test_utils.h" ]
Wyatt Hepler948f5472020-06-02 16:52:28 -0700101 public_configs = [ ":private_includes" ]
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700102 public_deps = [
103 ":common",
104 dir_pw_span,
105 ]
Wyatt Hepler948f5472020-06-02 16:52:28 -0700106 visibility = [ "./*" ]
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700107}
108
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700109pw_proto_library("protos") {
110 sources = [ "pw_rpc_protos/packet.proto" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700111}
112
113pw_doc_group("docs") {
114 sources = [ "docs.rst" ]
115}
116
117pw_test_group("tests") {
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700118 tests = [
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700119 ":base_server_writer_test",
Wyatt Hepler948f5472020-06-02 16:52:28 -0700120 "nanopb:method_test",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700121 ":packet_test",
122 ":server_test",
123 ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700124}
125
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700126# RPC server for tests only. A mock method implementation is used.
127_pw_rpc_server_library("test_server") {
Wyatt Hepler948f5472020-06-02 16:52:28 -0700128 implementation = "test_impl"
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700129 visibility = [ ":*" ]
130}
131
Wyatt Hepler948f5472020-06-02 16:52:28 -0700132pw_proto_library("test_protos") {
133 sources = [ "pw_rpc_test_protos/test.proto" ]
134 visibility = [ "./*" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700135}
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700136
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700137pw_test("base_server_writer_test") {
138 deps = [
139 ":test_server",
140 ":test_utils",
141 ]
142 sources = [ "base_server_writer_test.cc" ]
143}
144
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700145pw_test("packet_test") {
146 deps = [
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700147 ":common",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700148 dir_pw_protobuf,
149 ]
150 sources = [ "packet_test.cc" ]
151}
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700152
153pw_test("server_test") {
154 deps = [
155 ":protos_pwpb",
156 ":test_server",
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700157 ":test_utils",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700158 dir_pw_assert,
159 ]
160 sources = [ "server_test.cc" ]
161}