From 026a2f18e25d98328b9166ce5a88a8fe3f6a2c53 Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Thu, 9 Jan 2025 18:47:46 +0100 Subject: [PATCH] napi: Move napi_env and napi_value to opaque_types. Internal change to prepare for the arkui native node napi bindings Signed-off-by: Jonathan Schwender --- components/opaque-types/src/opaque_types.rs | 10 ++++++++++ components/opaque-types/wrapper.h | 1 + scripts/generator/src/main.rs | 1 + scripts/generator/src/opaque_types.rs | 6 +++++- src/napi/napi_ffi.rs | 12 +----------- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/components/opaque-types/src/opaque_types.rs b/components/opaque-types/src/opaque_types.rs index 026094b..d2cb183 100644 --- a/components/opaque-types/src/opaque_types.rs +++ b/components/opaque-types/src/opaque_types.rs @@ -4,6 +4,16 @@ #![allow(non_camel_case_types)] #![allow(non_snake_case)] +#[repr(C)] +pub struct napi_env__ { + _unused: [u8; 0], +} +pub type napi_env = *mut napi_env__; +#[repr(C)] +pub struct napi_value__ { + _unused: [u8; 0], +} +pub type napi_value = *mut napi_value__; #[repr(C)] pub struct OH_NativeBuffer { _unused: [u8; 0], diff --git a/components/opaque-types/wrapper.h b/components/opaque-types/wrapper.h index 6179698..1e11c43 100644 --- a/components/opaque-types/wrapper.h +++ b/components/opaque-types/wrapper.h @@ -1,3 +1,4 @@ +#include "napi/native_api.h" #include "native_buffer/native_buffer.h" #include "multimedia/image_framework/image/pixelmap_native.h" #include "multimedia/image_framework/image_pixel_map_mdk.h" diff --git a/scripts/generator/src/main.rs b/scripts/generator/src/main.rs index 325070b..422e2be 100644 --- a/scripts/generator/src/main.rs +++ b/scripts/generator/src/main.rs @@ -258,6 +258,7 @@ fn get_bindings_config(api_version: u32) -> Vec { .no_copy("napi_extended_error_info") .no_copy("napi_node_version") .no_copy("napi_module") + .raw_line("pub use ohos_sys_opaque_types::{napi_env, napi_value};") }), }, BindingConf { diff --git a/scripts/generator/src/opaque_types.rs b/scripts/generator/src/opaque_types.rs index 67c3ef6..a8d409a 100644 --- a/scripts/generator/src/opaque_types.rs +++ b/scripts/generator/src/opaque_types.rs @@ -1,4 +1,4 @@ -pub(crate) static OPAQUE_TYPES: [&str; 9] = [ +pub(crate) static OPAQUE_TYPES: [&str; 13] = [ "OH_PixelmapNative", "NativePixelMap_", "OH_NativeBuffer", @@ -8,4 +8,8 @@ pub(crate) static OPAQUE_TYPES: [&str; 9] = [ "OHNativeWindowBuffer", "ArkUI_AccessibilityProvider", "OH_NativeColorSpaceManager", + "napi_env", + "napi_env__", + "napi_value", + "napi_value__", ]; \ No newline at end of file diff --git a/src/napi/napi_ffi.rs b/src/napi/napi_ffi.rs index 1f07beb..64da977 100644 --- a/src/napi/napi_ffi.rs +++ b/src/napi/napi_ffi.rs @@ -3,6 +3,7 @@ #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] +pub use ohos_sys_opaque_types::{napi_env, napi_value}; pub const NAPI_VERSION: u32 = 8; pub const NAPI_VERSION_EXPERIMENTAL: u32 = 2147483647; @@ -82,16 +83,6 @@ impl napi_task_priority { pub struct napi_task_priority(pub ::core::ffi::c_uint); pub type char16_t = u16; #[repr(C)] -pub struct napi_env__ { - _unused: [u8; 0], -} -pub type napi_env = *mut napi_env__; -#[repr(C)] -pub struct napi_value__ { - _unused: [u8; 0], -} -pub type napi_value = *mut napi_value__; -#[repr(C)] pub struct napi_ref__ { _unused: [u8; 0], } @@ -298,7 +289,6 @@ pub type napi_finalize = ::core::option::Option< ), >; #[repr(C)] -#[derive(Debug)] pub struct napi_property_descriptor { pub utf8name: *const ::core::ffi::c_char, pub name: napi_value,