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: [ 113 "libchrome_support_defaults", 114 ], 115 srcs: [ 116 "src/connection/ffi/connection_shim.cc", 117 "src/core/ffi/module.cc", 118 "src/gatt/ffi/gatt_shim.cc", 119 ], 120 include_dirs: [ 121 "packages/modules/Bluetooth/system", 122 "packages/modules/Bluetooth/system/gd", 123 "packages/modules/Bluetooth/system/gd/rust/shim", 124 "packages/modules/Bluetooth/system/include", 125 "packages/modules/Bluetooth/system/internal_include", 126 "packages/modules/Bluetooth/system/stack/include", 127 "packages/modules/Bluetooth/system/types", 128 ], 129 export_include_dirs: ["."], 130 static_libs: [ 131 "libbt_shim_bridge", 132 "libbt_shim_ffi", 133 134 "libflatbuffers-cpp", 135 ], 136 generated_headers: [ 137 "cxx-bridge-header", 138 "libbluetooth_core_rs_bridge_codegen_header", 139 140 "BluetoothGeneratedBundlerSchema_h_bfbs", 141 "BluetoothGeneratedDumpsysDataSchema_h", 142 "BluetoothGeneratedPackets_h", 143 ], 144 export_generated_headers: [ 145 "libbluetooth_core_rs_bridge_codegen_header", 146 ], 147 host_supported: true, 148 generated_sources: ["libbluetooth_core_rs_bridge_codegen"], 149 apex_available: ["com.android.btservices"], 150 min_sdk_version: "Tiramisu", 151} 152 153/// FFI codegen 154/// 155/// The static library libbluetooth_core_rs_bridge is included by 156/// libbluetooth_core_rs and depends on libbluetooth_core. libbluetooth 157/// depends on libbluetooth_core_rs. 158/// i.e. 159/// libbluetooth -> {libbluetooth_core_rs, libbluetooth_core_rs_bridge} -> libbluetooth_core 160/// 161/// Thus, FFI can be either: 162/// * Rust to GD 163/// * Legacy C++ to Rust 164/// * Core to Rust only via injected callbacks (libbluetooth_core does not 165/// depend on libbluetooth_core_rs) 166/// * Legacy C++ to Rust can be made directly (as libbluetooth *does* depend 167/// on libbluetooth_core_rs). 168/// 169/// To add FFI for a new module, create an ffi.rs file, and add it to the filegroup below. 170 171filegroup { 172 name: "libbluetooth_core_rs_ffi", 173 srcs: [ 174 "src/connection/ffi.rs", 175 "src/core/ffi.rs", 176 "src/gatt/ffi.rs", 177 ], 178} 179 180gensrcs { 181 name: "libbluetooth_core_rs_bridge_codegen_header", 182 tools: ["cxxbridge"], 183 cmd: "$(location cxxbridge) $(in) --header > $(out)", 184 srcs: [":libbluetooth_core_rs_ffi"], 185 output_extension: "rs.h", 186 export_include_dirs: ["."], 187} 188 189gensrcs { 190 name: "libbluetooth_core_rs_bridge_codegen", 191 tools: ["cxxbridge"], 192 cmd: "$(location cxxbridge) $(in) > $(out)", 193 srcs: [":libbluetooth_core_rs_ffi"], 194 output_extension: "cc", 195} 196 197genrule { 198 name: "bluetooth_core_rust_packets", 199 defaults: ["pdl_rust_noalloc_generator_defaults"], 200 srcs: ["src/packets.pdl"], 201 out: ["_packets.rs"], 202} 203