From 8d6753e1c2258e6d869d6ea1c6582e4dc8d71d83 Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Thu, 5 Dec 2024 22:09:47 +0100 Subject: [PATCH] Don't be so chatty --- Cargo.lock | 3 +++ dylo-cli/src/load_template.rs | 3 +-- dylo-cli/src/main.rs | 22 +++++++++++++++------ dylo-runtime/Cargo.toml | 6 +----- dylo-runtime/README.md | 2 +- dylo-runtime/src/details.rs | 36 +++++++++++++++++++++++++++++++++-- dylo/Cargo.toml | 5 +++++ 7 files changed, 61 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ac3fdd..197e204 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,6 +38,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "dylo" version = "1.0.0" +dependencies = [ + "rubicon", +] [[package]] name = "dylo-cli" diff --git a/dylo-cli/src/load_template.rs b/dylo-cli/src/load_template.rs index 479157b..df313a4 100644 --- a/dylo-cli/src/load_template.rs +++ b/dylo-cli/src/load_template.rs @@ -5,8 +5,7 @@ /// See pub fn load() -> &'static (dyn Mod) { static MOD: ::std::sync::LazyLock<&'static (dyn Mod)> = ::std::sync::LazyLock::new(|| { - let mod_name = stringify!($mod_name); - let fat_pointer = ::dylo_runtime::details::load_mod(mod_name); + let fat_pointer = ::dylo_runtime::details::load_mod(env!("CARGO_PKG_NAME")); unsafe { ::std::mem::transmute::<::dylo_runtime::details::AnyModRef, &'static dyn Mod>( fat_pointer, diff --git a/dylo-cli/src/main.rs b/dylo-cli/src/main.rs index 0639d00..3482305 100644 --- a/dylo-cli/src/main.rs +++ b/dylo-cli/src/main.rs @@ -39,21 +39,27 @@ enum ProcessReason { /// Discover all mods in the `./` directory, recursively fn list_mods(mods_dir: &camino::Utf8Path) -> std::io::Result> { let mut mods = Vec::new(); - for entry in fs_err::read_dir(mods_dir)? { + for entry in walkdir::WalkDir::new(mods_dir) { let entry = entry?; - let mod_path: Utf8PathBuf = entry.path().try_into().unwrap(); + let mod_path: Utf8PathBuf = entry.path().to_owned().try_into().unwrap(); if !mod_path.is_dir() { continue; } - let name = mod_path.file_name().unwrap().to_string(); + if !mod_path.join("Cargo.toml").exists() { + continue; + } + + let Some(name) = mod_path.file_name().map(|n| n.to_string()) else { + continue; + }; if !name.starts_with("mod-") { continue; } let name = name.trim_start_matches("mod-").to_string(); - let con_path = mods_dir.join(&name); + let con_path = mod_path.parent().unwrap().join(&name); // Check timestamps let mod_timestamp = get_latest_timestamp(&mod_path)?; @@ -447,8 +453,12 @@ fn process_mod(mod_info: ModInfo, force: bool) -> std::io::Result<()> { mod_info.name, duration.as_secs_f32() ); - tracing::error!("⛔ Exiting due to failed cargo check"); - std::process::exit(1); + if force { + tracing::warn!("⚠️ Continuing despite failed cargo check due to --force"); + } else { + tracing::error!("⛔ Exiting due to failed cargo check"); + std::process::exit(1); + } } } Ok(()) diff --git a/dylo-runtime/Cargo.toml b/dylo-runtime/Cargo.toml index 496ff4c..856463b 100644 --- a/dylo-runtime/Cargo.toml +++ b/dylo-runtime/Cargo.toml @@ -12,8 +12,4 @@ categories = ["development-tools"] rust-version = "1.83" [dependencies] -rubicon = { version = "3.4.9" } - -[features] -import-globals = ["rubicon/import-globals"] -export-globals = ["rubicon/export-globals"] +rubicon = "3.4.9" diff --git a/dylo-runtime/README.md b/dylo-runtime/README.md index b4f0249..41c20e4 100644 --- a/dylo-runtime/README.md +++ b/dylo-runtime/README.md @@ -19,7 +19,7 @@ In production, you probably want `DYLO_BUILD` to be set to 0, as your mods should be pre-built, and put in the right place, next to the executable. > **Warning** -> Make sure to build your mods with the `rubicon/import-globals` and `impl` +> Make sure to build your mods with the `dylo/import-globals` and `impl` > features enabled, just like `dylo-runtime` would do. > > See the [rubicon docs](https://crates.io/crates/rubicon) for more details: essentially, your diff --git a/dylo-runtime/src/details.rs b/dylo-runtime/src/details.rs index 9bb7b6e..26c9e69 100644 --- a/dylo-runtime/src/details.rs +++ b/dylo-runtime/src/details.rs @@ -47,8 +47,40 @@ fn get_paths(mod_name: &str) -> Paths { .ancestors() .find(|p| p.join("Cargo.toml").exists()) .unwrap_or(current_exe_folder); + eprintln!("base dir: {:?}", base_dir); - let mod_srcdir = base_dir.join("mods").join(format!("mod-{mod_name}")); + fn find_mod_dir(dir: &std::path::Path, mod_name: &str) -> Option { + if !dir.is_dir() { + return None; + } + + let dir_name = dir.file_name()?.to_str()?; + if dir_name.starts_with(".") + || dir_name.starts_with("target") + || dir_name.starts_with("node_modules") + { + // no thanks + return None; + } + + if dir_name == format!("mod-{mod_name}") { + return Some(dir.to_path_buf()); + } + + for entry in dir.read_dir().ok()? { + let entry = entry.ok()?; + let path = entry.path(); + + if let Some(found) = find_mod_dir(&path, mod_name) { + return Some(found); + } + } + + None + } + + let mod_srcdir = find_mod_dir(base_dir, mod_name) + .unwrap_or_else(|| panic!("Could not find mod source directory for mod {mod_name}")); let cargo_target_dir = get_target_dir(mod_name); Paths { @@ -152,7 +184,7 @@ fn build_mod(mod_name: &'static str) { cmd.env("CARGO_TARGET_DIR", &paths.cargo_target_dir); cmd.arg("build"); cmd.arg("--verbose"); - cmd.arg("--features=impl,dylo-runtime/import-globals"); + cmd.arg("--features=impl,dylo/import-globals"); if build_profile == "release" { cmd.arg("--release"); } diff --git a/dylo/Cargo.toml b/dylo/Cargo.toml index cd9e247..92c6806 100644 --- a/dylo/Cargo.toml +++ b/dylo/Cargo.toml @@ -15,3 +15,8 @@ rust-version = "1.83" proc-macro = true [dependencies] +rubicon = { version = "3.4.9" } + +[features] +import-globals = ["rubicon/import-globals"] +export-globals = ["rubicon/export-globals"]