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 features: ["proto"], 193 host_supported: true, 194 native_coverage: false, 195} 196 197genrule { 198 name: "gen_uwb_core_proto", 199 tools: ["aprotoc", "protoc-gen-rust"], 200 cmd: "$(location aprotoc)" + 201 " --proto_path=`dirname $(in)`" + 202 " --plugin=protoc-gen-rust=$(location protoc-gen-rust)" + 203 " --rust_out=$(genDir) $(in)", 204 srcs: [ 205 "rust/uwb_core/protos/uwb_service.proto", 206 ], 207 out: [ 208 "uwb_service.rs", 209 ], 210} 211 212genrule { 213 name: "include_uwb_core_proto", 214 cmd: "echo '#[path = \"uwb_service.rs\"]' > $(out);" + 215 "echo 'pub mod bindings;' >> $(out);", 216 out: [ 217 "proto_bindings.rs", 218 ], 219} 220 221rust_fuzz { 222 name: "uwb_core_fuzzer", 223 srcs: [ 224 "rust/uwb_core/fuzz/proto_uwb_service_fuzzer.rs", 225 ], 226 rustlibs: [ 227 "libarbitrary", 228 "libuwb_core_with_proto", 229 ], 230 fuzz_config: { 231 cc: [ 232 "android-uwb-team@google.com", 233 ], 234 componentid: 1042770, 235 fuzz_on_haiku_device: true, 236 fuzz_on_haiku_host: true, 237 }, 238} 239 240rust_defaults { 241 name: "libuci_hal_android_defaults", 242 crate_name: "uci_hal_android", 243 lints: "android", 244 clippy_lints: "android", 245 rustlibs: [ 246 "android.hardware.uwb-V1-rust", 247 "libanyhow", 248 "libbinder_rs", 249 "libbinder_tokio_rs", 250 "libbytes", 251 "libjni_legacy", 252 "liblog_rust", 253 "libpdl_runtime", 254 "libthiserror", 255 "libtokio", 256 "libuwb_uci_packets", 257 ], 258 target: { 259 android: { 260 rustlibs: [ 261 "librustutils", 262 ], 263 }, 264 }, 265 proc_macros: [ 266 "libasync_trait", 267 ], 268 apex_available: [ 269 "com.android.uwb", 270 ], 271 min_sdk_version: "Tiramisu", 272 srcs: [ 273 "rust/uci_hal_android/lib.rs", 274 ], 275} 276 277rust_library { 278 name: "libuci_hal_android", 279 defaults: ["libuci_hal_android_defaults"], 280 rustlibs: [ 281 "libuwb_core", 282 ], 283} 284 285// uci_hal_android built with uwb_core_with_mock. 286// Used to replace uci_hal_android in place where mock version of uwb_core is 287// used. 288rust_library { 289 name: "libuci_hal_android_with_mock", 290 defaults: ["libuci_hal_android_defaults"], 291 rustlibs: [ 292 "libuwb_core_with_mock", 293 ], 294 native_coverage: false, 295} 296 297rust_test { 298 name: "libuci_hal_android_tests", 299 defaults: ["libuci_hal_android_defaults"], 300 rustlibs: [ 301 "libenv_logger", 302 "libtempfile", 303 "libuwb_core", 304 ], 305 target: { 306 android: { 307 test_suites: [ 308 "general-tests", 309 "mts-uwb" 310 ], 311 test_config_template: "uwb_rust_test_config_template.xml", 312 }, 313 }, 314 // Support multilib variants (using different suffix per sub-architecture), which is needed on 315 // build targets with secondary architectures, as the MTS test suite packaging logic flattens 316 // all test artifacts into a single `testcases` directory. 317 compile_multilib: "both", 318 multilib: { 319 lib32: { 320 suffix: "32", 321 }, 322 lib64: { 323 suffix: "64", 324 }, 325 }, 326 auto_gen_config: true, 327 min_sdk_version: "33", 328} 329 330// Generate the artifacts zip for uwb_core library and its dependencies. 331genrule { 332 name: "uwb_core_artifacts", 333 tools: [ 334 "pdlc", 335 "soong_zip", 336 ], 337 srcs: [ 338 "rust/uwb_core/**/*", 339 "rust/uwb_uci_packets/**/*", 340 "rust/Cargo.toml", 341 ], 342 cmd: 343 // Create a artifacts directory and copy the source code into it. 344 "mkdir $(genDir)/artifacts && " + 345 "cp -r external/uwb/src/rust/uwb_core " + 346 " external/uwb/src/rust/uwb_uci_packets " + 347 " external/uwb/src/rust/Cargo.toml " + 348 " $(genDir)/artifacts && " + 349 350 // Generate uci_packets.rs at $(genDir)/artifacts/uwb_uci_packets/. 351 "$(location pdlc) --output-format rust " + 352 " external/uwb/src/rust/uwb_uci_packets/uci_packets.pdl " + 353 " > $(genDir)/artifacts/uwb_uci_packets/uci_packets.rs && " + 354 355 // Pack the artifacts directory and clean up the directory. 356 "$(location soong_zip) -o $(out) " + 357 " -C $(genDir)/artifacts " + 358 " -D $(genDir)/artifacts && " + 359 "rm -rf $(genDir)/artifacts", 360 out: [ 361 "uwb_core_artifacts.zip", 362 ], 363} 364 365// Verify if the uwb_core library can be built via cargo system. 366sh_test_host { 367 name: "libuwb_core_cargo_test", 368 src: "tests/libuwb_core_cargo_test.sh", 369 test_config: "tests/libuwb_core_cargo_test.xml", 370 test_suites: ["general-tests"], 371 data: [":uwb_core_artifacts"], 372 test_options: { 373 unit_test: false, 374 }, 375} 376