This commit is contained in:
griffi-gh 2024-09-01 20:20:51 +02:00
parent 2849c11621
commit 518b2c3e79
3 changed files with 20 additions and 5 deletions

View file

@ -51,6 +51,7 @@ winapi = { version = "0.3", features = ["wincon"] }
default = ["raw-evt-mouse"] default = ["raw-evt-mouse"]
raw-evt-keyboard = [] # use raw input for keyboard. works on x11 and windows, breaks keyboard on android and wayland raw-evt-keyboard = [] # use raw input for keyboard. works on x11 and windows, breaks keyboard on android and wayland
raw-evt-mouse = [] # required for mouse input raw-evt-mouse = [] # required for mouse input
c-ffi = [] # generate a C-ffi-compatible `kubi_main` entry point (useful if building as a shared library)
generate_visualizer_data = ["dep:serde_json", "shipyard/serde1"] generate_visualizer_data = ["dep:serde_json", "shipyard/serde1"]
safe_lz4 = ["lz4_flex/safe-encode", "lz4_flex/safe-decode"] safe_lz4 = ["lz4_flex/safe-encode", "lz4_flex/safe-decode"]
parallel = ["shipyard/parallel"] # causes some serious issues! parallel = ["shipyard/parallel"] # causes some serious issues!

View file

@ -189,16 +189,30 @@ fn attach_console() {
unsafe { AttachConsole(ATTACH_PARENT_PROCESS); } unsafe { AttachConsole(ATTACH_PARENT_PROCESS); }
} }
#[unsafe(no_mangle)]
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
#[unsafe(no_mangle)]
pub fn android_main(app: android_activity::AndroidApp) { pub fn android_main(app: android_activity::AndroidApp) {
use android_activity::WindowManagerFlags; use android_activity::WindowManagerFlags;
app.set_window_flags(WindowManagerFlags::FULLSCREEN, WindowManagerFlags::empty()); app.set_window_flags(WindowManagerFlags::FULLSCREEN, WindowManagerFlags::empty());
kubi_main(app) kubi_main_impl(app);
} }
#[cfg(feature = "c-ffi")]
#[cfg(not(target_os = "android"))]
#[unsafe(no_mangle)] #[unsafe(no_mangle)]
pub fn kubi_main( pub extern "C" fn kubi_main() {
// cant let unwinds cross the ffi boundary!
// also, hopefully this code should never panic either...
let panic = std::panic::catch_unwind(|| {
kubi_main_impl();
});
if panic.is_err() {
println!("!!! PANIC CAUGHT ON FFI BOUNDARY !!!");
};
std::mem::forget(panic); // forget the result, as dropping it will cause unwinding!
}
pub fn kubi_main_impl(
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
app: android_activity::AndroidApp app: android_activity::AndroidApp
) { ) {

View file

@ -1,8 +1,8 @@
#![cfg_attr( #![cfg_attr(
all(windows, not(debug_assertions)), all(windows, not(debug_assertions)),
windows_subsystem = "windows" windows_subsystem = "windows"
)] )]
fn main() { fn main() {
kubilib::kubi_main(); kubilib::kubi_main_impl();
} }