diff options
author | Marcin Radomski <dextero@google.com> | 2024-03-05 11:22:56 +0000 |
---|---|---|
committer | Marcin Radomski <dextero@google.com> | 2024-03-18 18:48:46 +0000 |
commit | 65742c01dd3a6f879fe0f0617e4720a869a16aba (patch) | |
tree | 98337bc123e1f072a9b70bc1f4b2707c68b13e55 | |
parent | 66c52b3f63a2f45b90aa790e11290f5dd614e262 (diff) | |
download | minigbm-65742c01dd3a6f879fe0f0617e4720a869a16aba.tar.gz |
This provides the bindings necessary to use the Rust gbm crate within
Android source tree. Bindgen flags used in the rust_bindgen definition,
as well as the workaround described in wrapper.h were based on upstream
gbm-sys crate's build.rs [1].
Looking at other rust_bindgen modules, they are generally defined
alongside the native module they provide bindings to.
Details: go/drm-gbm-rust-crates-for-android
[1] https://github.com/Smithay/gbm.rs/blob/606c4260e0147256fb5c2901bbe837c0dc7d9f2d/gbm-sys/build.rs#L78
Bug: b/328181805
Test: lunch aosp_cf_x86_64_only_phone-trunk_staging-userdebug && m
Test: m libgbm_sys
Change-Id: I3065f7fe35f4a86b72ac90c34476da6304155daf
-rw-r--r-- | Android.bp | 31 | ||||
-rw-r--r-- | rust/gbm_wrapper.h | 28 |
2 files changed, 57 insertions, 2 deletions
@@ -163,7 +163,7 @@ cc_library { android: { shared_libs: [ "libcutils", - "liblog" + "liblog", ], static_libs: [ "libdrm", @@ -172,13 +172,40 @@ cc_library { }, apex_available: [ "//apex_available:platform", - "com.android.virt", + "//apex_available:anyapex", ], vendor_available: true, + product_available: true, export_include_dirs: ["."], } +// Rust bindings to minigbm, generated in a way compatible with gbm crate. +rust_bindgen { + name: "libgbm_sys", + crate_name: "gbm_sys", + wrapper_src: "rust/gbm_wrapper.h", + source_stem: "bindings", + bindgen_flags: [ + "--blocklist-type=__BINDGEN_TMP_.*", + "--allowlist-type=^gbm_.*$", + "--allowlist-function=^gbm_.*$", + "--allowlist-var=GBM_.*|gbm_.*$", + "--constified-enum-module=^gbm_.*$", + ], + shared_libs: ["libgbm"], + host_supported: true, + vendor_available: true, + product_available: true, + apex_available: [ + "//apex_available:anyapex", + "//apex_available:platform", + ], + visibility: [ + "//external/rust/crates/gbm", + ], +} + // Generic cc_library_shared { name: "libminigbm_gralloc", diff --git a/rust/gbm_wrapper.h b/rust/gbm_wrapper.h new file mode 100644 index 0000000..abcf3af --- /dev/null +++ b/rust/gbm_wrapper.h @@ -0,0 +1,28 @@ +/* + * Copyright 2024 Google LLC + */ + +#include <gbm.h> + +// bindgen doesn't create constants for macros that expand to other macros +// https://github.com/Smithay/gbm.rs/blob/606c4260e0147256fb5c2901bbe837c0dc7d9f2d/gbm-sys/build.rs#L16 + +const unsigned int __BINDGEN_TMP_GBM_BO_IMPORT_WL_BUFFER = GBM_BO_IMPORT_WL_BUFFER; +#undef GBM_BO_IMPORT_WL_BUFFER +const unsigned int GBM_BO_IMPORT_WL_BUFFER = __BINDGEN_TMP_GBM_BO_IMPORT_WL_BUFFER; +#define GBM_BO_IMPORT_WL_BUFFER GBM_BO_IMPORT_WL_BUFFER + +const unsigned int __BINDGEN_TMP_GBM_BO_IMPORT_EGL_IMAGE = GBM_BO_IMPORT_EGL_IMAGE; +#undef GBM_BO_IMPORT_EGL_IMAGE +const unsigned int GBM_BO_IMPORT_EGL_IMAGE = __BINDGEN_TMP_GBM_BO_IMPORT_EGL_IMAGE; +#define GBM_BO_IMPORT_EGL_IMAGE GBM_BO_IMPORT_EGL_IMAGE + +const unsigned int __BINDGEN_TMP_GBM_BO_IMPORT_FD = GBM_BO_IMPORT_FD; +#undef GBM_BO_IMPORT_FD +const unsigned int GBM_BO_IMPORT_FD = __BINDGEN_TMP_GBM_BO_IMPORT_FD; +#define GBM_BO_IMPORT_FD GBM_BO_IMPORT_FD + +const unsigned int __BINDGEN_TMP_GBM_BO_IMPORT_FD_MODIFIER = GBM_BO_IMPORT_FD_MODIFIER; +#undef GBM_BO_IMPORT_FD_MODIFIER +const unsigned int GBM_BO_IMPORT_FD_MODIFIER = __BINDGEN_TMP_GBM_BO_IMPORT_FD_MODIFIER; +#define GBM_BO_IMPORT_FD_MODIFIER GBM_BO_IMPORT_FD_MODIFIER |