Skip to content

Commit

Permalink
Don't be so chatty
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Dec 5, 2024
1 parent 6115afc commit 8d6753e
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 16 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions dylo-cli/src/load_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
/// See <https://github.com/bearcove/dylo>
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,
Expand Down
22 changes: 16 additions & 6 deletions dylo-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,27 @@ enum ProcessReason {
/// Discover all mods in the `./` directory, recursively
fn list_mods(mods_dir: &camino::Utf8Path) -> std::io::Result<Vec<ModInfo>> {
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)?;
Expand Down Expand Up @@ -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(())
Expand Down
6 changes: 1 addition & 5 deletions dylo-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion dylo-runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 34 additions & 2 deletions dylo-runtime/src/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::path::PathBuf> {
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 {
Expand Down Expand Up @@ -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");
}
Expand Down
5 changes: 5 additions & 0 deletions dylo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit 8d6753e

Please sign in to comment.