refactor(napi): module register logic
This commit is contained in:
parent
283a4aaab9
commit
826ebd9847
1 changed files with 69 additions and 76 deletions
|
@ -154,11 +154,8 @@ macro_rules! register_module {
|
|||
_ => Err(Error::from_status(status)),
|
||||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
#[cfg_attr(target_os = "linux", link_section = ".ctors")]
|
||||
#[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")]
|
||||
#[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")]
|
||||
pub static __REGISTER_MODULE: extern "C" fn() = {
|
||||
|
||||
extern "C" fn register_module() {
|
||||
use std::ffi::CString;
|
||||
use std::io::Write;
|
||||
use std::os::raw::c_char;
|
||||
|
@ -167,15 +164,13 @@ macro_rules! register_module {
|
|||
|
||||
#[cfg(all(feature = "tokio_rt", napi4))]
|
||||
use $crate::shutdown_tokio_rt;
|
||||
|
||||
extern "C" fn register_module() {
|
||||
static mut MODULE_DESCRIPTOR: Option<sys::napi_module> = None;
|
||||
unsafe {
|
||||
MODULE_DESCRIPTOR = Some(sys::napi_module {
|
||||
nm_version: 1,
|
||||
nm_flags: 0,
|
||||
nm_filename: concat!(file!(), "\0").as_ptr() as *const c_char,
|
||||
nm_register_func: Some(init_module),
|
||||
nm_register_func: Some(napi_register_module_v1),
|
||||
nm_modname: concat!(stringify!($module_name), "\0").as_ptr() as *const c_char,
|
||||
nm_priv: 0 as *mut _,
|
||||
reserved: [0 as *mut _; 4],
|
||||
|
@ -184,7 +179,8 @@ macro_rules! register_module {
|
|||
sys::napi_module_register(MODULE_DESCRIPTOR.as_mut().unwrap() as *mut sys::napi_module);
|
||||
}
|
||||
|
||||
extern "C" fn init_module(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn napi_register_module_v1(
|
||||
raw_env: sys::napi_env,
|
||||
raw_exports: sys::napi_value,
|
||||
) -> sys::napi_value {
|
||||
|
@ -217,8 +213,5 @@ macro_rules! register_module {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
register_module
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue