qjs_sys/
lib.rs

1#![allow(non_camel_case_types)]
2#![allow(non_snake_case)]
3#![allow(non_upper_case_globals)]
4#![allow(clippy::unreadable_literal)]
5
6#[macro_use]
7extern crate cfg_if;
8#[macro_use]
9extern crate lazy_static;
10
11cfg_if! {
12    if #[cfg(feature = "gen")] {
13        include!(concat!(env!("OUT_DIR"), "/raw.rs"));
14    } else {
15        include!("raw.rs");
16    }
17}
18
19lazy_static! {
20    pub static ref VERSION: &'static str =
21        include_str!(concat!(env!("OUT_DIR"), "/VERSION")).trim();
22}
23
24cfg_if! {
25    if #[cfg(feature = "repl")] {
26        extern "C" {
27            #[no_mangle]
28            pub static repl: [u8; 0];
29
30            #[no_mangle]
31            pub static repl_size: u32;
32        }
33
34        lazy_static! {
35            pub static ref REPL: &'static [u8] = unsafe {
36                std::slice::from_raw_parts(repl.as_ptr(), repl_size as usize)
37            };
38        }
39    }
40}
41
42cfg_if! {
43    if #[cfg(feature = "qjscalc")] {
44        extern "C" {
45            #[no_mangle]
46            pub static qjscalc: [u8; 0];
47
48            #[no_mangle]
49            pub static qjscalc_size: u32;
50        }
51
52        lazy_static! {
53            pub static ref QJSCALC: &'static [u8] = unsafe {
54                std::slice::from_raw_parts(qjscalc.as_ptr(), qjscalc_size as usize)
55            };
56        }
57    }
58}
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63
64    #[test]
65    fn runtime() {
66        let rt = unsafe { JS_NewRuntime() };
67
68        assert!(!rt.is_null());
69
70        unsafe {
71            JS_FreeRuntime(rt);
72        }
73    }
74}