napi_sys_dev/
lib.rs

1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4
5include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
6
7#[macro_export]
8macro_rules! register_module {
9    ($module_name:ident, $init:ident) => {
10        #[no_mangle]
11        #[cfg_attr(target_os = "linux", link_section = ".ctors")]
12        #[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")]
13        #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")]
14        pub static __REGISTER_MODULE: extern "C" fn() = {
15            use std::io::Write;
16            use std::os::raw::c_char;
17            use std::ptr;
18            use napi_sys_dev::*;
19            // use $crate::*;
20
21            extern "C" fn register_module() {
22                static mut MODULE_DESCRIPTOR: Option<napi_module> = None;
23                unsafe {
24                    MODULE_DESCRIPTOR = Some(napi_module {
25                        nm_version: 1,
26                        nm_flags: 0,
27                        nm_filename: concat!(file!(), "\0").as_ptr() as *const c_char,
28                        nm_register_func: Some($init),
29                        nm_modname: concat!(stringify!($module_name), "\0").as_ptr() as *const c_char,
30                        nm_priv: 0 as *mut _,
31                        reserved: [0 as *mut _; 4],
32                    });
33                    napi_module_register(MODULE_DESCRIPTOR.as_mut().unwrap() as *mut napi_module);
34                }
35            }
36
37            register_module
38        };
39    };
40}