1package { 2 default_applicable_licenses: ["external_uwb_license"], 3} 4 5rust_defaults { 6 name: "libuwb_uci_packet_defaults", 7 srcs: [ 8 "rust/uwb_uci_packets/src/lib.rs", 9 ":UwbGeneratedPackets_rust", 10 ], 11 edition: "2021", 12 proc_macros: ["libnum_derive"], 13 rustlibs: [ 14 "libbytes", 15 "liblog_rust", 16 "libnum_traits", 17 "libpdl_runtime", 18 "libzeroize", 19 ], 20 host_supported: true, 21} 22 23rust_test { 24 name: "libuwb_uci_packet_tests", 25 defaults: ["libuwb_uci_packet_defaults"], 26 target: { 27 android: { 28 test_suites: [ 29 "general-tests", 30 "mts-uwb", 31 ], 32 test_config_template: "uwb_rust_test_config_template.xml", 33 }, 34 host: { 35 test_suites: [ 36 "general-tests", 37 ], 38 // See b/268061150 39 stem: "libuwb_uci_packet_tests_host", 40 }, 41 }, 42 // Support multilib variants (using different suffix per sub-architecture), which is needed on 43 // build targets with secondary architectures, as the MTS test suite packaging logic flattens 44 // all test artifacts into a single `testcases` directory. 45 compile_multilib: "both", 46 multilib: { 47 lib32: { 48 suffix: "32", 49 }, 50 lib64: { 51 suffix: "64", 52 }, 53 }, 54 auto_gen_config: true, 55 min_sdk_version: "33", 56} 57 58rust_library { 59 name: "libuwb_uci_packets", 60 defaults: ["libuwb_uci_packet_defaults"], 61 crate_name: "uwb_uci_packets", 62 apex_available: [ 63 "//apex_available:platform", 64 "com.android.uwb", 65 ], 66 min_sdk_version: "Tiramisu", 67 vendor_available: true, 68} 69 70genrule { 71 name: "UwbGeneratedPackets_rust", 72 defaults: ["pdl_rust_legacy_generator_defaults"], 73 srcs: [ 74 "rust/uwb_uci_packets/uci_packets.pdl", 75 ], 76 out: [ 77 "rust/uwb_uci_packets/uci_packets.rs", 78 ], 79} 80 81rust_defaults { 82 name: "libuwb_core_defaults", 83 srcs: ["rust/uwb_core/src/lib.rs"], 84 edition: "2021", 85 lints: "android", 86 clippy_lints: "android", 87 rustlibs: [ 88 "libbytes", 89 "libnum_traits", 90 "liblog_rust", 91 "libpdl_runtime", 92 "libthiserror", 93 "libtokio", 94 "libuwb_uci_packets", 95 "libzeroize", 96 ], 97 proc_macros: [ 98 "libasync_trait", 99 "libnum_derive", 100 ], 101 min_sdk_version: "Tiramisu", 102} 103 104// Build uwb_core library with the production version of Aconfig flags lib. 105rust_library { 106 name: "libuwb_core", 107 defaults: ["libuwb_core_defaults"], 108 crate_name: "uwb_core", 109 apex_available: [ 110 "com.android.uwb", 111 ], 112} 113 114// Builds uwb_core library with "mock-utils" enabled. 115// This enables mock methods to be used for testing external crates. 116rust_library { 117 name: "libuwb_core_with_mock", 118 defaults: ["libuwb_core_defaults"], 119 crate_name: "uwb_core", 120 features: ["mock-utils"], 121 host_supported: true, 122 native_coverage: false, 123} 124 125// The test target uses the test version of Aconfig flags lib, as that has 126// support for setting the flag values in unit tests. 127rust_test { 128 name: "libuwb_core_tests", 129 defaults: ["libuwb_core_defaults"], 130 rustlibs: [ 131 "libenv_logger", 132 "libtempfile", 133 ], 134 target: { 135 android: { 136 test_suites: [ 137 "general-tests", 138 "mts-uwb", 139 ], 140 test_config_template: "uwb_rust_test_config_template.xml", 141 }, 142 }, 143 // Support multilib variants (using different suffix per sub-architecture), which is needed on 144 // build targets with secondary architectures, as the MTS test suite packaging logic flattens 145 // all test artifacts into a single `testcases` directory. 146 compile_multilib: "both", 147 multilib: { 148 lib32: { 149 suffix: "32", 150 }, 151 lib64: { 152 suffix: "64", 153 }, 154 }, 155 auto_gen_config: true, 156 min_sdk_version: "33", 157} 158 159rust_binary { 160 name: "uwb_core_examples", 161 srcs: ["rust/uwb_core/examples/main.rs"], 162 rustlibs: [ 163 "libenv_logger", 164 "liblog_rust", 165 "libtokio", 166 "libuwb_core", 167 ], 168 proc_macros: [ 169 "libasync_trait", 170 ], 171 172 lints: "android", 173 clippy_lints: "android", 174 min_sdk_version: "Tiramisu", 175} 176 177// Build the uwb_core library with "proto" feature enabled. 178// It's used for fuzzer test. 179rust_library { 180 name: "libuwb_core_with_proto", 181 defaults: ["libuwb_core_defaults"], 182 crate_name: "uwb_core", 183 srcs: [ 184 // Generate the protobuf bindings. 185 // These genrule follows the logic of rust/uwb_core/build.rs. 186 ":gen_uwb_core_proto", 187 ":include_uwb_core_proto", 188 ], 189 rustlibs: [ 190 "libprotobuf", 191 ], 192 flags: [ 193 // Required due to the protoc-gen-rust tool emitting invalid 194 // annotations. This can be removed when we upgrade to protobuf-4, 195 // if we patch protobuf-3 to no longer emit `#![allow(box_pointers)]`, 196 // or switch to using a `rust_protobuf` rule instead of a `genrule`. 197 "-A renamed_and_removed_lints", 198 ], 199 features: ["proto"], 200 host_supported: true, 201 native_coverage: false, 202} 203 204genrule { 205 name: "gen_uwb_core_proto", 206 tools: [ 207 "aprotoc", 208 "protoc-gen-rust", 209 ], 210 cmd: "$(location aprotoc)" + 211 " --proto_path=`dirname $(in)`" + 212 " --plugin=protoc-gen-rust=$(location protoc-gen-rust)" + 213 " --rust_out=$(genDir) $(in)", 214 srcs: [ 215 "rust/uwb_core/protos/uwb_service.proto", 216 ], 217 out: [ 218 "uwb_service.rs", 219 ], 220} 221 222genrule { 223 name: "include_uwb_core_proto", 224 cmd: "echo '#[path = \"uwb_service.rs\"]' > $(out);" + 225 "echo 'pub mod bindings;' >> $(out);", 226 out: [ 227 "proto_bindings.rs", 228 ], 229} 230 231rust_fuzz { 232 name: "uwb_core_fuzzer", 233 srcs: [ 234 "rust/uwb_core/fuzz/proto_uwb_service_fuzzer.rs", 235 ], 236 rustlibs: [ 237 "libarbitrary", 238 "libuwb_core_with_proto", 239 ], 240 fuzz_config: { 241 cc: [ 242 "android-uwb-team@google.com", 243 ], 244 componentid: 1042770, 245 fuzz_on_haiku_device: false, 246 fuzz_on_haiku_host: false, 247 }, 248 249} 250 251rust_defaults { 252 name: "libuci_hal_android_defaults", 253 crate_name: "uci_hal_android", 254 lints: "android", 255 clippy_lints: "android", 256 rustlibs: [ 257 "android.hardware.uwb-V1-rust", 258 "libanyhow", 259 "libbinder_rs", 260 "libbinder_tokio_rs", 261 "libbytes", 262 "libjni_legacy", 263 "liblog_rust", 264 "libpdl_runtime", 265 "libthiserror", 266 "libtokio", 267 "libuwb_uci_packets", 268 ], 269 target: { 270 android: { 271 rustlibs: [ 272 "librustutils", 273 ], 274 }, 275 }, 276 proc_macros: [ 277 "libasync_trait", 278 ], 279 apex_available: [ 280 "com.android.uwb", 281 "//apex_available:platform", 282 ], 283 min_sdk_version: "Tiramisu", 284 srcs: [ 285 "rust/uci_hal_android/lib.rs", 286 ], 287} 288 289rust_library { 290 name: "libuci_hal_android", 291 defaults: ["libuci_hal_android_defaults"], 292 rustlibs: [ 293 "libuwb_core", 294 ], 295} 296 297// uci_hal_android built with uwb_core_with_mock. 298// Used to replace uci_hal_android in place where mock version of uwb_core is 299// used. 300rust_library { 301 name: "libuci_hal_android_with_mock", 302 defaults: ["libuci_hal_android_defaults"], 303 rustlibs: [ 304 "libuwb_core_with_mock", 305 ], 306 native_coverage: false, 307} 308 309rust_test { 310 name: "libuci_hal_android_tests", 311 defaults: ["libuci_hal_android_defaults"], 312 rustlibs: [ 313 "libenv_logger", 314 "libtempfile", 315 "libuwb_core", 316 ], 317 target: { 318 android: { 319 test_suites: [ 320 "general-tests", 321 "mts-uwb", 322 ], 323 test_config_template: "uwb_rust_test_config_template.xml", 324 }, 325 }, 326 // Support multilib variants (using different suffix per sub-architecture), which is needed on 327 // build targets with secondary architectures, as the MTS test suite packaging logic flattens 328 // all test artifacts into a single `testcases` directory. 329 compile_multilib: "both", 330 multilib: { 331 lib32: { 332 suffix: "32", 333 }, 334 lib64: { 335 suffix: "64", 336 }, 337 }, 338 auto_gen_config: true, 339 min_sdk_version: "33", 340} 341 342// Generate the artifacts zip for uwb_core library and its dependencies. 343genrule { 344 name: "uwb_core_artifacts", 345 tools: [ 346 "pdlc", 347 "soong_zip", 348 ], 349 srcs: [ 350 "rust/uwb_core/**/*", 351 "rust/uwb_uci_packets/**/*", 352 "rust/Cargo.toml", 353 ], 354 cmd: "mkdir $(genDir)/artifacts && " + // Create a artifacts directory and copy the source code into it. 355 "cp -r external/uwb/src/rust/uwb_core " + 356 " external/uwb/src/rust/uwb_uci_packets " + 357 " external/uwb/src/rust/Cargo.toml " + 358 " $(genDir)/artifacts && " + 359 360 // Generate uci_packets.rs at $(genDir)/artifacts/uwb_uci_packets/. 361 "$(location pdlc) --output-format rust " + 362 " external/uwb/src/rust/uwb_uci_packets/uci_packets.pdl " + 363 " > $(genDir)/artifacts/uwb_uci_packets/uci_packets.rs && " + 364 365 // Pack the artifacts directory and clean up the directory. 366 "$(location soong_zip) -o $(out) " + 367 " -C $(genDir)/artifacts " + 368 " -D $(genDir)/artifacts && " + 369 "rm -rf $(genDir)/artifacts", 370 out: [ 371 "uwb_core_artifacts.zip", 372 ], 373} 374 375// Verify if the uwb_core library can be built via cargo system. 376sh_test_host { 377 name: "libuwb_core_cargo_test", 378 src: "tests/libuwb_core_cargo_test.sh", 379 test_config: "tests/libuwb_core_cargo_test.xml", 380 test_suites: ["general-tests"], 381 data: [":uwb_core_artifacts"], 382 test_options: { 383 unit_test: false, 384 }, 385} 386