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    default_applicable_licenses: ["system_bt_license"],
8}
9
10rust_defaults {
11    name: "libbluetooth_core_rs_defaults",
12    min_sdk_version: "Tiramisu",
13    dylib: {
14        enabled: false,
15    },
16    srcs: [
17        "src/lib.rs",
18
19        ":bluetooth_core_rust_packets",
20    ],
21    shared_libs: [
22        "libbase",
23    ],
24    static_libs: [
25        "libbt_shim_bridge",
26        "libbt_shim_ffi",
27
28        "libchrome",
29        "libevent",
30        "libmodpb64",
31    ],
32    proc_macros: [
33        "libasync_trait",
34        "libpaste",
35    ],
36    rustlibs: [
37        "libanyhow",
38        "libbitflags",
39        "libbt_common",
40        "libcxx",
41        "liblog_rust",
42        "libscopeguard",
43
44        // needed to work around duplicate symbols
45        // caused by bug in Soong
46        "libbt_shim",
47    ],
48    whole_static_libs: [
49        "libbluetooth_core_rs_bridge",
50    ],
51    features: [
52        // used to hide libbt_shim in Cargo builds, but
53        // expose it to Soong to work around linker bug
54        "via_android_bp",
55    ],
56    target: {
57        android: {
58            shared_libs: [
59                "android.hardware.bluetooth@1.0",
60                "android.hardware.bluetooth@1.1",
61                "android.system.suspend-V1-ndk",
62                "android.system.suspend.control-V1-ndk",
63                "libbinder_ndk",
64                "libcutils",
65                "libhidlbase",
66                "libstatslog_bt",
67                "libutils",
68            ],
69        },
70    },
71    apex_available: ["com.android.btservices"],
72}
73
74rust_library {
75    name: "libbluetooth_core_rs_for_facade",
76    crate_name: "bluetooth_core_rs_for_facade",
77    defaults: ["libbluetooth_core_rs_defaults"],
78    rustlibs: [
79        "libtokio",
80    ],
81    host_supported: true,
82}
83
84rust_ffi_static {
85    name: "libbluetooth_core_rs",
86    crate_name: "bluetooth_core",
87    defaults: ["libbluetooth_core_rs_defaults"],
88    rustlibs: [
89        "libtokio",
90    ],
91    target: {
92        android: {
93            rustlibs: [
94                "libandroid_logger",
95            ],
96        },
97    },
98    host_supported: true,
99}
100
101rust_test_host {
102    name: "libbluetooth_core_rs_test",
103    defaults: ["libbluetooth_core_rs_defaults"],
104    rustlibs: [
105        "libtokio_for_test",
106        "libtokio_test",
107    ],
108}
109
110cc_library_static {
111    name: "libbluetooth_core_rs_bridge",
112    defaults: ["bluetooth_cflags"],
113    srcs: [
114        "src/connection/ffi/connection_shim.cc",
115        "src/core/ffi/module.cc",
116        "src/gatt/ffi/gatt_shim.cc",
117    ],
118    include_dirs: [
119        "packages/modules/Bluetooth/system",
120        "packages/modules/Bluetooth/system/gd",
121        "packages/modules/Bluetooth/system/include",
122        "packages/modules/Bluetooth/system/stack/include",
123        "packages/modules/Bluetooth/system/types",
124    ],
125    export_include_dirs: ["."],
126    static_libs: [
127        "libbluetooth_hci_pdl",
128        "libbluetooth_log",
129        "libbt_shim_bridge",
130        "libbt_shim_ffi",
131        "libchrome",
132        "libflatbuffers-cpp",
133    ],
134    generated_headers: [
135        "cxx-bridge-header",
136        "libbluetooth_core_rs_bridge_codegen_header",
137
138        "BluetoothGeneratedBundlerSchema_h_bfbs",
139        "BluetoothGeneratedDumpsysDataSchema_h",
140    ],
141    export_generated_headers: [
142        "libbluetooth_core_rs_bridge_codegen_header",
143    ],
144    host_supported: true,
145    generated_sources: ["libbluetooth_core_rs_bridge_codegen"],
146    apex_available: ["com.android.btservices"],
147    min_sdk_version: "Tiramisu",
148    // Bug: 286537287 this library gets linked with Rust objects but cross-language LTO
149    // isn't supported yet.
150    lto: {
151        never: true,
152    },
153}
154
155/// FFI codegen
156///
157/// The static library libbluetooth_core_rs_bridge is included by
158/// libbluetooth_core_rs and depends on libbluetooth_core. libbluetooth
159/// depends on libbluetooth_core_rs.
160/// i.e.
161/// libbluetooth -> {libbluetooth_core_rs, libbluetooth_core_rs_bridge} -> libbluetooth_core
162///
163/// Thus, FFI can be either:
164///  * Rust to GD
165///  * Legacy C++ to Rust
166///     * Core to Rust only via injected callbacks (libbluetooth_core does not
167///       depend on libbluetooth_core_rs)
168///     * Legacy C++ to Rust can be made directly (as libbluetooth *does* depend
169///       on libbluetooth_core_rs).
170///
171/// To add FFI for a new module, create an ffi.rs file, and add it to the filegroup below.
172
173filegroup {
174    name: "libbluetooth_core_rs_ffi",
175    srcs: [
176        "src/connection/ffi.rs",
177        "src/core/ffi.rs",
178        "src/gatt/ffi.rs",
179    ],
180}
181
182gensrcs {
183    name: "libbluetooth_core_rs_bridge_codegen_header",
184    tools: ["cxxbridge"],
185    cmd: "$(location cxxbridge) $(in) --header > $(out)",
186    srcs: [":libbluetooth_core_rs_ffi"],
187    output_extension: "rs.h",
188    export_include_dirs: ["."],
189}
190
191gensrcs {
192    name: "libbluetooth_core_rs_bridge_codegen",
193    tools: ["cxxbridge"],
194    cmd: "$(location cxxbridge) $(in) > $(out)",
195    srcs: [":libbluetooth_core_rs_ffi"],
196    output_extension: "cc",
197}
198
199genrule {
200    name: "bluetooth_core_rust_packets",
201    defaults: ["pdl_rust_noalloc_generator_defaults"],
202    srcs: ["src/packets.pdl"],
203    out: ["_packets.rs"],
204}
205