From efb1ad016e76c24dcfc229e7f63077ca63198ede Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Tue, 15 Sep 2026 23:55:19 +0300 Subject: [PATCH 1/2] Add a library target, for the analysis pipeline in other tooling --- Cargo.toml | 4 ++++ src/lib.rs | 22 ++++++++++++++++++++++ src/main.rs | 9 +-------- 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 9ead5769..e118406b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,10 @@ readme = "README.md" categories = ["command-line-utilities"] rust-version = "1.85" +[lib] +name = "decomp_toolkit" +path = "src/lib.rs" + [[bin]] name = "dtk" path = "src/main.rs" diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 00000000..1a83d55a --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,22 @@ +#![deny(unused_crate_dependencies)] +//! decomp-toolkit as a library. +//! +//! The `dtk` binary in `main.rs` is the primary consumer, and these modules are +//! arranged for it rather than as a curated public API. +//! +//! Nothing here is covered by a stability promise: it moves with `dtk`. + +pub mod analysis; +pub mod argp_version; +pub mod cmd; +pub mod obj; +pub mod util; +pub mod vfs; + +// Dependencies of the `dtk` binary alone. `unused_crate_dependencies` is +// checked per target, so without these the library target reports them unused. +use enable_ansi_support as _; +use supports_color as _; +use tracing_subscriber as _; +#[cfg(target_env = "musl")] +use mimalloc as _; diff --git a/src/main.rs b/src/main.rs index 4333df7c..d1b6861e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,20 +1,13 @@ -#![deny(unused_crate_dependencies)] use std::{env, ffi::OsStr, fmt::Display, path::PathBuf, process::exit, str::FromStr}; use anyhow::Error; use argp::{FromArgValue, FromArgs}; +use decomp_toolkit::{argp_version, cmd}; use enable_ansi_support::enable_ansi_support; use supports_color::Stream; use tracing::level_filters::LevelFilter; use tracing_subscriber::EnvFilter; -pub mod analysis; -pub mod argp_version; -pub mod cmd; -pub mod obj; -pub mod util; -pub mod vfs; - // musl's allocator is very slow, so use mimalloc when targeting musl. // Otherwise, use the system allocator to avoid extra code size. #[cfg(target_env = "musl")] From f9317bf06df0ec15f9191f3700865ef496c96a16 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Wed, 16 Sep 2026 18:32:27 +0300 Subject: [PATCH 2/2] Expose the DOL analysis entry point --- src/cmd/dol.rs | 12 ++++++------ src/lib.rs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cmd/dol.rs b/src/cmd/dol.rs index 619201bb..7f7ff775 100644 --- a/src/cmd/dol.rs +++ b/src/cmd/dol.rs @@ -869,11 +869,11 @@ fn resolve_external_relocations( Ok(()) } -struct AnalyzeResult { - obj: ObjInfo, - dep: Vec, - symbols_cache: Option, - splits_cache: Option, +pub struct AnalyzeResult { + pub obj: ObjInfo, + pub dep: Vec, + pub symbols_cache: Option, + pub splits_cache: Option, } fn load_dol_module( @@ -897,7 +897,7 @@ fn load_dol_module( Ok((obj, object_path)) } -fn load_analyze_dol(config: &ProjectConfig, object_base: &ObjectBase) -> Result { +pub fn load_analyze_dol(config: &ProjectConfig, object_base: &ObjectBase) -> Result { let (mut obj, object_path) = load_dol_module(&config.base, object_base)?; let mut dep = vec![object_path]; diff --git a/src/lib.rs b/src/lib.rs index 1a83d55a..8cb60595 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ pub mod vfs; // Dependencies of the `dtk` binary alone. `unused_crate_dependencies` is // checked per target, so without these the library target reports them unused. use enable_ansi_support as _; -use supports_color as _; -use tracing_subscriber as _; #[cfg(target_env = "musl")] use mimalloc as _; +use supports_color as _; +use tracing_subscriber as _;