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