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/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 new file mode 100644 index 00000000..8cb60595 --- /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 _; +#[cfg(target_env = "musl")] +use mimalloc as _; +use supports_color as _; +use tracing_subscriber 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")]