Skip to main content

tsnative/
lib.rs

1//! ts-native 库入口
2//! 提供 DLL 导出接口供 loader 调用
3
4use std::sync::Once;
5
6static PANIC_HOOK_INIT: Once = Once::new();
7
8/// 初始化 panic hook(线程安全,只执行一次)
9pub fn init_panic_hook() {
10    PANIC_HOOK_INIT.call_once(|| {
11        std::panic::set_hook(Box::new(|info| {
12            eprintln!("\n=========== ts-native Library Panic ===========");
13            if let Some(s) = info.payload().downcast_ref::<&str>() {
14                eprintln!("Message: {}", s);
15            } else if let Some(s) = info.payload().downcast_ref::<String>() {
16                eprintln!("Message: {}", s);
17            } else {
18                eprintln!("Message: <unknown>");
19            }
20            if let Some(loc) = info.location() {
21                eprintln!("Location: {}:{}", loc.file(), loc.line());
22            }
23            eprintln!("--- Backtrace ---");
24            let bt = backtrace::Backtrace::new();
25            for frame in bt.frames().iter().take(20) {
26                for symbol in frame.symbols() {
27                    let name = symbol.name().map(|n| n.to_string()).unwrap_or_else(|| "<unknown>".to_string());
28                    let file = symbol.filename().and_then(|f| f.file_name()).and_then(|f| f.to_str()).unwrap_or("");
29                    let line = symbol.lineno().map(|l| l.to_string()).unwrap_or_else(|| "?".to_string());
30                    eprintln!("  {} ({}:{})", name, file, line);
31                }
32            }
33            eprintln!("=============================================\n");
34        }));
35    });
36}
37
38pub mod diag;
39pub mod codegen;
40pub mod coff;
41pub mod dep_graph;
42#[cfg(feature = "native-linker")]
43pub mod native_linker;
44pub mod project;
45pub mod project_compiler;
46pub mod standalone_gen;
47pub mod swc_transform;
48pub mod tsn_ffi;
49
50// 重新导出常用类型
51pub use tsn_ffi::{TsnCompileResult, TsnSymbol, TsnRelocation};