blob: cc6531610a9320741695648ceea13694c7f9ad75 [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
18import("$dir_pigweed/legacy_target.gni")
Alexei Frolovedd2f142020-06-09 19:11:27 -070019import("$dir_pw_build/target_types.gni")
Alexei Frolov26e3ae62020-05-04 17:06:17 -070020import("$dir_pw_docgen/docs.gni")
Alexei Frolov5d6d3922020-05-08 13:57:02 -070021import("$dir_pw_protobuf_compiler/proto.gni")
Alexei Frolov26e3ae62020-05-04 17:06:17 -070022import("$dir_pw_unit_test/test.gni")
Alexei Frolov26e3ae62020-05-04 17:06:17 -070023config("default_config") {
24 include_dirs = [ "public" ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070025 visibility = [ ":*" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -070026}
27
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070028# pw_rpc servers depend on the protobuf library used to encode and decode
29# requests and responses when invoking methods. This template is used to create
30# instances of the pw_rpc server library with different implementations.
31#
32# The implementation parameter must refer to a library that provides the
33# definition of the Method class in pw_rpc/internal/method.h. The Method class
34# provides the Invoke function, which handles the server use to call into the
35# RPC functions themselves.
36template("_pw_rpc_server_library") {
37 assert(defined(invoker.implementation),
38 "_pw_rpc_server_library requires an implementation to be set")
Wyatt Hepler7da973a2020-06-09 10:04:48 -070039 _target_name = target_name
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070040
Alexei Frolovedd2f142020-06-09 19:11:27 -070041 pw_source_set(_target_name) {
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070042 forward_variables_from(invoker, "*")
43
44 public_configs = [ ":default_config" ]
45 public_deps = [
46 ":common",
47 dir_pw_span,
48 dir_pw_status,
49 implementation,
50 ]
51 deps = [
52 dir_pw_assert,
53 dir_pw_log,
54 ]
55 public = [
56 "public/pw_rpc/server.h",
57 "public/pw_rpc/server_context.h",
58 ]
59 sources = [
Wyatt Heplercb9d9572020-06-01 11:25:58 -070060 "base_server_writer.cc",
61 "public/pw_rpc/internal/base_server_writer.h",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070062 "public/pw_rpc/internal/service.h",
63 "public/pw_rpc/internal/service_registry.h",
64 "server.cc",
65 "service.cc",
66 "service_registry.cc",
67 ]
68 allow_circular_includes_from = [ implementation ]
Wyatt Hepler948f5472020-06-02 16:52:28 -070069 friend = [ "./*" ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070070 }
Wyatt Hepler7da973a2020-06-09 10:04:48 -070071
72 source_set("test_utils_$_target_name") {
73 public = [ "pw_rpc_private/test_utils.h" ]
74 public_configs = [ ":private_includes" ]
75 public_deps = [
76 ":$_target_name",
77 ":common",
78 dir_pw_span,
79 ]
80 visibility = [ "./*" ]
81 }
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070082}
83
84# Classes with no dependencies on the protobuf library for method invocations.
Alexei Frolovedd2f142020-06-09 19:11:27 -070085pw_source_set("common") {
Alexei Frolov26e3ae62020-05-04 17:06:17 -070086 public_configs = [ ":default_config" ]
87 public_deps = [
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070088 ":protos_pwpb",
Alexei Frolov26e3ae62020-05-04 17:06:17 -070089 dir_pw_assert,
90 dir_pw_span,
Alexei Frolov5d6d3922020-05-08 13:57:02 -070091 dir_pw_status,
Alexei Frolov26e3ae62020-05-04 17:06:17 -070092 ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070093 public = [ "public/pw_rpc/channel.h" ]
Alexei Frolov5d6d3922020-05-08 13:57:02 -070094 sources = [
95 "channel.cc",
96 "packet.cc",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070097 "public/pw_rpc/internal/base_method.h",
Wyatt Hepler7da973a2020-06-09 10:04:48 -070098 "public/pw_rpc/internal/call.h",
Alexei Frolov5d6d3922020-05-08 13:57:02 -070099 "public/pw_rpc/internal/packet.h",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700100 ]
Wyatt Hepler948f5472020-06-02 16:52:28 -0700101 friend = [ "./*" ]
102 visibility = [ "./*" ]
103}
104
105# RPC server that uses Nanopb to encode and decode protobufs. RPCs use Nanopb
106# structs as their requests and responses.
107_pw_rpc_server_library("nanopb_server") {
108 implementation = "nanopb"
109}
110
111config("private_includes") {
112 include_dirs = [ "." ]
Wyatt Hepler7da973a2020-06-09 10:04:48 -0700113 visibility = [ ":*" ]
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700114}
115
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700116pw_proto_library("protos") {
117 sources = [ "pw_rpc_protos/packet.proto" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700118}
119
120pw_doc_group("docs") {
121 sources = [ "docs.rst" ]
122}
123
124pw_test_group("tests") {
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700125 tests = [
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700126 ":base_server_writer_test",
Wyatt Hepler948f5472020-06-02 16:52:28 -0700127 "nanopb:method_test",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700128 ":packet_test",
129 ":server_test",
130 ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700131}
132
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700133# RPC server for tests only. A mock method implementation is used.
134_pw_rpc_server_library("test_server") {
Wyatt Hepler948f5472020-06-02 16:52:28 -0700135 implementation = "test_impl"
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700136 visibility = [ ":*" ]
137}
138
Wyatt Hepler948f5472020-06-02 16:52:28 -0700139pw_proto_library("test_protos") {
140 sources = [ "pw_rpc_test_protos/test.proto" ]
141 visibility = [ "./*" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700142}
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700143
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700144pw_test("base_server_writer_test") {
145 deps = [
146 ":test_server",
Wyatt Hepler7da973a2020-06-09 10:04:48 -0700147 ":test_utils_test_server",
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700148 ]
149 sources = [ "base_server_writer_test.cc" ]
150}
151
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700152pw_test("packet_test") {
153 deps = [
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700154 ":common",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700155 dir_pw_protobuf,
156 ]
157 sources = [ "packet_test.cc" ]
158}
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700159
160pw_test("server_test") {
161 deps = [
162 ":protos_pwpb",
163 ":test_server",
Wyatt Hepler7da973a2020-06-09 10:04:48 -0700164 ":test_utils_test_server",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700165 dir_pw_assert,
166 ]
167 sources = [ "server_test.cc" ]
168}