1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
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"],
}
|