tirbofish/dropbear · commit
1eeec37e50fcd1df2d1bd03a24d98fb31eabf756
jarvis, run github actions. i made some more changes... nothing works i hate this so fucking much
Signature present but could not be verified.
Unverified
@@ -100,16 +100,20 @@ jobs: - name: Prepare artifact run: | - mkdir dist + mkdir -p dist/libs cp target/${{ matrix.target }}/release/eucalyptus-editor${{ matrix.ext }} dist/ - - # Copy any library files from target/release + if [ "${{ matrix.os }}" = "windows-latest" ]; then - cp target/${{ matrix.target }}/release/*.dll dist/ 2>/dev/null || true + # Copy Windows native libs and import library + cp target/${{ matrix.target }}/release/eucalyptus_core.dll dist/ 2>/dev/null || true + cp target/${{ matrix.target }}/release/eucalyptus_core.dll dist/libs/ 2>/dev/null || true + cp target/${{ matrix.target }}/release/eucalyptus_core.dll.lib dist/libs/ 2>/dev/null || true elif [ "${{ matrix.os }}" = "ubuntu-latest" ]; then - cp target/${{ matrix.target }}/release/*.so* dist/ 2>/dev/null || true + cp target/${{ matrix.target }}/release/libeucalyptus_core.so dist/ 2>/dev/null || true + cp target/${{ matrix.target }}/release/libeucalyptus_core.so dist/libs/ 2>/dev/null || true elif [ "${{ matrix.os }}" = "macos-latest" ]; then - cp target/${{ matrix.target }}/release/*.dylib dist/ 2>/dev/null || true + cp target/${{ matrix.target }}/release/libeucalyptus_core.dylib dist/ 2>/dev/null || true + cp target/${{ matrix.target }}/release/libeucalyptus_core.dylib dist/libs/ 2>/dev/null || true cp README.md dist/ fi shell: bash @@ -1,5 +1,6 @@ <component name="ProjectRunConfigurationManager"> <configuration default="false" name="Build eucalyptus_core cdylib" type="CargoCommandRunConfiguration" factoryName="Cargo Command"> + <option name="buildProfileId" value="release" /> <option name="command" value="build -p eucalyptus-core --features "editor"" /> <option name="workingDirectory" value="file://$PROJECT_DIR$" /> <envs /> @@ -469,7 +469,7 @@ impl App { #[cfg(not(target_os = "android"))] { - Builder::new() + let _ = Builder::new() .format(move |buf, record| { let ts = Local::now().format("%Y-%m-%dT%H:%M:%S"); @@ -520,7 +520,7 @@ impl App { LevelFilter::Debug, ) .filter(Some("eucalyptus_core"), LevelFilter::Debug) - .init(); + .try_init(); // setup panic panic::set_hook(); @@ -37,8 +37,11 @@ rfd = { workspace = true, optional = true } [features] # editor only stuff -editor = ["jvm", "rfd"] +editor = ["jvm", "rfd", "jvm_debug"] +# enabled scripttarget::jvm as an option jvm = [] +# enables jdb +jvm_debug = ["jvm"] [build-dependencies] anyhow = "1.0" @@ -4,4 +4,11 @@ The core libraries of the eucalyptus editor. Great for embedding into `redback-r This is a library, so if tools are wished to be made, this is the perfect library for you. -it also produces a shared library for Kotlin/Native and the JVM :) +it also produces a shared library for Kotlin/Native and the JVM :) + +## Features + +- `editor` - Enables editor only features that the redback-runtime would not be able to access +- `jvm` - Enables the JVM as a ScriptTarget and running the Java Virtual Machine (not possible with non-desktop targets) +- `jvm_debug` - Enables debugging of the JVM through the java debugger. Can pose a risk to tampering, so is disabled by default unless + want to be enabled by developer or enabled by default by the `editor` feature. @@ -81,14 +81,36 @@ impl JavaContext { .version(JNIVersion::V8) .option(format!("-Djava.class.path={}", host_jar_path.display())); - #[cfg(feature = "editor")] + #[cfg(feature = "jvm_debug")] let jvm_args = jvm_args.option("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:6741"); + #[cfg(all(feature = "jvm", not(feature = "editor")))] + let jvm_args = { + #[allow(unused)] + let pathbuf = std::env::current_exe()?; + #[allow(unused)] + let path = pathbuf + .parent() + .ok_or_else(|| anyhow::anyhow!("Unable to locate parent"))?; + + println!("Libs folder at {}", path.display()); + + if !path.exists() { + log::warn!( + "Libs folder ({}) does not exist; native libraries may fail to load", + path.display() + ); + } + + let path_str = path.to_string_lossy(); + jvm_args.option(format!("-Djava.library.path={}", path_str)) + }; + let jvm_args = jvm_args.build()?; let jvm = JavaVM::new(jvm_args)?; - #[cfg(feature = "editor")] + #[cfg(feature = "jvm_debug")] crate::success!("JDB debugger enabled on localhost:6741"); log::info!("Created JVM instance"); @@ -72,7 +72,7 @@ pub fn Java_com_dropbear_ffi_JNINative_getEntity( return id.id() as jlong; } } - -1 + 0 } /// `JNIEXPORT jobject JNICALL Java_com_dropbear_ffi_JNINative_getTransform @@ -41,6 +41,9 @@ open.workspace = true rustc_version_runtime.workspace = true egui_plot.workspace = true memory-stats.workspace = true +env_logger.workspace = true +colored.workspace = true +chrono.workspace = true [target.'cfg(not(target_os = "android"))'.dependencies] rfd.workspace = true @@ -18,6 +18,89 @@ async fn main() -> anyhow::Result<()> { to use with dependencies or create your own game on Desktop. Sorry :(" ); + #[cfg(not(target_os = "android"))] + { + use std::fs::OpenOptions; + use colored::Colorize; + use env_logger::Builder; + use log::LevelFilter; + + let log_dir = app_dirs2::app_root(app_dirs2::AppDataType::UserData, &eucalyptus_core::APP_INFO) + .expect("Failed to get app data directory") + .join("logs"); + std::fs::create_dir_all(&log_dir).expect("Failed to create log dir"); + + let datetime_str = chrono::offset::Local::now().format("%Y-%m-%d_%H-%M-%S"); + let log_filename = format!("{}.{}.log", "eucalyptus-editor", datetime_str); + let log_path = log_dir.join(log_filename); + + let file = OpenOptions::new() + .create(true) + .append(true) + .open(&log_path) + .expect("Failed to open log file"); + let file = parking_lot::Mutex::new(file); + + let app_target = "eucalyptus-editor".replace('-', "_"); + let log_config = format!("dropbear_engine=trace,{}=debug,warn", app_target); + unsafe { std::env::set_var("RUST_LOG", log_config) }; + + Builder::new() + .format(move |buf, record| { + use std::io::Write; + + let ts = chrono::offset::Local::now().format("%Y-%m-%dT%H:%M:%S"); + + let colored_level = match record.level() { + log::Level::Error => record.level().to_string().red().bold(), + log::Level::Warn => record.level().to_string().yellow().bold(), + log::Level::Info => record.level().to_string().green().bold(), + log::Level::Debug => record.level().to_string().blue().bold(), + log::Level::Trace => record.level().to_string().cyan().bold(), + }; + + let colored_timestamp = ts.to_string().bright_black(); + + let file_info = format!( + "{}:{}", + record.file().unwrap_or("unknown"), + record.line().unwrap_or(0) + ) + .bright_black(); + + let console_line = format!( + "{} {} [{}] - {}\n", + file_info, + colored_timestamp, + colored_level, + record.args() + ); + + let file_line = format!( + "{}:{} {} [{}] - {}\n", + record.file().unwrap_or("unknown"), + record.line().unwrap_or(0), + ts, + record.level(), + record.args() + ); + + write!(buf, "{}", console_line)?; + + let mut fh = file.lock(); + let _ = fh.write_all(file_line.as_bytes()); + + Ok(()) + }) + .filter(Some("dropbear_engine"), LevelFilter::Trace) + .filter( + Some("eucalyptus-editor".replace('-', "_").as_str()), + LevelFilter::Debug, + ) + .filter(Some("eucalyptus_core"), LevelFilter::Debug) + .init(); + } + dropbear_engine::panic::set_hook(); let matches = Command::new("eucalyptus-editor") .about("A visual game editor") @@ -68,6 +68,8 @@ actual class NativeEngine { } else { null } + } else if (result == 0L) { + null } else { result }