Introduced dylib extension format, cleared up shutdown sequence

This commit is contained in:
2026-01-17 00:23:35 +01:00
parent 1a7230ce9b
commit 6a3c1d5917
18 changed files with 214 additions and 113 deletions

View File

@@ -1,4 +1,5 @@
use orchid_base::logging::Logger;
use orchid_host::dylib::ext_dylib;
use tokio::time::Instant;
pub mod parse_folder;
@@ -9,7 +10,7 @@ use std::process::{Command, ExitCode};
use std::rc::Rc;
use async_fn_stream::try_stream;
use camino::Utf8PathBuf;
use camino::{Utf8Path, Utf8PathBuf};
use clap::{Parser, Subcommand};
use futures::future::LocalBoxFuture;
use futures::{FutureExt, Stream, TryStreamExt, io};
@@ -100,10 +101,32 @@ fn get_all_extensions<'a>(
args: &'a Args,
ctx: &'a Ctx,
) -> impl Stream<Item = io::Result<Extension>> + 'a {
fn not_found_error(ext_path: &Utf8Path) -> io::Error {
io::Error::new(
std::io::ErrorKind::NotFound,
format!("None of the file candidates for {ext_path} were found"),
)
}
try_stream(async |mut cx| {
for ext_path in args.extension.iter() {
let exe = if cfg!(windows) { ext_path.with_extension("exe") } else { ext_path.clone() };
let init = ext_command(Command::new(exe.as_os_str()), ctx.clone()).await?;
let init = if cfg!(windows) {
if ext_path.with_extension("dll").exists() {
let dylib =
ext_dylib(ext_path.with_extension("dll").as_std_path(), ctx.clone()).await.unwrap();
eprintln!("Loaded DLL {ext_path}.dll");
dylib
} else if ext_path.with_extension("exe").exists() {
ext_command(Command::new(ext_path.with_extension("exe").as_os_str()), ctx.clone()).await?
} else {
return Err(not_found_error(ext_path));
}
} else if ext_path.with_extension("so").exists() {
ext_dylib(ext_path.with_extension("so").as_std_path(), ctx.clone()).await.unwrap()
} else if ext_path.exists() {
ext_command(Command::new(ext_path.as_os_str()), ctx.clone()).await?
} else {
return Err(not_found_error(ext_path));
};
cx.emit(Extension::new(init, ctx.clone()).await?).await;
}
Ok(cx)