android-binder 0.2.0

Safe bindings to Android Binder, restricted to the NDK
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "frameworks_native_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["frameworks_native_license"],
}

// TODO(b/402766978) : This bindgen is meant for NDK APIs for which we
// need the API level checks as rust has no support for it.
rust_bindgen {
    name: "libbinder_ndk_compat_bindgen",
    crate_name: "binder_ndk_compat_bindgen",
    host_supported: true,
    vendor_available: true,
    product_available: true,
    recovery_available: true,
    wrapper_src: "src/cpp/include/binder_rust.hpp",
    source_stem: "bindings",
    visibility: [":__subpackages__"],
    bindgen_flags: [
        "--raw-line",
        "#![no_std]",
        "--blocklist-type",
        "AIBinder_Class",
        "--blocklist-type",
        "AIBinder",
        "--allowlist-function",
        "Compat_AIBinder_Class_setTransactionCodeToFunctionNameMap",
        "--allowlist-function",
        "Compat_AIBinder_Class_getFunctionName",
        "--allowlist-function",
        "Compat_AIBinder_requiresVintfDeclaration",
        "--allowlist-function",
        "Compat_AIBinder_isVendorStable",
        "--allowlist-function",
        "Compat_AIBinder_isSystemStable",
        "--raw-line",
        "use binder_ndk_sys::AIBinder_Class;",
        "--raw-line",
        "use binder_ndk_sys::AIBinder;",
        "--use-core",
        "--ctypes-prefix",
        "::core::ffi",
    ],
    apex_available: [
        "//apex_available:platform",
        "//apex_available:anyapex",
    ],
    shared_libs: [
        "libbinder_ndk",
    ],
    rustlibs: [
        "libbinder_ndk_sys",
    ],
    min_sdk_version: "Tiramisu",
    no_std: {
        enabled: true,
    },
}

// TODO(b/402766978) : This c++ lib is wrapper for calling NDK APIs for which we
// need the API level checks as rust has no support for it.
cc_library_static {
    name: "libbinder_rs_compat",
    srcs: ["src/cpp/binder_rust.cpp"],
    host_supported: true,
    vendor_available: true,
    product_available: true,
    recovery_available: true,
    min_sdk_version: "Tiramisu",
    shared_libs: [
        "libbinder_ndk",
    ],
    apex_available: [
        "//apex_available:platform",
        "//apex_available:anyapex",
    ],
    visibility: [":__subpackages__"],
}

// TODO(b/402766978) : rust lib which calls into C++ wrapper API around the NDK APIs.
rust_library {
    name: "libbinder_rs_ndk_compat",
    crate_name: "binder_rs_ndk_compat",
    srcs: ["src/cpp/lib.rs"],
    whole_static_libs: [
        "libbinder_rs_compat",
    ],
    shared_libs: [
        "libbinder_ndk",
    ],
    rustlibs: [
        "libbinder_ndk_compat_bindgen",
        "libbinder_ndk_sys",
    ],
    host_supported: true,
    vendor_available: true,
    product_available: true,
    recovery_available: true,
    target: {
        darwin: {
            enabled: false,
        },
    },
    apex_available: [
        "//apex_available:platform",
        "//apex_available:anyapex",
    ],
    min_sdk_version: "Tiramisu",
    visibility: [":__subpackages__"],
    no_std: {
        enabled: true,
    },
}

rust_library {
    name: "libbinder_rs",
    crate_name: "binder",
    srcs: ["src/lib.rs"],
    rustlibs: [
        "libbinder_ndk_sys",
        "libdowncast_rs",
        "liblibc",
        "liblog_rust",
        "libstatic_assertions",
        "libzerocopy",
        "libbinder_rs_ndk_compat",
    ],
    host_supported: true,
    vendor_available: true,
    product_available: true,
    recovery_available: true,
    target: {
        darwin: {
            enabled: false,
        },
    },
    apex_available: [
        "//apex_available:platform",
        "//apex_available:anyapex",
    ],
    features: [
        "std",
        "kernel_ipc",
        "android_ndk_compat_symbols",
    ],
    min_sdk_version: "Tiramisu",
    // The no_std version of libbinder_rs is enabled in a mode that
    // allows testing the no_std support of the lib and rust AIDL
    // backend. This currently has shared lib deps and enables kernel binder,
    // both of which are unlikely to work for targets that require no_std support.
    // As of the time of this writing, such targets are not using soong to build
    // binder so this is not a concerrn.
    no_std: {
        enabled: true,
        features: [
            "android_ndk_compat_symbols",
            // Needed for testing no_std on Android where
            // most meaningful integration tests are using
            // kernel binder and service manager for service discovery.
            "kernel_ipc",
        ],
        cfgs: [
            "single_threaded",
        ],
        rustlibs: [
            "libbinder_ndk_sys",
            "libbinder_rs_ndk_compat",
            "libdowncast_rs_nostd",
            "liblibc",
            "liblog_rust",
            "libspin",
            "libstatic_assertions",
            "libzerocopy",
        ],
    },
}

rust_library {
    name: "libbinder_rs_on_trusty_mock",
    crate_name: "binder",
    srcs: ["src/lib.rs"],
    cfgs: [
        "trusty",
    ],
    features: [
        "std",
    ],
    rustlibs: [
        "libbinder_ndk_sys_on_trusty_mock",
        "libdowncast_rs",
        "liblibc",
        "libbinder_rs_ndk_compat",
        "libstatic_assertions",
        "libzerocopy",
    ],
    vendor: true,
}

