Create a Rust wrapper for vm_payload
And use it in place of directly calling the bindgen-generated
interface in our current clients.
Bug: 340857915
Test: atest VmAttestationTestApp
composd_cmd test-compile
Change-Id: I51f1c1ab6a4dce09d9160731aacd83ebb9c0ce07
diff --git a/vm_payload/Android.bp b/vm_payload/Android.bp
index 229f533..cf2a002 100644
--- a/vm_payload/Android.bp
+++ b/vm_payload/Android.bp
@@ -39,8 +39,8 @@
visibility: [":__subpackages__"],
}
-// Rust wrappers round the C API for Rust clients.
-// (Yes, this involves going Rust -> C -> Rust.)
+// Access to the C API for Rust code.
+// This shouldn't be used directly - prefer libvm_payload_rs (below)
rust_bindgen {
name: "libvm_payload_bindgen",
wrapper_src: "include-restricted/vm_payload_restricted.h",
@@ -51,15 +51,31 @@
bindgen_flags: [
"--default-enum-style rust",
],
- visibility: [
- "//packages/modules/Virtualization/compos",
- "//packages/modules/Virtualization/service_vm:__subpackages__",
- ],
shared_libs: [
"libvm_payload#current",
],
}
+// Wrapper library for the raw C API for use by Rust clients.
+// (Yes, this involves going Rust -> C -> Rust.)
+// This is not a stable API - we may change it in subsequent versions.
+// But it is made available as an rlib so it is linked into any
+// code using it, leaving only dependencies on stable APIs.
+// So code built with it should run unchanged on future versions.
+rust_library_rlib {
+ name: "libvm_payload_rs",
+ crate_name: "vm_payload",
+ defaults: ["avf_build_flags_rust"],
+ srcs: ["wrapper/lib.rs"],
+ rustlibs: [
+ "libbinder_rs",
+ "libstatic_assertions",
+ "libvm_payload_bindgen",
+ ],
+ apex_available: ["com.android.compos"],
+ visibility: ["//visibility:public"],
+}
+
// Shared library for clients to link against.
cc_library_shared {
name: "libvm_payload",