• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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        "libthiserror",
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_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        "libthiserror",
92        "libtokio",
93        "libuwb_uci_packets",
94        "libzeroize",
95    ],
96    proc_macros: [
97        "libasync_trait",
98        "libnum_derive",
99    ],
100    min_sdk_version: "Tiramisu",
101    host_supported: true,
102}
103
104rust_library {
105    name: "libuwb_core",
106    defaults: ["libuwb_core_defaults"],
107    crate_name: "uwb_core",
108    apex_available: [
109        "com.android.uwb",
110    ],
111}
112
113// Builds uwb_core library with "mock-utils" enabled.
114// This enables mock methods to be used for testing external crates.
115rust_library {
116    name: "libuwb_core_with_mock",
117    defaults: ["libuwb_core_defaults"],
118    crate_name: "uwb_core",
119    features: ["mock-utils"],
120    host_supported: true,
121}
122
123rust_test {
124    name: "libuwb_core_tests",
125    defaults: ["libuwb_core_defaults"],
126    rustlibs: [
127        "libenv_logger",
128        "libtempfile",
129    ],
130    target: {
131        android: {
132            test_suites: [
133                "general-tests",
134                "mts-uwb"
135            ],
136            test_config_template: "uwb_rust_test_config_template.xml",
137        },
138        host: {
139            test_suites: [
140                "general-tests",
141            ],
142            data_libs: [
143                "libandroid_runtime_lazy",
144                "libbase",
145                "libcutils",
146                "liblog",
147                "libutils",
148            ],
149            // See b/268061150
150            stem: "libuwb_core_tests_host",
151        },
152    },
153    // Support multilib variants (using different suffix per sub-architecture), which is needed on
154    // build targets with secondary architectures, as the MTS test suite packaging logic flattens
155    // all test artifacts into a single `testcases` directory.
156    compile_multilib: "both",
157    multilib: {
158        lib32: {
159            suffix: "32",
160        },
161        lib64: {
162            suffix: "64",
163        },
164    },
165    auto_gen_config: true,
166    min_sdk_version: "33",
167}
168
169rust_binary {
170    name: "uwb_core_examples",
171    srcs: ["rust/uwb_core/examples/main.rs"],
172    rustlibs: [
173        "libenv_logger",
174        "liblog_rust",
175        "libtokio",
176        "libuwb_core",
177    ],
178    proc_macros: [
179        "libasync_trait",
180    ],
181
182    lints: "android",
183    clippy_lints: "android",
184    min_sdk_version: "Tiramisu",
185    host_supported: true,
186}
187
188// Build the uwb_core library with "proto" feature enabled.
189// It's used for fuzzer test.
190rust_library {
191    name: "libuwb_core_with_proto",
192    defaults: ["libuwb_core_defaults"],
193    crate_name: "uwb_core",
194    srcs: [
195        // Generate the protobuf bindings.
196        // These genrule follows the logic of rust/uwb_core/build.rs.
197        ":gen_uwb_core_proto",
198        ":include_uwb_core_proto",
199    ],
200    rustlibs: [
201        "libprotobuf_deprecated",
202    ],
203    features: ["proto"],
204    host_supported: true,
205}
206
207genrule {
208    name: "gen_uwb_core_proto",
209    tools: ["aprotoc", "protoc-gen-rust-deprecated"],
210    cmd: "$(location aprotoc)" +
211         " --proto_path=`dirname $(in)`" +
212         " --dependency_out=$(depfile)" +
213         " --plugin=protoc-gen-rust=$(location protoc-gen-rust-deprecated)" +
214         " --rust_out=$(genDir) $(in)",
215    srcs: [
216        "rust/uwb_core/protos/uwb_service.proto",
217    ],
218    out: [
219        "uwb_service.rs",
220    ],
221    depfile: true,
222}
223
224genrule {
225    name: "include_uwb_core_proto",
226    cmd: "echo '#[path = \"uwb_service.rs\"]' > $(out);" +
227         "echo 'pub mod bindings;' >> $(out);",
228    out: [
229        "proto_bindings.rs",
230    ],
231}
232
233rust_fuzz {
234    name: "uwb_core_fuzzer",
235    srcs: [
236        "rust/uwb_core/fuzz/proto_uwb_service_fuzzer.rs",
237    ],
238    rustlibs: [
239        "libarbitrary",
240        "libuwb_core_with_proto",
241    ],
242    fuzz_config: {
243        cc: [
244            "android-uwb-team@google.com",
245        ],
246        componentid: 1042770,
247        fuzz_on_haiku_device: true,
248        fuzz_on_haiku_host: true,
249    },
250}
251
252rust_defaults {
253    name: "libuci_hal_android_defaults",
254    crate_name: "uci_hal_android",
255    lints: "android",
256    clippy_lints: "android",
257    rustlibs: [
258        "android.hardware.uwb-V1-rust",
259        "libanyhow",
260        "libbinder_rs",
261        "libbinder_tokio_rs",
262        "libbytes",
263        "libjni",
264        "liblog_rust",
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    host_supported: true,
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}
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        host: {
325            test_suites: [
326                "general-tests",
327            ],
328            data_libs: [
329                "libandroid_runtime_lazy",
330                "libbase",
331                "libcutils",
332                "liblog",
333                "libutils",
334            ],
335            // See b/268061150
336            stem: "libuci_hal_android_tests_host",
337        },
338    },
339    // Support multilib variants (using different suffix per sub-architecture), which is needed on
340    // build targets with secondary architectures, as the MTS test suite packaging logic flattens
341    // all test artifacts into a single `testcases` directory.
342    compile_multilib: "both",
343    multilib: {
344        lib32: {
345            suffix: "32",
346        },
347        lib64: {
348            suffix: "64",
349        },
350    },
351    auto_gen_config: true,
352    min_sdk_version: "33",
353}
354
355// Generate the artifacts zip for uwb_core library and its dependencies.
356genrule {
357    name: "uwb_core_artifacts",
358    tools: [
359        "pdl",
360        "soong_zip",
361    ],
362    cmd:
363        // Create a artifacts directory and copy the source code into it.
364        "mkdir $(genDir)/artifacts;" +
365        "cp -r external/uwb/src/rust/uwb_core " +
366        "      external/uwb/src/rust/uwb_uci_packets " +
367        "      external/uwb/src/rust/Cargo.toml " +
368        "      $(genDir)/artifacts;" +
369
370        // Generate uci_packets.rs at $(genDir)/artifacts/uwb_uci_packets/.
371        "$(location pdl) --output-format rust " +
372        "      external/uwb/src/rust/uwb_uci_packets/uci_packets.pdl " +
373        "      > $(genDir)/artifacts/uwb_uci_packets/uci_packets.rs;" +
374
375        // Pack the artifacts directory and clean up the directory.
376        "$(location soong_zip) -o $(out) " +
377        "                      -C $(genDir)/artifacts " +
378        "                      -D $(genDir)/artifacts;" +
379        "rm -rf $(genDir)/artifacts",
380    out: [
381        "uwb_core_artifacts.zip",
382    ],
383}
384
385// Verify if the uwb_core library can be built via cargo system.
386sh_test_host {
387    name: "libuwb_core_cargo_test",
388    src: "tests/libuwb_core_cargo_test.sh",
389    test_config: "tests/libuwb_core_cargo_test.xml",
390    test_suites: ["general-tests"],
391    data: [":uwb_core_artifacts"],
392    test_options: {
393        unit_test: false,
394    },
395}
396