xref: /aosp_15_r20/external/pigweed/pw_rpc/nanopb/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# 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("//build_overrides/pigweed.gni")
16
17import("$dir_pw_build/target_types.gni")
18import("$dir_pw_docgen/docs.gni")
19import("$dir_pw_sync/backend.gni")
20import("$dir_pw_third_party/nanopb/nanopb.gni")
21import("$dir_pw_thread/backend.gni")
22import("$dir_pw_unit_test/test.gni")
23
24config("public") {
25  include_dirs = [ "public" ]
26  visibility = [ ":*" ]
27}
28
29pw_source_set("server_api") {
30  public_configs = [ ":public" ]
31  public = [
32    "public/pw_rpc/nanopb/internal/method.h",
33    "public/pw_rpc/nanopb/internal/method_union.h",
34    "public/pw_rpc/nanopb/server_reader_writer.h",
35  ]
36  sources = [
37    "method.cc",
38    "server_reader_writer.cc",
39  ]
40  public_deps = [
41    ":common",
42    "$dir_pw_rpc/raw:server_api",
43    "..:config",
44    "..:server",
45    dir_pw_bytes,
46    dir_pw_span,
47  ]
48  deps = [
49    "..:log_config",
50    dir_pw_log,
51  ]
52  allow_circular_includes_from = [ ":common" ]
53}
54
55pw_source_set("client_api") {
56  public_configs = [ ":public" ]
57  public_deps = [
58    ":common",
59    "..:client",
60    dir_pw_function,
61  ]
62  public = [ "public/pw_rpc/nanopb/client_reader_writer.h" ]
63}
64
65pw_source_set("common") {
66  public_deps = [
67    "..:common",
68    dir_pw_bytes,
69  ]
70  public_configs = [ ":public" ]
71  deps = [
72    "..:client",
73    "..:log_config",
74    dir_pw_log,
75  ]
76  public = [ "public/pw_rpc/nanopb/internal/common.h" ]
77  sources = [ "common.cc" ]
78
79  if (dir_pw_third_party_nanopb != "") {
80    public_deps += [ "$dir_pw_third_party/nanopb" ]
81  }
82}
83
84pw_source_set("test_method_context") {
85  public_configs = [ ":public" ]
86  public = [
87    "public/pw_rpc/nanopb/fake_channel_output.h",
88    "public/pw_rpc/nanopb/test_method_context.h",
89  ]
90  public_deps = [
91    ":server_api",
92    "..:test_utils",
93    dir_pw_assert,
94    dir_pw_containers,
95  ]
96}
97
98pw_source_set("client_testing") {
99  public = [ "public/pw_rpc/nanopb/client_testing.h" ]
100  public_deps = [
101    ":test_method_context",
102    "..:client",
103    "../raw:client_testing",
104  ]
105}
106
107pw_source_set("client_server_testing") {
108  public = [ "public/pw_rpc/nanopb/client_server_testing.h" ]
109  public_deps = [
110    ":test_method_context",
111    "..:client_server_testing",
112  ]
113}
114
115pw_source_set("client_server_testing_threaded") {
116  public = [ "public/pw_rpc/nanopb/client_server_testing_threaded.h" ]
117  public_deps = [
118    ":test_method_context",
119    "..:client_server_testing_threaded",
120  ]
121}
122
123pw_source_set("internal_test_utils") {
124  public = [ "pw_rpc_nanopb_private/internal_test_utils.h" ]
125  public_deps = [ dir_pw_span ]
126  if (dir_pw_third_party_nanopb != "") {
127    public_deps += [ "$dir_pw_third_party/nanopb" ]
128  }
129}
130
131pw_source_set("echo_service") {
132  public_configs = [ ":public" ]
133  public_deps = [ "..:protos.nanopb_rpc" ]
134  sources = [ "public/pw_rpc/echo_service_nanopb.h" ]
135}
136
137pw_source_set("client_integration_test") {
138  testonly = pw_unit_test_TESTONLY
139  public_configs = [ ":public" ]
140  public_deps = [
141    "$dir_pw_sync:binary_semaphore",
142    "..:integration_testing",
143    "..:protos.nanopb_rpc",
144    dir_pw_assert,
145    dir_pw_unit_test,
146  ]
147  sources = [ "client_integration_test.cc" ]
148}
149
150pw_doc_group("docs") {
151  inputs = [ "Kconfig" ]
152  sources = [ "docs.rst" ]
153}
154
155pw_test_group("tests") {
156  tests = [
157    ":callback_test",
158    ":client_call_test",
159    ":client_reader_writer_test",
160    ":client_server_context_test",
161    ":client_server_context_threaded_test",
162    ":codegen_test",
163    ":echo_service_test",
164    ":fake_channel_output_test",
165    ":method_lookup_test",
166    ":method_test",
167    ":method_info_test",
168    ":method_union_test",
169    ":server_callback_test",
170    ":server_reader_writer_test",
171    ":serde_test",
172    ":stub_generation_test",
173    ":synchronous_call_test",
174  ]
175}
176
177pw_test("callback_test") {
178  enable_if = dir_pw_third_party_nanopb != "" &&
179              pw_thread_THREAD_BACKEND == "$dir_pw_thread_stl:thread"
180  deps = [
181    ":client_testing",
182    "$dir_pw_sync:binary_semaphore",
183    "$dir_pw_thread:non_portable_test_thread_options",
184    "$dir_pw_thread:sleep",
185    "$dir_pw_thread:yield",
186    "$dir_pw_thread_stl:non_portable_test_thread_options",
187    "..:client",
188    "..:server",
189    "..:test_protos.nanopb_rpc",
190  ]
191  sources = [ "callback_test.cc" ]
192}
193
194pw_test("client_call_test") {
195  deps = [
196    ":client_api",
197    ":internal_test_utils",
198    "..:test_protos.nanopb",
199    "..:test_utils",
200  ]
201  sources = [ "client_call_test.cc" ]
202  enable_if = dir_pw_third_party_nanopb != ""
203
204  # TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; hangs
205  # indefinitely.
206  if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") {
207    enable_if = false
208  }
209}
210
211pw_test("client_reader_writer_test") {
212  deps = [
213    ":client_api",
214    ":client_testing",
215    "..:test_protos.nanopb_rpc",
216  ]
217  sources = [ "client_reader_writer_test.cc" ]
218  enable_if = dir_pw_third_party_nanopb != ""
219}
220
221pw_test("client_server_context_test") {
222  deps = [
223    ":client_api",
224    ":client_server_testing",
225    "$dir_pw_sync:mutex",
226    "..:test_protos.nanopb_rpc",
227  ]
228  sources = [ "client_server_context_test.cc" ]
229  enable_if = dir_pw_third_party_nanopb != "" && pw_sync_MUTEX_BACKEND != ""
230}
231
232_stl_threading_and_nanopb_enabled =
233    pw_thread_THREAD_BACKEND == "$dir_pw_thread_stl:thread" &&
234    pw_sync_BINARY_SEMAPHORE_BACKEND != "" && pw_sync_MUTEX_BACKEND != "" &&
235    dir_pw_third_party_nanopb != ""
236
237pw_test("client_server_context_threaded_test") {
238  deps = [
239    ":client_api",
240    ":client_server_testing_threaded",
241    "$dir_pw_sync:binary_semaphore",
242    "$dir_pw_sync:mutex",
243    "$dir_pw_thread:non_portable_test_thread_options",
244    "$dir_pw_thread_stl:non_portable_test_thread_options",
245    "..:test_protos.nanopb_rpc",
246  ]
247  sources = [ "client_server_context_threaded_test.cc" ]
248  enable_if = _stl_threading_and_nanopb_enabled
249}
250
251pw_test("codegen_test") {
252  deps = [
253    ":client_api",
254    ":internal_test_utils",
255    ":server_api",
256    ":test_method_context",
257    "..:test_protos.nanopb_rpc",
258    "..:test_utils",
259  ]
260  sources = [ "codegen_test.cc" ]
261  enable_if = dir_pw_third_party_nanopb != ""
262}
263
264pw_test("fake_channel_output_test") {
265  deps = [
266    ":server_api",
267    ":test_method_context",
268    "..:test_protos.nanopb_rpc",
269  ]
270  sources = [ "fake_channel_output_test.cc" ]
271  enable_if = dir_pw_third_party_nanopb != ""
272}
273
274pw_test("method_test") {
275  deps = [
276    ":internal_test_utils",
277    ":server_api",
278    "$dir_pw_containers",
279    "..:test_protos.nanopb",
280    "..:test_utils",
281  ]
282  sources = [ "method_test.cc" ]
283  enable_if = dir_pw_third_party_nanopb != ""
284}
285
286pw_test("method_info_test") {
287  deps = [
288    "..:common",
289    "..:test_protos.nanopb_rpc",
290    "..:test_utils",
291  ]
292  sources = [ "method_info_test.cc" ]
293  enable_if = dir_pw_third_party_nanopb != ""
294}
295
296pw_test("method_lookup_test") {
297  deps = [
298    ":server_api",
299    ":test_method_context",
300    "..:test_protos.nanopb_rpc",
301    "..:test_utils",
302    "../raw:test_method_context",
303  ]
304  sources = [ "method_lookup_test.cc" ]
305  enable_if = dir_pw_third_party_nanopb != ""
306}
307
308pw_test("method_union_test") {
309  deps = [
310    ":internal_test_utils",
311    ":server_api",
312    "..:test_protos.nanopb",
313    "..:test_utils",
314  ]
315  sources = [ "method_union_test.cc" ]
316  enable_if = dir_pw_third_party_nanopb != ""
317}
318
319pw_test("echo_service_test") {
320  deps = [
321    ":echo_service",
322    ":server_api",
323    ":test_method_context",
324  ]
325  sources = [ "echo_service_test.cc" ]
326  enable_if = dir_pw_third_party_nanopb != ""
327}
328
329pw_test("serde_test") {
330  deps = [
331    ":server_api",
332    "..:test_protos.nanopb",
333  ]
334  sources = [ "serde_test.cc" ]
335  enable_if = dir_pw_third_party_nanopb != ""
336}
337
338pw_test("server_callback_test") {
339  deps = [
340    ":server_api",
341    ":test_method_context",
342    "..:test_protos.nanopb_rpc",
343  ]
344  sources = [ "server_callback_test.cc" ]
345  enable_if = dir_pw_third_party_nanopb != ""
346}
347
348pw_test("server_reader_writer_test") {
349  deps = [
350    ":server_api",
351    ":test_method_context",
352    "..:test_protos.nanopb_rpc",
353  ]
354  sources = [ "server_reader_writer_test.cc" ]
355  enable_if = dir_pw_third_party_nanopb != ""
356}
357
358pw_test("stub_generation_test") {
359  deps = [ "..:test_protos.nanopb_rpc" ]
360  sources = [ "stub_generation_test.cc" ]
361  enable_if = dir_pw_third_party_nanopb != ""
362}
363
364pw_test("synchronous_call_test") {
365  deps = [
366    ":test_method_context",
367    "$dir_pw_work_queue:pw_work_queue",
368    "$dir_pw_work_queue:stl_test_thread",
369    "$dir_pw_work_queue:test_thread",
370    "..:synchronous_client_api",
371    "..:test_protos.nanopb_rpc",
372  ]
373  sources = [ "synchronous_call_test.cc" ]
374  enable_if = dir_pw_third_party_nanopb != "" &&
375              pw_sync_TIMED_THREAD_NOTIFICATION_BACKEND != ""
376
377  # TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; hangs
378  # indefinitely.
379  if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") {
380    enable_if = false
381  }
382}
383