xref: /aosp_15_r20/external/pigweed/pw_hdlc/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2021 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_async2/backend.gni")
18import("$dir_pw_bloat/bloat.gni")
19import("$dir_pw_build/python.gni")
20import("$dir_pw_build/target_types.gni")
21import("$dir_pw_docgen/docs.gni")
22import("$dir_pw_fuzzer/fuzz_test.gni")
23import("$dir_pw_unit_test/test.gni")
24
25config("default_config") {
26  include_dirs = [ "public" ]
27}
28
29group("pw_hdlc") {
30  public_deps = [
31    ":decoder",
32    ":encoded_size",
33    ":encoder",
34  ]
35}
36
37pw_source_set("common") {
38  public_configs = [ ":default_config" ]
39  public = [ "public/pw_hdlc/internal/protocol.h" ]
40  public_deps = [ dir_pw_varint ]
41  visibility = [ ":*" ]
42}
43
44pw_source_set("encoded_size") {
45  public_configs = [ ":default_config" ]
46  public = [ "public/pw_hdlc/encoded_size.h" ]
47  public_deps = [
48    ":common",
49    "$dir_pw_bytes",
50    "$dir_pw_span",
51    "$dir_pw_varint",
52  ]
53}
54
55pw_source_set("decoder") {
56  public_configs = [ ":default_config" ]
57  public = [ "public/pw_hdlc/decoder.h" ]
58  sources = [ "decoder.cc" ]
59  public_deps = [
60    ":common",
61    dir_pw_bytes,
62    dir_pw_checksum,
63    dir_pw_result,
64    dir_pw_span,
65    dir_pw_status,
66  ]
67  deps = [ dir_pw_log ]
68  friend = [ ":*" ]
69}
70
71pw_source_set("encoder") {
72  public_configs = [ ":default_config" ]
73  public = [ "public/pw_hdlc/encoder.h" ]
74  sources = [ "encoder.cc" ]
75  public_deps = [
76    ":common",
77    dir_pw_bytes,
78    dir_pw_checksum,
79    dir_pw_span,
80    dir_pw_status,
81    dir_pw_stream,
82  ]
83  deps = [ ":encoded_size" ]
84  friend = [ ":*" ]
85}
86
87pw_source_set("rpc_channel_output") {
88  public_configs = [ ":default_config" ]
89  public = [ "public/pw_hdlc/rpc_channel.h" ]
90  public_deps = [
91    ":pw_hdlc",
92    "$dir_pw_rpc:server",
93    dir_pw_span,
94  ]
95}
96
97pw_source_set("default_addresses") {
98  public_configs = [ ":default_config" ]
99  public = [ "public/pw_hdlc/default_addresses.h" ]
100}
101
102pw_source_set("packet_parser") {
103  public_configs = [ ":default_config" ]
104  public = [ "public/pw_hdlc/wire_packet_parser.h" ]
105  sources = [ "wire_packet_parser.cc" ]
106  public_deps = [
107    ":pw_hdlc",
108    "$dir_pw_router:packet_parser",
109  ]
110  deps = [
111    dir_pw_bytes,
112    dir_pw_checksum,
113  ]
114}
115
116# A backend for pw_rpc's `system_server` that sends and receives HDLC-framed RPC
117# packets over pw_sys_io.
118#
119# Warning: This system server is polling and blocking, so it's not
120# production-ready. This exists for simplifying initial bringup/testing, and
121# should not be used in any performance-sensitive application.
122pw_source_set("hdlc_sys_io_system_server") {
123  deps = [
124    "$dir_pw_hdlc:decoder",
125    "$dir_pw_hdlc:default_addresses",
126    "$dir_pw_hdlc:rpc_channel_output",
127    "$dir_pw_rpc/system_server:facade",
128    "$dir_pw_stream:sys_io_stream",
129    dir_pw_log,
130  ]
131  sources = [ "hdlc_sys_io_system_server.cc" ]
132}
133
134pw_source_set("router") {
135  public_configs = [ ":default_config" ]
136  public_deps = [
137    ":decoder",
138    "$dir_pw_async2:dispatcher",
139    "$dir_pw_async2:poll",
140    "$dir_pw_containers:vector",
141    "$dir_pw_multibuf:allocator",
142    dir_pw_channel,
143    dir_pw_multibuf,
144    dir_pw_status,
145  ]
146  deps = [
147    ":encoder",
148    "$dir_pw_multibuf:stream",
149    dir_pw_log,
150    dir_pw_result,
151    dir_pw_stream,
152  ]
153  public = [ "public/pw_hdlc/router.h" ]
154  sources = [ "router.cc" ]
155}
156
157pw_test("router_test") {
158  enable_if = pw_async2_DISPATCHER_BACKEND != ""
159  deps = [
160    ":router",
161    "$dir_pw_allocator:testing",
162    "$dir_pw_async2:pend_func_task",
163    "$dir_pw_channel:forwarding_channel",
164    "$dir_pw_channel:loopback_channel",
165    "$dir_pw_multibuf:simple_allocator",
166  ]
167  sources = [ "router_test.cc" ]
168}
169
170pw_test_group("tests") {
171  tests = [
172    ":encoded_size_test",
173    ":encoder_test",
174    ":decoder_test",
175    ":router_test",
176    ":rpc_channel_test",
177    ":wire_packet_parser_test",
178  ]
179  group_deps = [
180    "$dir_pw_preprocessor:tests",
181    "$dir_pw_status:tests",
182    "$dir_pw_stream:tests",
183  ]
184}
185
186pw_test("encoded_size_test") {
187  deps = [
188    ":pw_hdlc",
189    "$dir_pw_bytes",
190    "$dir_pw_result",
191    "$dir_pw_stream",
192    "$dir_pw_varint",
193  ]
194  sources = [ "encoded_size_test.cc" ]
195
196  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
197  configs = [ "$dir_pw_build:conversion_warnings" ]
198}
199
200pw_test("encoder_test") {
201  deps = [ ":pw_hdlc" ]
202  sources = [ "encoder_test.cc" ]
203
204  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
205  configs = [ "$dir_pw_build:conversion_warnings" ]
206}
207
208pw_python_action("generate_decoder_test") {
209  outputs = [ "$target_gen_dir/generated_decoder_test.cc" ]
210  script = "py/decode_test.py"
211  args = [ "--generate-cc-test" ] + rebase_path(outputs, root_build_dir)
212  python_deps = [
213    "$dir_pw_build/py",
214    "py",
215  ]
216}
217
218pw_fuzz_test("decoder_test") {
219  deps = [ ":pw_hdlc" ]
220  source_gen_deps = [ ":generate_decoder_test" ]
221  sources = [ "decoder_test.cc" ]
222
223  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
224  configs = [ "$dir_pw_build:conversion_warnings" ]
225}
226
227pw_test("rpc_channel_test") {
228  deps = [
229    ":pw_hdlc",
230    ":rpc_channel_output",
231  ]
232  sources = [ "rpc_channel_test.cc" ]
233
234  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
235  configs = [ "$dir_pw_build:conversion_warnings" ]
236}
237
238pw_test("wire_packet_parser_test") {
239  deps = [
240    ":packet_parser",
241    dir_pw_bytes,
242  ]
243  sources = [ "wire_packet_parser_test.cc" ]
244
245  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
246  configs = [ "$dir_pw_build:conversion_warnings" ]
247}
248
249pw_size_diff("size_report") {
250  title = "HDLC sizes"
251
252  binaries = [
253    {
254      target = "size_report:full"
255      base = "size_report:base"
256      label = "HDLC encode and decode"
257    },
258    {
259      target = "size_report:full_crc"
260      base = "size_report:base_crc"
261      label = "HDLC encode and decode, ignoring CRC and varint"
262    },
263  ]
264}
265
266pw_doc_group("docs") {
267  sources = [
268    "api.rst",
269    "design.rst",
270    "docs.rst",
271    "guide.rst",
272    "router.rst",
273    "rpc_example/docs.rst",
274    "size.rst",
275  ]
276  inputs = [
277    "Kconfig",
278    "py/pw_hdlc/decode.py",
279    "py/pw_hdlc/encode.py",
280  ]
281  report_deps = [ ":size_report" ]
282}
283