blob: 344da0728df42df3e72ad222a479d495b9bab6a1 [file] [edit]
package {
// See: http://go/android-license-faq
// A large-scale-change added 'default_applicable_licenses' to import
// all of the 'license_kinds' from "system_bt_license"
// to get the below license kinds:
// SPDX-license-identifier-Apache-2.0
default_applicable_licenses: ["system_bt_license"],
}
rust_defaults {
name: "libbluetooth_core_rs_defaults",
min_sdk_version: "Tiramisu",
dylib: {
enabled: false,
},
srcs: [
"src/lib.rs",
":bluetooth_core_rust_packets",
],
shared_libs: [
"libbase",
],
static_libs: [
"libchrome",
"libevent",
"libmodpb64",
],
proc_macros: [
"libasync_trait",
"libpaste",
],
rustlibs: [
"libanyhow",
"libbitflags",
"libbytes",
"libcxx",
"liblog_rust",
"libpdl_runtime",
"libscopeguard",
],
whole_static_libs: [
"libbluetooth_core_rs_bridge",
],
target: {
android: {
shared_libs: [
"android.hardware.bluetooth@1.0",
"android.hardware.bluetooth@1.1",
"android.system.suspend-V1-ndk",
"android.system.suspend.control-V1-ndk",
"libbinder_ndk",
"libcutils",
"libhidlbase",
"libstatslog_bt",
"libutils",
],
rustlibs: [
"libandroid_logger",
],
test_config_template: ":BluetoothRustTestConfigTemplate",
test_suites: [
"general-tests",
"mts-bt",
],
},
host: {
rustlibs: [
"libenv_logger",
],
},
darwin: {
enabled: false,
},
},
compile_multilib: "both",
multilib: {
lib32: {
suffix: "32",
},
lib64: {
suffix: "64",
},
},
apex_available: [
"//apex_available:platform",
"com.android.bt",
],
}
rust_ffi_static {
name: "libbluetooth_core_rs",
crate_name: "bluetooth_core",
defaults: ["libbluetooth_core_rs_defaults"],
rustlibs: [
"libbluetooth_aconfig_flags_rust",
"libtokio",
],
target: {
android: {
rustlibs: [
"libandroid_logger",
],
},
},
host_supported: true,
}
rust_test {
name: "libbluetooth_core_rs_test",
host_supported: true,
defaults: ["libbluetooth_core_rs_defaults"],
rustlibs: [
"libbluetooth_aconfig_flags_rust",
"libtokio_for_test",
"libtokio_test",
],
}
cc_library_static {
name: "libbluetooth_core_rs_bridge",
defaults: ["bluetooth_cflags"],
cflags: [
// The generated code triggers these warnings.
"-Wno-missing-prototypes",
],
srcs: [
"src/core/ffi/module.cc",
"src/gatt/ffi/gatt_shim.cc",
],
include_dirs: [
"packages/modules/Bluetooth/system",
"packages/modules/Bluetooth/system/gd",
"packages/modules/Bluetooth/system/include",
"packages/modules/Bluetooth/system/stack/include",
],
export_include_dirs: ["."],
static_libs: [
"libbluetooth_hci_pdl",
"libbluetooth_log",
"libchrome",
"libflatbuffers-cpp",
],
generated_headers: [
"cxx-bridge-header",
"libbluetooth_core_rs_bridge_codegen_header",
],
export_generated_headers: [
"cxx-bridge-header",
"libbluetooth_core_rs_bridge_codegen_header",
],
host_supported: true,
generated_sources: ["libbluetooth_core_rs_bridge_codegen"],
apex_available: ["com.android.bt"],
min_sdk_version: "Tiramisu",
// Bug: 286537287 this library gets linked with Rust objects but cross-language LTO
// isn't supported yet.
lto: {
never: true,
},
}
/// FFI codegen
///
/// The static library libbluetooth_core_rs_bridge is included by
/// libbluetooth_core_rs and depends on libbluetooth_core. libbluetooth
/// depends on libbluetooth_core_rs.
/// i.e.
/// libbluetooth -> {libbluetooth_core_rs, libbluetooth_core_rs_bridge} -> libbluetooth_core
///
/// Thus, FFI can be either:
/// * Rust to GD
/// * Legacy C++ to Rust
/// * Core to Rust only via injected callbacks (libbluetooth_core does not
/// depend on libbluetooth_core_rs)
/// * Legacy C++ to Rust can be made directly (as libbluetooth *does* depend
/// on libbluetooth_core_rs).
///
/// To add FFI for a new module, create an ffi.rs file, and add it to the filegroup below.
filegroup {
name: "libbluetooth_core_rs_ffi",
srcs: [
"src/core/ffi.rs",
"src/gatt/ffi.rs",
],
}
gensrcs {
name: "libbluetooth_core_rs_bridge_codegen_header",
tools: ["cxxbridge"],
cmd: "$(location cxxbridge) $(in) --header > $(out)",
srcs: [":libbluetooth_core_rs_ffi"],
output_extension: "rs.h",
export_include_dirs: ["."],
}
gensrcs {
name: "libbluetooth_core_rs_bridge_codegen",
tools: ["cxxbridge"],
cmd: "$(location cxxbridge) $(in) > $(out)",
srcs: [":libbluetooth_core_rs_ffi"],
output_extension: "cc",
}
genrule {
name: "bluetooth_core_rust_packets",
defaults: ["pdl_rust_generator_defaults"],
srcs: ["src/packets.pdl"],
out: ["_packets.rs"],
}