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 "[email protected]", 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 ], 282 min_sdk_version: "Tiramisu", 283 srcs: [ 284 "rust/uci_hal_android/lib.rs", 285 ], 286} 287 288rust_library { 289 name: "libuci_hal_android", 290 defaults: ["libuci_hal_android_defaults"], 291 rustlibs: [ 292 "libuwb_core", 293 ], 294} 295 296// uci_hal_android built with uwb_core_with_mock. 297// Used to replace uci_hal_android in place where mock version of uwb_core is 298// used. 299rust_library { 300 name: "libuci_hal_android_with_mock", 301 defaults: ["libuci_hal_android_defaults"], 302 rustlibs: [ 303 "libuwb_core_with_mock", 304 ], 305 native_coverage: false, 306} 307 308rust_test { 309 name: "libuci_hal_android_tests", 310 defaults: ["libuci_hal_android_defaults"], 311 rustlibs: [ 312 "libenv_logger", 313 "libtempfile", 314 "libuwb_core", 315 ], 316 target: { 317 android: { 318 test_suites: [ 319 "general-tests", 320 "mts-uwb", 321 ], 322 test_config_template: "uwb_rust_test_config_template.xml", 323 }, 324 }, 325 // Support multilib variants (using different suffix per sub-architecture), which is needed on 326 // build targets with secondary architectures, as the MTS test suite packaging logic flattens 327 // all test artifacts into a single `testcases` directory. 328 compile_multilib: "both", 329 multilib: { 330 lib32: { 331 suffix: "32", 332 }, 333 lib64: { 334 suffix: "64", 335 }, 336 }, 337 auto_gen_config: true, 338 min_sdk_version: "33", 339} 340 341// Generate the artifacts zip for uwb_core library and its dependencies. 342genrule { 343 name: "uwb_core_artifacts", 344 tools: [ 345 "pdlc", 346 "soong_zip", 347 ], 348 srcs: [ 349 "rust/uwb_core/**/*", 350 "rust/uwb_uci_packets/**/*", 351 "rust/Cargo.toml", 352 ], 353 cmd: "mkdir $(genDir)/artifacts && " + // Create a artifacts directory and copy the source code into it. 354 "cp -r external/uwb/src/rust/uwb_core " + 355 " external/uwb/src/rust/uwb_uci_packets " + 356 " external/uwb/src/rust/Cargo.toml " + 357 " $(genDir)/artifacts && " + 358 359 // Generate uci_packets.rs at $(genDir)/artifacts/uwb_uci_packets/. 360 "$(location pdlc) --output-format rust " + 361 " external/uwb/src/rust/uwb_uci_packets/uci_packets.pdl " + 362 " > $(genDir)/artifacts/uwb_uci_packets/uci_packets.rs && " + 363 364 // Pack the artifacts directory and clean up the directory. 365 "$(location soong_zip) -o $(out) " + 366 " -C $(genDir)/artifacts " + 367 " -D $(genDir)/artifacts && " + 368 "rm -rf $(genDir)/artifacts", 369 out: [ 370 "uwb_core_artifacts.zip", 371 ], 372} 373 374// Verify if the uwb_core library can be built via cargo system. 375sh_test_host { 376 name: "libuwb_core_cargo_test", 377 src: "tests/libuwb_core_cargo_test.sh", 378 test_config: "tests/libuwb_core_cargo_test.xml", 379 test_suites: ["general-tests"], 380 data: [":uwb_core_artifacts"], 381 test_options: { 382 unit_test: false, 383 }, 384} 385