1package {
2    default_team: "trendy_team_android_rust",
3    default_applicable_licenses: ["Android-Apache-2.0"],
4}
5
6rust_defaults {
7    name: "librustutils_defaults",
8    srcs: ["lib.rs"],
9    rustlibs: [
10        "libanyhow",
11        "libcutils_bindgen",
12        "liblibc",
13        "libnix",
14        "libsystem_properties_bindgen_sys",
15        "libthiserror",
16    ],
17}
18
19rust_library {
20    name: "librustutils",
21    crate_name: "rustutils",
22    defaults: ["librustutils_defaults"],
23    shared_libs: [
24        "libbase",
25        "libcutils",
26    ],
27    apex_available: [
28        "//apex_available:platform",
29        "com.android.btservices",
30        "com.android.compos",
31        "com.android.uwb",
32        "com.android.virt",
33    ],
34    product_available: true,
35    vendor_available: true,
36    min_sdk_version: "29",
37}
38
39rust_test {
40    name: "librustutils_test",
41    crate_name: "librustutils_test_test",
42    defaults: ["librustutils_defaults"],
43    test_suites: ["general-tests"],
44    auto_gen_config: true,
45}
46
47// Build a separate rust_library rather than depending directly on libsystem_properties_bindgen,
48// to work around the fact that rust_bindgen targets only produce rlibs and not dylibs, which would
49// result in duplicate conflicting versions of liblibc. This will hopefully be fixed in the build
50// system, at which point we can delete this target and go back to using libsystem_properties_bindgen
51// directly.
52rust_library {
53    name: "libsystem_properties_bindgen_sys",
54    crate_name: "system_properties_bindgen",
55    srcs: [
56        ":libsystem_properties_bindgen",
57    ],
58    rustlibs: [
59        "liblibc",
60    ],
61    product_available: true,
62    vendor_available: true,
63    apex_available: [
64        "//apex_available:platform",
65        "com.android.btservices",
66        "com.android.compos",
67        "com.android.uwb",
68        "com.android.virt",
69    ],
70    min_sdk_version: "29",
71    lints: "none",
72    clippy_lints: "none",
73}
74
75rust_bindgen {
76    name: "libsystem_properties_bindgen",
77    wrapper_src: "bindgen/system_properties.h",
78    crate_name: "system_properties_bindgen",
79    source_stem: "bindings",
80
81    bindgen_flags: [
82        "--allowlist-function=__system_property_find",
83        "--allowlist-function=__system_property_foreach",
84        "--allowlist-function=__system_property_read_callback",
85        "--allowlist-function=__system_property_set",
86        "--allowlist-function=__system_property_wait",
87        "--blocklist-type=timespec",
88        "--raw-line",
89        "use libc::timespec;",
90    ],
91    rustlibs: [
92        "liblibc",
93    ],
94    product_available: true,
95    vendor_available: true,
96    apex_available: [
97        "//apex_available:platform",
98        "com.android.btservices",
99        "com.android.compos",
100        "com.android.uwb",
101        "com.android.virt",
102    ],
103    min_sdk_version: "29",
104}
105
106rust_bindgen {
107    name: "libcutils_bindgen",
108    wrapper_src: "bindgen/cutils.h",
109    crate_name: "cutils_bindgen",
110    source_stem: "bindings",
111    header_libs: ["libcutils_headers"],
112    bindgen_flags: [
113        "--allowlist-function",
114        "android_get_control_socket",
115        "--allowlist-var",
116        "AID_KEYSTORE",
117        "--allowlist-var",
118        "AID_ROOT",
119        "--allowlist-var",
120        "AID_SHELL",
121        "--allowlist-var",
122        "AID_SYSTEM",
123        "--allowlist-var",
124        "AID_USER_OFFSET",
125    ],
126    product_available: true,
127    vendor_available: true,
128    apex_available: [
129        "//apex_available:platform",
130        "com.android.btservices",
131        "com.android.compos",
132        "com.android.uwb",
133        "com.android.virt",
134    ],
135    min_sdk_version: "29",
136}
137
138rust_test {
139    name: "libsystem_properties_bindgen_test",
140    srcs: [":libsystem_properties_bindgen"],
141    crate_name: "system_properties_bindgen_test",
142    test_suites: ["general-tests"],
143    rustlibs: [
144        "liblibc",
145    ],
146    auto_gen_config: true,
147    clippy_lints: "none",
148    lints: "none",
149}
150
151rust_test {
152    name: "libcutils_bindgen_test",
153    srcs: [":libcutils_bindgen"],
154    crate_name: "cutils_bindgen_test",
155    test_suites: ["general-tests"],
156    auto_gen_config: true,
157    clippy_lints: "none",
158    lints: "none",
159}
160
161rust_fuzz {
162    name: "system_properties_fuzzer",
163    srcs: ["system_properties_fuzzer.rs"],
164    rustlibs: [
165        "libarbitrary",
166        "librustutils",
167    ],
168    fuzz_config: {
169        fuzz_on_haiku_device: true,
170        fuzz_on_haiku_host: true,
171    },
172}
173