android-binder 0.2.2

Safe bindings to Android Binder, restricted to the NDK
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"],
}

rust_test {
    name: "rustBinderTest",
    srcs: ["integration.rs"],
    rustlibs: [
        "libbinder_rs",
        "libselinux_bindgen",
        "libbinder_tokio_rs",
        "libtokio",
        "libzerocopy",
    ],
    shared_libs: [
        "libselinux",
    ],
    data: [
        ":rustBinderTestService",
    ],
    test_suites: ["general-tests"],
}

rust_test {
    name: "rustBinderTestService",
    srcs: ["integration.rs"],
    rustlibs: [
        "libbinder_rs",
        "liblibc",
        "libzerocopy",
    ],
    test_harness: false,
    auto_gen_config: false,
}

cc_test {
    name: "binderRustNdkInteropTest",
    srcs: [
        "binderRustNdkInteropTest.cpp",
    ],
    shared_libs: [
        "libbinder",
        "libbinder_ndk",
    ],
    static_libs: [
        "IBinderRustNdkInteropTest-ndk",
        "libbinder_ndk_rust_interop",
    ],
    test_suites: ["general-tests"],
    require_root: true,

    // rustBinderTestService uses a custom config
    auto_gen_config: true,
}

aidl_interface {
    name: "IBinderRustNdkInteropTest",
    unstable: true,
    srcs: [
        "IBinderRustNdkInteropTest.aidl",
        "IBinderRustNdkInteropTestOther.aidl",
    ],
    backend: {
        ndk: {
            enabled: true,
        },
        rust: {
            enabled: true,
        },
    },
}

rust_ffi_static {
    name: "libbinder_ndk_rust_interop",
    crate_name: "binder_ndk_rust_interop",
    srcs: [
        "ndk_rust_interop.rs",
    ],
    rustlibs: [
        "libbinder_rs",
        "libbinder_rs_ndk_compat",
        "IBinderRustNdkInteropTest-rust",
    ],
}

cc_defaults {
    name: "rustBinderSerializationTest_defaults",
    shared_libs: [
        "libbinder",
        "libbinder_ndk",
        "libutils",
        "libbase",
    ],
    srcs: [
        "serialization.cpp",
    ],
    auto_gen_config: true,
    test_suites: ["general-tests"],
}

cc_test {
    name: "rustBinderSerializationTest",
    defaults: ["rustBinderSerializationTest_defaults"],
    static_libs: [
        "libbinder_rs_serialization_test",
    ],
}

rust_bindgen {
    name: "libbinder_rs_serialization_bindgen",
    crate_name: "binder_rs_serialization_bindgen",
    wrapper_src: "serialization.hpp",
    source_stem: "bindings",
    bindgen_flags: [
        "--allowlist-type",
        "Transaction",
        "--allowlist-var",
        "TESTDATA_.*",
    ],

    shared_libs: [
        "libbinder",
        "libc++",
    ],
}

rust_ffi_static {
    name: "libbinder_rs_serialization_test",
    crate_name: "binder_rs_serialization_test",
    srcs: [
        "serialization.rs",
        ":libbinder_rs_serialization_bindgen",
    ],
    rustlibs: [
        "libbinder_rs",
    ],
}

// The following rules add tests that link against libbinder_rs_nostd.
// The binaries and tests themselves still link against std.
rust_ffi_static {
    name: "libbinder_rs_nostd_serialization_test",
    crate_name: "binder_rs_nostd_serialization_test",
    srcs: [
        "serialization.rs",
        ":libbinder_rs_serialization_bindgen",
    ],
    // TODO: b/425915863 - change to no_std_rlibs once libbinder_rs_nostd is actually no_std
    rlibs: [
        "libbinder_rs_nostd",
    ],
}

cc_test {
    name: "rustBinderNoStdSerializationTest",
    defaults: ["rustBinderSerializationTest_defaults"],
    static_libs: [
        "libbinder_rs_nostd_serialization_test",
    ],
}