rust_library {
    name: "libbinder_tokio_rs",
    crate_name: "binder_tokio",
    srcs: ["binder_tokio/lib.rs"],
    rustlibs: [
        "libbinder_rs",
        "libtokio",
    ],
    host_supported: true,
    vendor_available: true,
    product_available: true,
    target: {
        darwin: {
            enabled: false,
        },
    },
    apex_available: [
        "//apex_available:platform",
        "//apex_available:anyapex",
    ],
    min_sdk_version: "Tiramisu",
}

rust_library {
    name: "libbinder_ndk_sys",
    crate_name: "binder_ndk_sys",
    srcs: [
        "sys/lib.rs",
        ":libbinder_ndk_bindgen",
    ],
    shared_libs: [
        "libbinder_ndk",
    ],
    rustlibs: [
        "liblibc",
    ],
    host_supported: true,
    vendor_available: true,
    product_available: true,
    recovery_available: true,
    target: {
        darwin: {
            enabled: false,
        },
    },
    apex_available: [
        "//apex_available:platform",
        "//apex_available:anyapex",
    ],
    min_sdk_version: "Tiramisu",
    features: [
        "std",
    ],
    lints: "none",
    clippy_lints: "none",
    visibility: [":__subpackages__"],
    no_std: {
        enabled: true,
        features: [],
    },
}

rust_library {
    name: "libbinder_ndk_sys_on_trusty_mock",
    crate_name: "binder_ndk_sys",
    srcs: [
        "sys/lib.rs",
        ":libbinder_ndk_bindgen_on_trusty_mock",
    ],
    cfgs: [
        "trusty",
    ],
    shared_libs: [
        "libbinder_ndk_on_trusty_mock",
    ],
    vendor: true,
    // Lints are checked separately for libbinder_ndk_sys.
    // The Trusty mock copy pulls in extra headers that
    // don't pass the lints for the bindgen output.
    lints: "none",
}

rust_defaults {
    name: "libbinder_ndk_bindgen_defaults",
    wrapper_src: "sys/BinderBindings.hpp",
    source_stem: "bindings",
    bindgen_flag_files: [
        // Unfortunately the only way to specify the rust_non_exhaustive enum
        // style for a type is to make it the default
        // and then specify constified enums for the enums we don't want
        // rustified
        "libbinder_ndk_bindgen_flags.txt",
    ],
    bindgen_flags: [
        "--blocklist-type",
        "sockaddr",
        "--raw-line",
        "use libc::sockaddr;",
        "--blocklist-item",
        "AIBinder_Class_setTransactionCodeToFunctionNameMap",
        "--blocklist-item",
        "AIBinder_Class_getFunctionName",
        // Generate code compatible with `no_std` environments by using `core`
        // instead of `std` and referencing C types via `core::ffi`.
        "--use-core",
        "--ctypes-prefix",
        "::core::ffi",
    ],
    cflags: [
        "-DANDROID_PLATFORM",
    ],
}

rust_bindgen {
    name: "libbinder_ndk_bindgen",
    crate_name: "binder_ndk_bindgen",
    defaults: [
        "libbinder_ndk_bindgen_defaults",
    ],
    shared_libs: [
        "libbinder_ndk",
    ],
    rustlibs: [
        "liblibc",
    ],
    host_supported: true,
    vendor_available: true,
    product_available: true,
    recovery_available: true,

    // Currently necessary for host builds
    // TODO(b/31559095): bionic on host should define this
    target: {
        darwin: {
            enabled: false,
        },
    },
    apex_available: [
        "//apex_available:platform",
        "//apex_available:anyapex",
    ],
    min_sdk_version: "Tiramisu",
}

rust_bindgen {
    name: "libbinder_ndk_bindgen_on_trusty_mock",
    crate_name: "binder_ndk_bindgen",
    wrapper_src: "sys/BinderBindings.hpp",
    source_stem: "bindings",
    defaults: [
        "trusty_mock_defaults",
    ],

    bindgen_flag_files: [
        // Unfortunately the only way to specify the rust_non_exhaustive enum
        // style for a type is to make it the default
        // and then specify constified enums for the enums we don't want
        // rustified
        "libbinder_ndk_bindgen_flags.txt",
    ],
    cflags: [
        "-DANDROID_PLATFORM",
    ],
    shared_libs: [
        "libbinder_ndk_on_trusty_mock",
        "libc++",
    ],
}

rust_test {
    name: "libbinder_rs-internal_test",
    crate_name: "binder",
    srcs: ["src/lib.rs"],
    test_suites: ["general-tests"],
    auto_gen_config: true,
    shared_libs: [
        "libbinder_ndk",
    ],
    features: [
        "std",
        "kernel_ipc",
    ],
    rustlibs: [
        "libbinder_ndk_sys",
        "libdowncast_rs",
        "liblibc",
        "liblog_rust",
        "libstatic_assertions",
        "libzerocopy",
        "libbinder_rs_ndk_compat",
    ],
}

rust_test {
    name: "libbinder_rs_nostd-internal_test",
    crate_name: "binder",
    srcs: ["src/lib.rs"],
    test_suites: ["general-tests"],
    cfgs: [
        "single_threaded",
    ],
    rustlibs: [
        "libdowncast_rs_nostd",
        "liblog_rust_nostd",
        "libspin_nostd",
    ],
    no_std_rlibs: [
        "libbinder_ndk_sys",
        "libstatic_assertions",
        "libzerocopy",
        "liblibc",
    ],
}

rust_test {
    name: "libbinder_ndk_bindgen_test",
    srcs: [":libbinder_ndk_bindgen"],
    crate_name: "binder_ndk_bindgen",
    test_suites: ["general-tests"],
    auto_gen_config: true,
    clippy_lints: "none",
    lints: "none",
    rustlibs: [
        "liblibc",
    ],
}