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