1use std::sync::Once;
5
6static PANIC_HOOK_INIT: Once = Once::new();
7
8pub 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
50pub use tsn_ffi::{TsnCompileResult, TsnSymbol, TsnRelocation};