• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// This file is generated by cargo_embargo.
2// Do not modify this file after the first "rust_*" or "genrule" module
3// because the changes will be overridden on upgrade.
4// Content before the first "rust_*" or "genrule" module is preserved.
5
6rust_library_host {
7    name: "libpdl_compiler",
8    crate_name: "pdl_compiler",
9    cargo_env_compat: true,
10    cargo_pkg_version: "0.3.0",
11    crate_root: "src/lib.rs",
12    edition: "2021",
13    features: [
14        "default",
15        "serde",
16    ],
17    rustlibs: [
18        "libargh",
19        "libcodespan_reporting",
20        "libheck",
21        "libpest",
22        "libprettyplease",
23        "libproc_macro2",
24        "libquote",
25        "libserde",
26        "libserde_json",
27        "libsyn",
28    ],
29    proc_macros: ["libpest_derive"],
30    compile_multilib: "first",
31}
32
33rust_binary_host {
34    name: "pdlc",
35    crate_name: "pdlc",
36    cargo_env_compat: true,
37    cargo_pkg_version: "0.3.0",
38    crate_root: "src/main.rs",
39    edition: "2021",
40    features: [
41        "default",
42        "serde",
43    ],
44    rustlibs: [
45        "libargh",
46        "libcodespan_reporting",
47        "libheck",
48        "libpdl_compiler",
49        "libpest",
50        "libprettyplease",
51        "libproc_macro2",
52        "libquote",
53        "libserde",
54        "libserde_json",
55        "libsyn",
56    ],
57    proc_macros: ["libpest_derive"],
58    compile_multilib: "first",
59}
60
61// Defaults for rust backend generation.
62genrule_defaults {
63    name: "pdl_rust_generator_defaults",
64    cmd: "$(location :pdlc) --output-format rust $(in) > $(out)",
65    tools: [":pdlc"],
66    defaults_visibility: [
67        "//system/nfc:__subpackages__",
68        "//external/rust/pica",
69        "//external/uwb/src",
70        "//packages/modules/Bluetooth:__subpackages__",
71        "//tools/netsim:__subpackages__",
72    ],
73}
74
75// Defaults for legacy rust backend generation.
76genrule_defaults {
77    name: "pdl_rust_legacy_generator_defaults",
78    cmd: "$(location :pdlc) --output-format rust_legacy $(in) > $(out)",
79    tools: [":pdlc"],
80    defaults_visibility: [
81        "//system/nfc:__subpackages__",
82        "//external/rust/pica",
83        "//external/uwb/src",
84        "//packages/modules/Bluetooth:__subpackages__",
85        "//tools/netsim:__subpackages__",
86    ],
87}
88
89// Defaults for rust_noalloc backend generation.
90genrule_defaults {
91    name: "pdl_rust_noalloc_generator_defaults",
92    cmd: "$(location :pdlc) --output-format rust_no_alloc $(in) > $(out)",
93    tools: [":pdlc"],
94}
95
96// Defaults for PDL python backend generation.
97genrule_defaults {
98    name: "pdl_python_generator_defaults",
99    tools: [
100        ":pdlc",
101        ":pdl_python_generator",
102    ],
103}
104
105// Defaults for PDL C++ backend generation.
106genrule_defaults {
107    name: "pdl_cxx_generator_defaults",
108    tools: [
109        ":pdlc",
110        ":pdl_cxx_generator",
111    ],
112}
113
114filegroup {
115    name: "pdl_generated_files",
116    srcs: [
117        "tests/generated/rust/**/*.rs",
118    ],
119}
120
121rust_test_host {
122    name: "pdl_tests",
123    srcs: ["src/main.rs"],
124    rustlibs: [
125        "libargh",
126        "libcodespan_reporting",
127        "libheck",
128        "libpdl_compiler",
129        "libpest",
130        "libprettyplease",
131        "libproc_macro2",
132        "libquote",
133        "libserde",
134        "libserde_json",
135        "libsyn",
136        "libtempfile",
137    ],
138    proc_macros: [
139        "libpest_derive",
140        "libpaste",
141    ],
142    test_suites: ["general-tests"],
143    data: [
144        ":pdl_generated_files",
145    ],
146}
147
148genrule {
149    name: "pdl_generated_files_compile_rs",
150    cmd: "$(location tests/generated_files_compile.sh) $(in) > $(out)",
151    srcs: [":pdl_generated_files"],
152    out: ["generated_files_compile.rs"],
153    tool_files: ["tests/generated_files_compile.sh"],
154}
155
156rust_test_host {
157    name: "pdl_generated_files_compile",
158    srcs: [":pdl_generated_files_compile_rs"],
159    features: ["serde"],
160    rustlibs: [
161        "libbytes",
162        "libserde",
163        "libtempfile",
164        "libpdl_runtime",
165    ],
166    test_suites: ["general-tests"],
167    clippy_lints: "none",
168    lints: "none",
169}
170
171// The generators support more features for LE packets than for BE
172// packets. We use a single input written for LE packets and remove
173// the parts that don't work for BE packets. We do this by removing
174// everything between
175//
176// // Start: little_endian_only
177//
178// and
179//
180// // End: little_endian_only
181//
182// from the LE packet input.
183genrule_defaults {
184    name: "pdl_be_test_file_defaults",
185    cmd: "sed -e 's/little_endian_packets/big_endian_packets/' " +
186        "     -e '/Start: little_endian_only/,/End: little_endian_only/d' " +
187        " < $(in) > $(out)",
188}
189
190genrule {
191    name: "pdl_be_test_file",
192    defaults: ["pdl_be_test_file_defaults"],
193    srcs: ["tests/canonical/le_test_file.pdl"],
194    out: ["be_test_file.pdl"],
195}
196
197genrule {
198    name: "pdl_rust_generator_tests_le_src",
199    cmd: "$(location :pdlc)" +
200        " --output-format rust" +
201        " --exclude-declaration UnsizedCustomField" +
202        " --exclude-declaration Packet_Custom_Field_VariableSize" +
203        " --exclude-declaration Struct_Custom_Field_VariableSize_" +
204        " --exclude-declaration Struct_Custom_Field_VariableSize" +
205        " --exclude-declaration Checksum" +
206        " --exclude-declaration Packet_Checksum_Field_FromStart" +
207        " --exclude-declaration Packet_Checksum_Field_FromEnd" +
208        " --exclude-declaration Struct_Checksum_Field_FromStart_" +
209        " --exclude-declaration Struct_Checksum_Field_FromStart" +
210        " --exclude-declaration Struct_Checksum_Field_FromEnd_" +
211        " --exclude-declaration Struct_Checksum_Field_FromEnd" +
212        " --exclude-declaration PartialParent5" +
213        " --exclude-declaration PartialParent12" +
214        " --exclude-declaration PartialChild5_A" +
215        " --exclude-declaration PartialChild5_B" +
216        " --exclude-declaration PartialChild12_A" +
217        " --exclude-declaration PartialChild12_B" +
218        " --exclude-declaration Packet_Array_Field_UnsizedElement_SizeModifier" +
219        " --exclude-declaration Struct_Array_Field_UnsizedElement_SizeModifier_" +
220        " --exclude-declaration Struct_Array_Field_UnsizedElement_SizeModifier" +
221        " $(location tests/canonical/le_test_file.pdl) > $(out);" +
222        "$(location :pdlc) $(location tests/canonical/le_test_vectors.json) --output-format rust --tests >> $(out)",
223    srcs: [
224        "tests/canonical/le_test_file.pdl",
225        "tests/canonical/le_test_vectors.json",
226    ],
227    out: ["le_canonical.rs"],
228    tools: [":pdlc"],
229}
230
231genrule {
232    name: "pdl_rust_generator_tests_be_src",
233    cmd: "$(location :pdlc)" +
234        " --output-format rust" +
235        " --exclude-declaration UnsizedCustomField" +
236        " --exclude-declaration Packet_Custom_Field_VariableSize" +
237        " --exclude-declaration Struct_Custom_Field_VariableSize_" +
238        " --exclude-declaration Struct_Custom_Field_VariableSize" +
239        " --exclude-declaration Checksum" +
240        " --exclude-declaration Packet_Checksum_Field_FromStart" +
241        " --exclude-declaration Packet_Checksum_Field_FromEnd" +
242        " --exclude-declaration Struct_Checksum_Field_FromStart_" +
243        " --exclude-declaration Struct_Checksum_Field_FromStart" +
244        " --exclude-declaration Struct_Checksum_Field_FromEnd_" +
245        " --exclude-declaration Struct_Checksum_Field_FromEnd" +
246        " --exclude-declaration Packet_Array_Field_UnsizedElement_SizeModifier" +
247        " --exclude-declaration Struct_Array_Field_UnsizedElement_SizeModifier_" +
248        " --exclude-declaration Struct_Array_Field_UnsizedElement_SizeModifier" +
249        " $(location :pdl_be_test_file) > $(out);" +
250        "$(location :pdlc) $(location tests/canonical/be_test_vectors.json) --output-format rust --tests >> $(out)",
251    srcs: [
252        ":pdl_be_test_file",
253        "tests/canonical/be_test_vectors.json",
254    ],
255    out: ["be_canonical.rs"],
256    tools: [":pdlc"],
257}
258
259rust_test_host {
260    name: "pdl_rust_generator_tests_le",
261    srcs: [":pdl_rust_generator_tests_le_src"],
262    test_suites: ["general-tests"],
263    features: ["serde"],
264    rustlibs: [
265        "libbytes",
266        "libnum_traits",
267        "libpdl_runtime",
268        "libserde",
269        "libserde_json",
270    ],
271    clippy_lints: "none",
272    lints: "none",
273}
274
275rust_test_host {
276    name: "pdl_rust_generator_tests_be",
277    srcs: [":pdl_rust_generator_tests_be_src"],
278    test_suites: ["general-tests"],
279    features: ["serde"],
280    rustlibs: [
281        "libbytes",
282        "libnum_traits",
283        "libpdl_runtime",
284        "libserde",
285        "libserde_json",
286    ],
287    clippy_lints: "none",
288    lints: "none",
289}
290
291// Generate the python parser+serializer backend for the
292// little endian test file located at tests/canonical/le_test_file.pdl.
293genrule {
294    name: "pdl_python_generator_le_test_gen",
295    defaults: ["pdl_python_generator_defaults"],
296    cmd: "set -o pipefail;" +
297        " $(location :pdlc) $(in) |" +
298        " $(location :pdl_python_generator)" +
299        " --exclude-declaration Packet_Array_Field_VariableElementSize_ConstantSize" +
300        " --exclude-declaration Packet_Array_Field_VariableElementSize_VariableSize" +
301        " --exclude-declaration Packet_Array_Field_VariableElementSize_VariableCount" +
302        " --exclude-declaration Packet_Array_Field_VariableElementSize_UnknownSize" +
303        " --output $(out) --custom-type-location tests.custom_types",
304    tool_files: [
305        "tests/custom_types.py",
306    ],
307    srcs: [
308        "tests/canonical/le_test_file.pdl",
309    ],
310    out: [
311        "le_backend.py",
312    ],
313}
314
315// Generate the python parser+serializer backend for a big endian test
316// file derived from tests/canonical/le_test_file.pdl.
317genrule {
318    name: "pdl_python_generator_be_test_gen",
319    defaults: ["pdl_python_generator_defaults"],
320    cmd: "set -o pipefail;" +
321        " $(location :pdlc) $(in) |" +
322        " $(location :pdl_python_generator)" +
323        " --exclude-declaration Packet_Array_Field_VariableElementSize_ConstantSize" +
324        " --exclude-declaration Packet_Array_Field_VariableElementSize_VariableSize" +
325        " --exclude-declaration Packet_Array_Field_VariableElementSize_VariableCount" +
326        " --exclude-declaration Packet_Array_Field_VariableElementSize_UnknownSize" +
327        " --output $(out) --custom-type-location tests.custom_types",
328    tool_files: [
329        "tests/custom_types.py",
330    ],
331    srcs: [
332        ":pdl_be_test_file",
333    ],
334    out: [
335        "be_backend.py",
336    ],
337}
338
339// Test the generated python parser+serializer against
340// pre-generated binary inputs.
341python_test_host {
342    name: "pdl_python_generator_test",
343    main: "tests/python_generator_test.py",
344    srcs: [
345        ":pdl_python_generator_be_test_gen",
346        ":pdl_python_generator_le_test_gen",
347        "tests/custom_types.py",
348        "tests/python_generator_test.py",
349    ],
350    data: [
351        "tests/canonical/be_test_vectors.json",
352        "tests/canonical/le_test_vectors.json",
353    ],
354    libs: [
355        "typing_extensions",
356    ],
357    test_options: {
358        unit_test: true,
359    },
360    version: {
361        py3: {
362            embedded_launcher: true,
363        },
364    },
365}
366
367// Generate the rust_noalloc backend srcs against the little-endian test vectors
368genrule {
369    name: "pdl_rust_noalloc_le_test_backend_srcs",
370    defaults: ["pdl_rust_noalloc_generator_defaults"],
371    srcs: ["tests/canonical/le_rust_noalloc_test_file.pdl"],
372    out: ["_packets.rs"],
373}
374
375// Generate the C++ parser+serializer backend for the
376// little endian test file located at tests/canonical/le_test_file.pdl.
377genrule {
378    name: "pdl_cxx_canonical_le_src_gen",
379    defaults: ["pdl_cxx_generator_defaults"],
380    cmd: "set -o pipefail;" +
381        " $(location :pdlc) $(in) |" +
382        " $(location :pdl_cxx_generator)" +
383        " --exclude-declaration Packet_Custom_Field_ConstantSize" +
384        " --exclude-declaration Packet_Custom_Field_VariableSize" +
385        " --exclude-declaration Packet_Checksum_Field_FromStart" +
386        " --exclude-declaration Packet_Checksum_Field_FromEnd" +
387        " --exclude-declaration Struct_Custom_Field_ConstantSize" +
388        " --exclude-declaration Struct_Custom_Field_VariableSize" +
389        " --exclude-declaration Struct_Checksum_Field_FromStart" +
390        " --exclude-declaration Struct_Checksum_Field_FromEnd" +
391        " --exclude-declaration Packet_Array_Field_VariableElementSize_ConstantSize" +
392        " --exclude-declaration Packet_Array_Field_VariableElementSize_VariableSize" +
393        " --exclude-declaration Packet_Array_Field_VariableElementSize_VariableCount" +
394        " --exclude-declaration Packet_Array_Field_VariableElementSize_UnknownSize" +
395        " --exclude-declaration Struct_Custom_Field_ConstantSize_" +
396        " --exclude-declaration Struct_Custom_Field_VariableSize_" +
397        " --exclude-declaration Struct_Checksum_Field_FromStart_" +
398        " --exclude-declaration Struct_Checksum_Field_FromEnd_" +
399        " --exclude-declaration PartialParent5" +
400        " --exclude-declaration PartialChild5_A" +
401        " --exclude-declaration PartialChild5_B" +
402        " --exclude-declaration PartialParent12" +
403        " --exclude-declaration PartialChild12_A" +
404        " --exclude-declaration PartialChild12_B" +
405        " --namespace le_test" +
406        " --output $(out)",
407    srcs: [
408        "tests/canonical/le_test_file.pdl",
409    ],
410    out: [
411        "canonical_le_test_file.h",
412    ],
413}
414
415// Generate the C++ parser+serializer backend tests for the
416// little endian test file located at tests/canonical/le_test_file.pdl.
417genrule {
418    name: "pdl_cxx_canonical_le_test_gen",
419    cmd: "set -o pipefail;" +
420        " inputs=( $(in) ) &&" +
421        " $(location :pdlc) $${inputs[0]} |" +
422        " $(location :pdl_cxx_unittest_generator)" +
423        " --output $(out)" +
424        " --test-vectors $${inputs[1]}" +
425        " --include-header $$(basename $${inputs[2]})" +
426        " --using-namespace le_test" +
427        " --namespace le_test" +
428        " --parser-test-suite LeParserTest" +
429        " --serializer-test-suite LeSerializerTest",
430    tools: [
431        ":pdlc",
432        ":pdl_cxx_unittest_generator",
433    ],
434    srcs: [
435        "tests/canonical/le_test_file.pdl",
436
437        "tests/canonical/le_test_vectors.json",
438
439        ":pdl_cxx_canonical_le_src_gen",
440    ],
441    out: [
442        "canonical_le_test.cc",
443    ],
444}
445
446// Generate the C++ parser+serializer backend for the
447// big endian test file.
448genrule {
449    name: "pdl_cxx_canonical_be_src_gen",
450    defaults: ["pdl_cxx_generator_defaults"],
451    cmd: "set -o pipefail;" +
452        " $(location :pdlc) $(in) |" +
453        " $(location :pdl_cxx_generator)" +
454        " --exclude-declaration Packet_Custom_Field_ConstantSize" +
455        " --exclude-declaration Packet_Custom_Field_VariableSize" +
456        " --exclude-declaration Packet_Checksum_Field_FromStart" +
457        " --exclude-declaration Packet_Checksum_Field_FromEnd" +
458        " --exclude-declaration Struct_Custom_Field_ConstantSize" +
459        " --exclude-declaration Struct_Custom_Field_VariableSize" +
460        " --exclude-declaration Struct_Checksum_Field_FromStart" +
461        " --exclude-declaration Struct_Checksum_Field_FromEnd" +
462        " --exclude-declaration Packet_Array_Field_VariableElementSize_ConstantSize" +
463        " --exclude-declaration Packet_Array_Field_VariableElementSize_VariableSize" +
464        " --exclude-declaration Packet_Array_Field_VariableElementSize_VariableCount" +
465        " --exclude-declaration Packet_Array_Field_VariableElementSize_UnknownSize" +
466        " --exclude-declaration Struct_Custom_Field_ConstantSize_" +
467        " --exclude-declaration Struct_Custom_Field_VariableSize_" +
468        " --exclude-declaration Struct_Checksum_Field_FromStart_" +
469        " --exclude-declaration Struct_Checksum_Field_FromEnd_" +
470        " --exclude-declaration PartialParent5" +
471        " --exclude-declaration PartialChild5_A" +
472        " --exclude-declaration PartialChild5_B" +
473        " --exclude-declaration PartialParent12" +
474        " --exclude-declaration PartialChild12_A" +
475        " --exclude-declaration PartialChild12_B" +
476        " --namespace be_test" +
477        " --output $(out)",
478    srcs: [
479        ":pdl_be_test_file",
480    ],
481    out: [
482        "canonical_be_test_file.h",
483    ],
484}
485
486// Generate the C++ parser+serializer backend tests for the
487// big endian test file.
488genrule {
489    name: "pdl_cxx_canonical_be_test_gen",
490    cmd: "set -o pipefail;" +
491        " inputs=( $(in) ) &&" +
492        " $(location :pdlc) $${inputs[0]} |" +
493        " $(location :pdl_cxx_unittest_generator)" +
494        " --output $(out)" +
495        " --test-vectors $${inputs[1]}" +
496        " --include-header $$(basename $${inputs[2]})" +
497        " --using-namespace be_test" +
498        " --namespace be_test" +
499        " --parser-test-suite BeParserTest" +
500        " --serializer-test-suite BeSerializerTest",
501    tools: [
502        ":pdlc",
503        ":pdl_cxx_unittest_generator",
504    ],
505    srcs: [
506        ":pdl_be_test_file",
507
508        "tests/canonical/be_test_vectors.json",
509
510        ":pdl_cxx_canonical_be_src_gen",
511    ],
512    out: [
513        "canonical_be_test.cc",
514    ],
515}
516
517// Test the generated C++ parser+serializer against
518// pre-generated binary inputs.
519cc_test_host {
520    name: "pdl_cxx_generator_test",
521    local_include_dirs: [
522        "scripts",
523    ],
524    generated_headers: [
525        "pdl_cxx_canonical_be_src_gen",
526        "pdl_cxx_canonical_le_src_gen",
527    ],
528    generated_sources: [
529        "pdl_cxx_canonical_be_test_gen",
530        "pdl_cxx_canonical_le_test_gen",
531    ],
532    static_libs: [
533        "libgtest",
534    ],
535}
536