1package {
2    // See: http://go/android-license-faq
3    // A large-scale-change added 'default_applicable_licenses' to import
4    // all of the 'license_kinds' from "system_bt_license"
5    // to get the below license kinds:
6    //   SPDX-license-identifier-Apache-2.0
7    //   SPDX-license-identifier-BSD
8    default_applicable_licenses: ["system_bt_license"],
9}
10
11cc_defaults {
12    name: "gd_defaults",
13    target: {
14        android: {
15            test_config_template: "AndroidTestTemplate.xml",
16            cflags: [
17                "-DOS_ANDROID",
18                "-DOS_LINUX_GENERIC",
19            ],
20            shared_libs: [
21                "liblog",
22            ],
23        },
24        host: {
25            cflags: [
26                "-DOS_LINUX_GENERIC",
27            ],
28        },
29        darwin: {
30            enabled: false,
31        },
32    },
33    cpp_std: "c++17",
34    cflags: [
35        "-DEXPORT_SYMBOL=__attribute__((visibility(\"default\")))",
36        "-fvisibility=hidden",
37        "-DLOG_NDEBUG=1",
38        "-DGOOGLE_PROTOBUF_NO_RTTI",
39        "-Wno-unused-parameter",
40        "-Wno-unused-result",
41    ],
42    conlyflags: [
43        "-std=c99",
44    ],
45    header_libs: ["jni_headers"],
46    sanitize: {
47        misc_undefined: ["bounds"],
48    },
49}
50
51// Enables code coverage for a set of source files. Must be combined with
52// "clang_coverage_bin" in order to work. See //test/gen_coverage.py for more information
53// on generating code coverage.
54cc_defaults {
55    name: "gd_clang_file_coverage",
56    target: {
57        host: {
58            clang_cflags: [
59                "-fprofile-instr-generate",
60                "-fcoverage-mapping",
61            ],
62        },
63    },
64}
65
66// Enabled code coverage on a binary. These flags allow libraries that were
67// compiled with "clang_file_coverage" to be properly linked together in
68// order to create a binary that will create a profraw file when ran. Note
69// these flags themselves don't enable code coverage for the source files
70// compiled in the binary. See //test/gen_coverage.py for more information
71// on generating code coverage.
72cc_defaults {
73    name: "gd_clang_coverage_bin",
74    target: {
75        host: {
76            ldflags: [
77                "-fprofile-instr-generate",
78                "-fcoverage-mapping",
79            ],
80        },
81    },
82}
83
84cc_defaults {
85    name: "gd_clang_tidy",
86    tidy: true,
87    tidy_checks: [
88        "clang-analyzer-core.CallAndMessage",
89        "clang-analyzer-optin.cplusplus.UninitializedObject",
90        "-google*",
91        "-performance*",
92        "-bugprone*",
93    ],
94    tidy_checks_as_errors: [
95        "cppcoreguidelines-pro-type-member-init",
96        "clang-analyzer-core.CallAndMessage",
97        "clang-analyzer-optin.cplusplus.UninitializedObject",
98    ],
99    tidy_flags: [
100        "--header-filter=^.*system/bt/.*.h$",
101        "--extra-arg-before=-Xclang",
102        "--extra-arg-before=-analyzer-config",
103        "--extra-arg-before=-Xclang",
104        "--extra-arg-before=optin.cplusplus.UninitializedObject:Pedantic=true",
105        "--extra-arg-before=-Xclang",
106        "--extra-arg-before=-analyzer-config",
107        "--extra-arg-before=-Xclang",
108        "--extra-arg-before=optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true",
109    ],
110}
111
112cc_defaults {
113    name: "libbluetooth_gd_defaults",
114    defaults: [
115        "gd_defaults",
116        "gd_clang_file_coverage",
117    ],
118    host_supported: true,
119    target: {
120        linux: {
121            srcs: [
122                ":BluetoothBtaaSources_linux_generic",
123                ":BluetoothOsSources_linux_generic",
124            ],
125        },
126        host: {
127            srcs: [
128                ":BluetoothBtaaSources_host",
129                ":BluetoothHalSources_hci_host",
130                ":BluetoothOsSources_host",
131            ],
132        },
133        android: {
134            srcs: [
135                ":BluetoothBtaaSources_android",
136                ":BluetoothHalSources_hci_android_hidl",
137                ":BluetoothOsSources_android",
138            ],
139            shared_libs: [
140                "android.hardware.bluetooth@1.0",
141                "android.hardware.bluetooth@1.1",
142                "android.system.suspend.control-V1-ndk",
143                "android.system.suspend@1.0",
144                "libbinder_ndk",
145                "libcutils",
146                "libhidlbase",
147                "libutils",
148                "libstatslog",
149            ],
150        },
151    },
152    srcs: [
153        "stack_manager.cc",
154        "module.cc",
155        ":BluetoothAttSources",
156        ":BluetoothCommonSources",
157        ":BluetoothCryptoToolboxSources",
158        ":BluetoothDumpsysSources",
159        ":BluetoothHalSources",
160        ":BluetoothHciSources",
161        ":BluetoothIsoSources",
162        ":BluetoothL2capSources",
163        ":BluetoothNeighborSources",
164        ":BluetoothPacketSources",
165        ":BluetoothShimSources",
166        ":BluetoothSecuritySources",
167        ":BluetoothStorageSources",
168    ],
169    generated_headers: [
170        "BluetoothGeneratedBundlerSchema_h_bfbs",
171        "BluetoothGeneratedDumpsysDataSchema_h",
172        "BluetoothGeneratedDumpsysBundledSchema_h",
173        "BluetoothGeneratedPackets_h",
174    ],
175    shared_libs: [
176        "libchrome",
177        "libcrypto",
178        "libflatbuffers-cpp",
179        "libgrpc++",
180        "libgrpc_wrap",
181    ],
182    static_libs: [
183        "libbluetooth-protos",
184        "libbluetooth_rust_interop",
185        "libbt-platform-protos-lite",
186    ],
187    export_static_lib_headers: [ "libbluetooth_rust_interop" ],
188}
189
190cc_library {
191    name: "libbluetooth_gd",
192    defaults: [
193        "libbluetooth_gd_defaults",
194    ],
195}
196
197cc_library {
198    name: "libbluetooth_gd_fuzzing",
199    defaults: [
200        "libbluetooth_gd_defaults",
201    ],
202    srcs: [
203        ":BluetoothOsSources_fuzz",
204    ],
205    cflags: [
206        "-DFUZZ_TARGET",
207    ],
208}
209
210cc_binary {
211    name: "bluetooth_stack_with_facade",
212    defaults: [
213        "gd_defaults",
214        "gd_clang_coverage_bin",
215    ],
216    host_supported: true,
217    srcs: [
218        "facade/facade_main.cc",
219        "facade/grpc_root_server.cc",
220        "facade/read_only_property_server.cc",
221        "grpc/grpc_module.cc",
222        ":BluetoothFacade_hci_hal",
223        ":BluetoothFacade_hci_layer",
224        ":BluetoothFacade_l2cap_layer",
225        ":BluetoothFacade_neighbor",
226        ":BluetoothFacade_iso_layer",
227        ":BluetoothFacade_security_layer",
228        ":BluetoothFacade_shim_layer",
229    ],
230    generated_headers: [
231        "BluetoothFacadeGeneratedStub_h",
232        "BluetoothGeneratedBundlerSchema_h_bfbs",
233        "BluetoothGeneratedDumpsysDataSchema_h",
234        "BluetoothGeneratedPackets_h",
235        // Needed here to guarantee that generated zip file is created before
236        // bluetooth_cert_tests.zip is packaged
237        "BluetoothFacadeAndCertGeneratedStub_py",
238    ],
239    generated_sources: [
240        "BluetoothFacadeGeneratedStub_cc",
241    ],
242    static_libs: [
243        "breakpad_client",
244        "libbluetooth-protos",
245        "libbluetooth_gd",
246        "libflatbuffers-cpp",
247        "libbluetooth_rust_interop",
248    ],
249    shared_libs: [
250        "libbacktrace",
251        "libchrome",
252        "libcrypto",
253        "libgrpc++",
254        "libgrpc++_unsecure",
255        "libgrpc_wrap",
256        "libprotobuf-cpp-full",
257    ],
258    target: {
259        android: {
260            shared_libs: [
261                "android.hardware.bluetooth@1.0",
262                "android.hardware.bluetooth@1.1",
263                "android.system.suspend.control-V1-ndk",
264                "android.system.suspend@1.0",
265                "libbinder_ndk",
266                "libhidlbase",
267                "libutils",
268                "libcutils",
269                "libstatslog",
270            ],
271        },
272        host: {
273            required: [
274                "root-canal",
275            ],
276        },
277    },
278    sanitize: {
279        address: true,
280        cfi: true,
281    }
282}
283
284cc_test {
285    name: "bluetooth_test_gd_unit",
286    test_suites: ["device-tests"],
287    defaults: [
288        "gd_defaults",
289        "gd_clang_coverage_bin",
290    ],
291    host_supported: true,
292    test_options: {
293        unit_test: true,
294    },
295    target: {
296        linux: {
297            srcs: [
298                ":BluetoothOsTestSources_linux_generic",
299            ],
300        },
301        host: {
302            srcs: [
303                ":BluetoothHalTestSources_hci_host",
304                ":BluetoothOsTestSources_host",
305            ],
306        },
307        android: {
308            srcs: [
309                ":BluetoothHalTestSources_hci_android_hidl",
310                ":BluetoothOsTestSources_android",
311            ],
312            shared_libs: [
313                "android.hardware.bluetooth@1.0",
314                "android.hardware.bluetooth@1.1",
315                "android.system.suspend.control-V1-ndk",
316                "android.system.suspend@1.0",
317                "libbinder_ndk",
318                "libhidlbase",
319                "libutils",
320                "libcutils",
321                "libstatslog",
322            ],
323        },
324    },
325    srcs: [
326        "module_unittest.cc",
327        "stack_manager_unittest.cc",
328        ":BluetoothCommonTestSources",
329        ":BluetoothCryptoToolboxTestSources",
330        ":BluetoothDumpsysTestSources",
331        ":BluetoothHalTestSources",
332        ":BluetoothHciUnitTestSources",
333        ":BluetoothL2capUnitTestSources",
334        ":BluetoothPacketTestSources",
335        ":BluetoothShimTestSources",
336        ":BluetoothSecurityUnitTestSources",
337        ":BluetoothStorageUnitTestSources",
338    ],
339    generated_headers: [
340        "BluetoothGeneratedBundlerSchema_h_bfbs",
341        "BluetoothGeneratedDumpsysBundledSchema_h",
342        "BluetoothGeneratedDumpsysBundledTestSchema_h",
343        "BluetoothGeneratedDumpsysDataSchema_h",
344        "BluetoothGeneratedDumpsysTestData_h",
345        "BluetoothGeneratedPackets_h",
346    ],
347    static_libs: [
348        "libbluetooth-protos",
349        "libbluetooth_gd",
350        "libc++fs",
351        "libflatbuffers-cpp",
352        "libgmock",
353        "libbluetooth_rust_interop",
354    ],
355    shared_libs: [
356        "libchrome",
357        "libcrypto",
358        "libgrpc++",
359        "libgrpc_wrap",
360    ],
361    sanitize: {
362        address: true,
363    },
364}
365
366cc_test {
367    name: "bluetooth_test_gd",
368    test_suites: ["device-tests"],
369    defaults: [
370        "gd_defaults",
371        "gd_clang_coverage_bin",
372    ],
373    host_supported: true,
374    test_options: {
375        unit_test: false,
376    },
377    target: {
378        linux: {
379            srcs: [
380                ":BluetoothOsTestSources_linux_generic",
381            ],
382        },
383        host: {
384            srcs: [
385                ":BluetoothHalTestSources_hci_host",
386                ":BluetoothOsTestSources_host",
387            ],
388        },
389        android: {
390            srcs: [
391                ":BluetoothHalTestSources_hci_android_hidl",
392                ":BluetoothOsTestSources_android",
393            ],
394            shared_libs: [
395                "android.hardware.bluetooth@1.0",
396                "android.hardware.bluetooth@1.1",
397                "android.system.suspend.control-V1-ndk",
398                "android.system.suspend@1.0",
399                "libbinder_ndk",
400                "libhidlbase",
401                "libutils",
402                "libcutils",
403                "libstatslog",
404            ],
405        },
406    },
407    srcs: [
408        "module_unittest.cc",
409        "stack_manager_unittest.cc",
410        ":BluetoothAttTestSources",
411        ":BluetoothCommonTestSources",
412        ":BluetoothCryptoToolboxTestSources",
413        ":BluetoothDumpsysTestSources",
414        ":BluetoothHalTestSources",
415        ":BluetoothHciTestSources",
416        ":BluetoothIsoTestSources",
417        ":BluetoothL2capTestSources",
418        ":BluetoothNeighborTestSources",
419        ":BluetoothPacketTestSources",
420        ":BluetoothSecurityTestSources",
421        ":BluetoothStorageTestSources",
422    ],
423    generated_headers: [
424        "BluetoothGeneratedBundlerSchema_h_bfbs",
425        "BluetoothGeneratedDumpsysBundledSchema_h",
426        "BluetoothGeneratedDumpsysBundledTestSchema_h",
427        "BluetoothGeneratedDumpsysDataSchema_h",
428        "BluetoothGeneratedDumpsysTestData_h",
429        "BluetoothGeneratedPackets_h",
430    ],
431    static_libs: [
432        "libbluetooth-protos",
433        "libbluetooth_gd",
434        "libc++fs",
435        "libflatbuffers-cpp",
436        "libgmock",
437        "libbluetooth_rust_interop",
438    ],
439    shared_libs: [
440        "libchrome",
441        "libcrypto",
442        "libgrpc++",
443        "libgrpc_wrap",
444    ],
445    sanitize: {
446        address: true,
447    },
448}
449
450cc_test {
451    name: "bluetooth_packet_parser_test",
452    test_suites: ["device-tests"],
453    defaults: [
454        "gd_defaults",
455        "gd_clang_coverage_bin",
456    ],
457    host_supported: true,
458    test_options: {
459        unit_test: true,
460    },
461    srcs: [
462        "hci/address.cc",
463        ":BluetoothPacketSources",
464        ":BluetoothPacketParserTestPacketTestSources",
465    ],
466    generated_headers: [
467        "BluetoothPacketParserTestPacketPdlGen_h",
468    ],
469    sanitize: {
470        address: true,
471        cfi: true,
472    },
473    static_libs: [
474        "libchrome",
475    ],
476    shared_libs: [
477        "libgrpc++",
478        "libgrpc_wrap",
479    ],
480    target: {
481        android: {
482            shared_libs: [
483                "android.hardware.bluetooth@1.0",
484                "android.hardware.bluetooth@1.1",
485                "libhidlbase",
486                "libutils",
487                "libcutils",
488            ],
489        },
490    },
491}
492
493cc_defaults {
494    name: "gd_fuzz_defaults",
495    defaults: ["gd_defaults"],
496    srcs: [
497        ":BluetoothFuzzHelperSources",
498        ":BluetoothHciFuzzHelperSources",
499    ],
500    static_libs: [
501        "libbluetooth-protos",
502        "libbluetooth_gd_fuzzing",
503        "libchrome",
504        "libgmock",
505        "libgtest",
506        "libbluetooth_rust_interop",
507    ],
508    host_supported: true,
509    generated_headers: [
510        "BluetoothGeneratedDumpsysDataSchema_h",
511        "BluetoothGeneratedPackets_h",
512    ],
513    shared_libs: [
514        "libcrypto",
515        "libflatbuffers-cpp",
516        "libgrpc++",
517        "libgrpc_wrap",
518    ],
519    cflags: [
520        "-DFUZZ_TARGET",
521    ],
522    target: {
523        android: {
524            shared_libs: [
525                "android.hardware.bluetooth@1.0",
526                "android.hardware.bluetooth@1.1",
527                "android.system.suspend.control-V1-ndk",
528                "libbinder_ndk",
529                "libcutils",
530                "libhidlbase",
531                "libutils",
532                "libstatslog",
533            ],
534        },
535    },
536}
537
538cc_fuzz {
539    name: "bluetooth_gd_fuzz_test",
540    defaults: ["gd_fuzz_defaults"],
541    srcs: [
542        "fuzz_test.cc",
543        ":BluetoothHciFuzzTestSources",
544        ":BluetoothL2capFuzzTestSources",
545    ],
546}
547
548cc_fuzz {
549    name: "bluetooth_gd_hci_layer_fuzz_test",
550    defaults: ["gd_fuzz_defaults"],
551    srcs: [
552        "hci/fuzz/hci_layer_fuzz_test.cc",
553        ":BluetoothHalFuzzSources",
554    ],
555}
556
557cc_fuzz {
558    name: "bluetooth_gd_acl_manager_fuzz_test",
559    defaults: ["gd_fuzz_defaults"],
560    srcs: [
561        "hci/fuzz/acl_manager_fuzz_test.cc",
562    ],
563}
564
565cc_benchmark {
566    name: "bluetooth_benchmark_gd",
567    defaults: ["gd_defaults"],
568    host_supported: true,
569    srcs: [
570        "benchmark.cc",
571        ":BluetoothOsBenchmarkSources",
572    ],
573    static_libs: [
574        "libbluetooth_gd",
575    ],
576    shared_libs: [
577        "libchrome",
578    ],
579}
580
581filegroup {
582    name: "BluetoothHciClassSources",
583    srcs: [
584        "hci/address.cc",
585        "hci/class_of_device.cc",
586    ],
587}
588
589genrule {
590    name: "BluetoothGeneratedPackets_h",
591    tools: [
592        "bluetooth_packetgen",
593    ],
594    cmd: "$(location bluetooth_packetgen) --include=system/bt/gd --out=$(genDir) $(in)",
595    srcs: [
596        "hci/hci_packets.pdl",
597        "l2cap/l2cap_packets.pdl",
598        "security/smp_packets.pdl",
599    ],
600    out: [
601        "hci/hci_packets.h",
602        "l2cap/l2cap_packets.h",
603        "security/smp_packets.h",
604    ],
605}
606
607genrule {
608    name: "BluetoothGeneratedPackets_rust",
609    tools: [
610        "bluetooth_packetgen",
611    ],
612    cmd: "$(location bluetooth_packetgen) --include=system/bt/gd --out=$(genDir) $(in) --rust",
613    srcs: [
614        "hci/hci_packets.pdl",
615    ],
616    out: [
617        "hci/hci_packets.rs",
618    ],
619}
620
621rust_library {
622    name: "libbt_packets",
623    defaults: ["gd_rust_defaults"],
624    crate_name: "bt_packets",
625    srcs: ["rust/packets/lib.rs", ":BluetoothGeneratedPackets_rust"],
626    edition: "2018",
627    host_supported: true,
628    proc_macros: ["libnum_derive"],
629    rustlibs: [
630        "libbytes",
631        "libnum_traits",
632        "libthiserror",
633        "libbt_hci_custom_types",
634        "liblog_rust",
635    ],
636}
637
638rust_test_host {
639    name: "libbt_packets_test",
640    defaults: ["gd_rust_defaults"],
641    srcs: ["rust/packets/lib.rs", ":BluetoothGeneratedPackets_rust"],
642    test_suites: ["general-tests"],
643    edition: "2018",
644    proc_macros: ["libnum_derive"],
645    rustlibs: [
646        "libbytes",
647        "libnum_traits",
648        "libthiserror",
649        "libbt_hci_custom_types",
650        "liblog_rust",
651    ],
652}
653
654// Generates binary schema data to be bundled and source file generated
655genrule {
656    name: "BluetoothGeneratedDumpsysBinarySchema_bfbs",
657    tools: [
658        "flatc",
659    ],
660    cmd: "$(location flatc) -I system/bt/gd -b --schema -o $(genDir) $(in) ",
661    srcs: [
662        "btaa/activity_attribution.fbs",
663        "common/init_flags.fbs",
664        "dumpsys_data.fbs",
665        "hci/hci_acl_manager.fbs",
666        "l2cap/classic/l2cap_classic_module.fbs",
667        "shim/dumpsys.fbs",
668        "os/wakelock_manager.fbs",
669    ],
670    out: [
671        "activity_attribution.bfbs",
672        "init_flags.bfbs",
673        "dumpsys.bfbs",
674        "dumpsys_data.bfbs",
675        "hci_acl_manager.bfbs",
676        "l2cap_classic_module.bfbs",
677        "wakelock_manager.bfbs",
678    ],
679}
680
681genrule {
682    name: "BluetoothGeneratedDumpsysDataSchema_h",
683    tools: [
684        "flatc",
685    ],
686    cmd: "$(location flatc) -I system/bt/gd -o $(genDir) --cpp $(in) ",
687    srcs: [
688        "btaa/activity_attribution.fbs",
689        "common/init_flags.fbs",
690        "dumpsys_data.fbs",
691        "hci/hci_acl_manager.fbs",
692        "l2cap/classic/l2cap_classic_module.fbs",
693        "shim/dumpsys.fbs",
694        "os/wakelock_manager.fbs",
695    ],
696    out: [
697        "activity_attribution_generated.h",
698        "dumpsys_data_generated.h",
699        "dumpsys_generated.h",
700        "hci_acl_manager_generated.h",
701        "init_flags_generated.h",
702        "l2cap_classic_module_generated.h",
703        "wakelock_manager_generated.h",
704    ],
705}
706
707genrule {
708    name: "BluetoothGeneratedPackets_python3_cc",
709    tools: [
710        "bluetooth_packetgen",
711    ],
712    cmd: "$(location bluetooth_packetgen) --include=system/bt/gd --out=$(genDir) --num_shards=10 $(in)",
713    srcs: [
714        "hci/hci_packets.pdl",
715        "l2cap/l2cap_packets.pdl",
716        "security/smp_packets.pdl",
717    ],
718    out: [
719        "hci/hci_packets_python3.cc",
720        "hci/hci_packets_python3_shard_0.cc",
721        "hci/hci_packets_python3_shard_1.cc",
722        "hci/hci_packets_python3_shard_2.cc",
723        "hci/hci_packets_python3_shard_3.cc",
724        "hci/hci_packets_python3_shard_4.cc",
725        "hci/hci_packets_python3_shard_5.cc",
726        "hci/hci_packets_python3_shard_6.cc",
727        "hci/hci_packets_python3_shard_7.cc",
728        "hci/hci_packets_python3_shard_8.cc",
729        "hci/hci_packets_python3_shard_9.cc",
730        "l2cap/l2cap_packets_python3.cc",
731        "l2cap/l2cap_packets_python3_shard_0.cc",
732        "l2cap/l2cap_packets_python3_shard_1.cc",
733        "l2cap/l2cap_packets_python3_shard_2.cc",
734        "l2cap/l2cap_packets_python3_shard_3.cc",
735        "l2cap/l2cap_packets_python3_shard_4.cc",
736        "l2cap/l2cap_packets_python3_shard_5.cc",
737        "l2cap/l2cap_packets_python3_shard_6.cc",
738        "l2cap/l2cap_packets_python3_shard_7.cc",
739        "l2cap/l2cap_packets_python3_shard_8.cc",
740        "l2cap/l2cap_packets_python3_shard_9.cc",
741        "security/smp_packets_python3.cc",
742        "security/smp_packets_python3_shard_0.cc",
743        "security/smp_packets_python3_shard_1.cc",
744        "security/smp_packets_python3_shard_2.cc",
745        "security/smp_packets_python3_shard_3.cc",
746        "security/smp_packets_python3_shard_4.cc",
747        "security/smp_packets_python3_shard_5.cc",
748        "security/smp_packets_python3_shard_6.cc",
749        "security/smp_packets_python3_shard_7.cc",
750        "security/smp_packets_python3_shard_8.cc",
751        "security/smp_packets_python3_shard_9.cc",
752    ],
753}
754
755filegroup {
756    name: "BluetoothFacadeProto",
757    srcs: [
758        "facade/common.proto",
759        "facade/rootservice.proto",
760        "hal/hal_facade.proto",
761        "hci/facade/hci_facade.proto",
762        "hci/facade/acl_manager_facade.proto",
763        "hci/facade/controller_facade.proto",
764        "hci/facade/le_acl_manager_facade.proto",
765        "hci/facade/le_advertising_manager_facade.proto",
766        "hci/facade/le_initiator_address_facade.proto",
767        "hci/facade/le_scanning_manager_facade.proto",
768        "iso/facade.proto",
769        "neighbor/facade/facade.proto",
770        "l2cap/classic/facade.proto",
771        "l2cap/le/facade.proto",
772        "security/facade.proto",
773        "shim/facade/facade.proto",
774    ],
775}
776
777genrule {
778    name: "BluetoothFacadeGeneratedStub_h",
779    tools: [
780        "aprotoc",
781        "protoc-gen-grpc-cpp-plugin",
782    ],
783    cmd: "$(location aprotoc) -Isystem/bt/gd -Iexternal/protobuf/src --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-cpp-plugin) $(in) --grpc_out=$(genDir) --cpp_out=$(genDir)",
784    srcs: [
785        ":BluetoothFacadeProto",
786    ],
787    out: [
788        "facade/common.grpc.pb.h",
789        "facade/common.pb.h",
790        "facade/rootservice.grpc.pb.h",
791        "facade/rootservice.pb.h",
792        "hal/hal_facade.grpc.pb.h",
793        "hal/hal_facade.pb.h",
794        "hci/facade/hci_facade.grpc.pb.h",
795        "hci/facade/hci_facade.pb.h",
796        "hci/facade/acl_manager_facade.grpc.pb.h",
797        "hci/facade/acl_manager_facade.pb.h",
798        "hci/facade/controller_facade.grpc.pb.h",
799        "hci/facade/controller_facade.pb.h",
800        "hci/facade/le_acl_manager_facade.grpc.pb.h",
801        "hci/facade/le_acl_manager_facade.pb.h",
802        "hci/facade/le_advertising_manager_facade.grpc.pb.h",
803        "hci/facade/le_advertising_manager_facade.pb.h",
804        "hci/facade/le_initiator_address_facade.grpc.pb.h",
805        "hci/facade/le_initiator_address_facade.pb.h",
806        "hci/facade/le_scanning_manager_facade.grpc.pb.h",
807        "hci/facade/le_scanning_manager_facade.pb.h",
808        "iso/facade.grpc.pb.h",
809        "iso/facade.pb.h",
810        "l2cap/classic/facade.grpc.pb.h",
811        "l2cap/classic/facade.pb.h",
812        "l2cap/le/facade.grpc.pb.h",
813        "l2cap/le/facade.pb.h",
814        "neighbor/facade/facade.grpc.pb.h",
815        "neighbor/facade/facade.pb.h",
816        "security/facade.grpc.pb.h",
817        "security/facade.pb.h",
818        "shim/facade/facade.grpc.pb.h",
819        "shim/facade/facade.pb.h",
820    ],
821}
822
823genrule {
824    name: "BluetoothFacadeGeneratedStub_cc",
825    tools: [
826        "aprotoc",
827        "protoc-gen-grpc-cpp-plugin",
828    ],
829    cmd: "$(location aprotoc) -Isystem/bt/gd -Iexternal/protobuf/src --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-cpp-plugin) $(in) --grpc_out=$(genDir) --cpp_out=$(genDir)",
830    srcs: [
831        ":BluetoothFacadeProto",
832    ],
833    out: [
834        "facade/common.grpc.pb.cc",
835        "facade/common.pb.cc",
836        "facade/rootservice.grpc.pb.cc",
837        "facade/rootservice.pb.cc",
838        "hal/hal_facade.grpc.pb.cc",
839        "hal/hal_facade.pb.cc",
840        "hci/facade/hci_facade.grpc.pb.cc",
841        "hci/facade/hci_facade.pb.cc",
842        "hci/facade/acl_manager_facade.grpc.pb.cc",
843        "hci/facade/acl_manager_facade.pb.cc",
844        "hci/facade/controller_facade.grpc.pb.cc",
845        "hci/facade/controller_facade.pb.cc",
846        "hci/facade/le_acl_manager_facade.grpc.pb.cc",
847        "hci/facade/le_acl_manager_facade.pb.cc",
848        "hci/facade/le_advertising_manager_facade.grpc.pb.cc",
849        "hci/facade/le_advertising_manager_facade.pb.cc",
850        "hci/facade/le_initiator_address_facade.grpc.pb.cc",
851        "hci/facade/le_initiator_address_facade.pb.cc",
852        "hci/facade/le_scanning_manager_facade.grpc.pb.cc",
853        "hci/facade/le_scanning_manager_facade.pb.cc",
854        "iso/facade.grpc.pb.cc",
855        "iso/facade.pb.cc",
856        "l2cap/classic/facade.grpc.pb.cc",
857        "l2cap/classic/facade.pb.cc",
858        "l2cap/le/facade.grpc.pb.cc",
859        "l2cap/le/facade.pb.cc",
860        "neighbor/facade/facade.grpc.pb.cc",
861        "neighbor/facade/facade.pb.cc",
862        "security/facade.grpc.pb.cc",
863        "security/facade.pb.cc",
864        "shim/facade/facade.grpc.pb.cc",
865        "shim/facade/facade.pb.cc",
866    ],
867}
868
869genrule {
870    name: "BluetoothFacadeAndCertGeneratedStub_py",
871    tools: [
872        "aprotoc",
873        "protoc-gen-grpc-python-plugin",
874        "soong_zip",
875    ],
876    cmd: "mkdir -p $(genDir)/files && " +
877        "$(location aprotoc) -Isystem/bt/gd -Iexternal/protobuf/src --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-python-plugin) $(in) --grpc_out=$(genDir)/files --python_out=$(genDir)/files && " +
878        "mkdir -p $(genDir)/files/cert && " +
879        "touch $(genDir)/files/cert/__init__.py && " +
880        "touch $(genDir)/files/facade/__init__.py && " +
881        "touch $(genDir)/files/hal/__init__.py && " +
882        "touch $(genDir)/files/hci/__init__.py && " +
883        "touch $(genDir)/files/hci/facade/__init__.py && " +
884        "touch $(genDir)/files/iso/__init__.py && " +
885        "touch $(genDir)/files/l2cap/classic/__init__.py && " +
886        "touch $(genDir)/files/l2cap/le/__init__.py && " +
887        "touch $(genDir)/files/neighbor/facade/__init__.py && " +
888        "touch $(genDir)/files/security/__init__.py && " +
889        "$(location soong_zip) -C $(genDir)/files -D $(genDir)/files -o $(out)",
890    srcs: [
891        ":BluetoothFacadeProto",
892    ],
893    out: ["bluetooth_cert_generated_py.zip"],
894}
895
896cc_defaults {
897    name: "bluetooth_py3_native_extension_defaults",
898    include_dirs: [
899        "external/python/cpython3/Include",
900    ],
901    target: {
902        android: {
903            include_dirs: ["external/python/cpython3/android/bionic/pyconfig"],
904        },
905        android_arm: {
906            cflags: ["-DSOABI=\"cpython-38android-arm-android-bionic\""],
907            suffix: ".cpython-38android-arm-android-bionic",
908        },
909        android_arm64: {
910            cflags: ["-DSOABI=\"cpython-38android-arm64-android-bionic\""],
911            suffix: ".cpython-38android-arm64-android-bionic",
912        },
913        android_x86: {
914            cflags: ["-DSOABI=\"cpython-38android-x86-android-bionic\""],
915            suffix: ".cpython-38android-x86-android-bionic",
916        },
917        android_x86_64: {
918            cflags: ["-DSOABI=\"cpython-38android-x86_64-android-bionic\""],
919            suffix: ".cpython-38android-x86_64-android-bionic",
920        },
921        // Regenerate include dirs with android_regen.sh
922        darwin_x86_64: {
923            include_dirs: ["external/python/cpython3/android/darwin_x86_64/pyconfig"],
924            cflags: [
925                "-Wno-deprecated-declarations",
926                "-Wno-pointer-arith",
927                "-DSOABI=\"cpython-38android-x86_64-darwin\"",
928            ],
929            suffix: ".cpython-38android-x86_64-darwin",
930        },
931        linux_bionic: {
932            // NB linux_bionic is a 'host' architecture but it uses the bionic libc like 'android'
933            // targets so use the android pyconfig.
934            include_dirs: ["external/python/cpython3/android/bionic/pyconfig"],
935            cflags: ["-DSOABI=\"cpython-38android-x86_64-linux-bionic\""],
936            suffix: ".cpython-38android-x86_64-linux-bionic",
937        },
938        linux_glibc_x86: {
939            enabled: false,
940        },
941        linux_glibc_x86_64: {
942            include_dirs: ["external/python/cpython3/android/linux_x86_64/pyconfig"],
943            cflags: ["-DSOABI=\"cpython-38android-x86_64-linux-gnu\""],
944            // Commenting out the Linux suffix so that cpython-38-x86_64-linux-gnu
945            // Python 3.8 can also import the untagged .so library per PEP 3149
946            // Keep this change until Android py3-cmd can run ACTS, gRPC and can
947            // Export Python native symbols such as PyType_Type
948            // suffix: ".cpython-38android-x86_64-linux-gnu",
949        },
950        windows: {
951            enabled: false,
952        },
953    },
954    allow_undefined_symbols: true,
955}
956
957cc_library_host_shared {
958    name: "bluetooth_packets_python3",
959    defaults: [
960        "gd_defaults",
961        "bluetooth_py3_native_extension_defaults",
962    ],
963    srcs: [
964        "common/strings.cc",
965        "packet/python3_module.cc",
966        "l2cap/fcs.cc",
967        ":BluetoothPacketSources",
968        "hci/address.cc",
969        "hci/class_of_device.cc",
970
971    ],
972    generated_headers: [
973        "BluetoothGeneratedPackets_h",
974    ],
975    generated_sources: [
976        "BluetoothGeneratedPackets_python3_cc",
977    ],
978    header_libs: [
979        "pybind11_headers",
980    ],
981    cflags: [
982        "-fexceptions",
983    ],
984    rtti: true,
985}
986
987rust_protobuf {
988    name: "libbt_facade_proto",
989    crate_name: "bt_facade_proto",
990    protos: ["facade/common.proto"],
991    grpc_protos: [
992        "hci/facade/controller_facade.proto",
993        "hci/facade/hci_facade.proto",
994        "hal/hal_facade.proto",
995        "facade/rootservice.proto",
996    ],
997    source_stem: "facade",
998    host_supported: true,
999}
1000