xtask_lib/
lib.rs

1//! # xtask — Cadmus build automation
2//!
3//! Centralises every build, test, lint, documentation, and release task for
4//! the Cadmus project as typed, testable Rust code that behaves identically
5//! in a local devenv shell and in GitHub Actions CI.
6//!
7//! ## Usage
8//!
9//! ```text
10//! cargo xtask <COMMAND> [OPTIONS]
11//! ```
12//!
13//! The `xtask` alias is configured in `.cargo/config.toml` so that
14//! `cargo xtask` works from any directory inside the workspace.
15//!
16//! ## Commands
17//!
18//! | Command | Description |
19//! |---------|-------------|
20//! | [`fmt`](tasks::fmt) | Check (or apply) `rustfmt` formatting |
21//! | [`clippy`](tasks::clippy) | Run `cargo clippy` across the feature matrix |
22//! | [`test`](tasks::test) | Run `cargo test` across the feature matrix |
23//! | [`build-kobo`](tasks::build_kobo) | Cross-compile for Kobo (ARM, Linux only) |
24//! | [`setup-native`](tasks::setup_native) | Build MuPDF and the C wrapper for native dev |
25//! | [`run-emulator`](tasks::run_emulator) | Run the Cadmus emulator (ensures prereqs are built) |
26//! | [`install-importer`](tasks::install_importer) | Install the Cadmus importer crate |
27//! | [`docs`](tasks::docs) | Build the full documentation portal |
28//! | [`download-assets`](tasks::download_assets) | Download static asset dirs from the latest release |
29//! | [`dist`](tasks::dist) | Assemble the Kobo distribution directory |
30//! | [`bundle`](tasks::bundle) | Package a `KoboRoot.tgz` ready for device installation |
31//! | [`ci`](tasks::ci) | CI-specific setup tasks (e.g. `install-doc-tools`) |
32//!
33//! ## Design
34//!
35//! Each command lives in its own module under [`tasks`].  The `tasks::util::cmd`
36//! helper wraps [`std::process::Command`] with consistent error reporting so
37//! every task fails fast with a clear message.  The `tasks::util::http` module
38//! provides pure-Rust download and archive helpers replacing `curl`, `wget`,
39//! `tar`, and `sha256sum` subprocess calls.
40
41pub mod tasks;
42
43pub use anyhow::Result;
44pub use clap::Parser;
45
46pub use tasks::{
47    build_kobo::BuildKoboArgs, bundle::BundleArgs, ci::CiArgs, clippy::ClippyArgs, dist::DistArgs,
48    docs::DocsArgs, fmt::FmtArgs, install_importer::InstallImporterArgs,
49    run_emulator::RunEmulatorArgs, setup_native::SetupNativeArgs, test::TestArgs,
50};
51
52/// Cadmus build automation.
53///
54/// Run `cargo xtask <COMMAND> --help` for per-command options.
55#[derive(Debug, Parser)]
56#[command(name = "xtask", about = "Cadmus build automation")]
57pub struct Cli {
58    #[command(subcommand)]
59    pub command: Command,
60}
61
62#[derive(Debug, clap::Subcommand)]
63pub enum Command {
64    /// Check (or apply) rustfmt formatting across the workspace.
65    Fmt(FmtArgs),
66    /// Run cargo clippy across the full feature matrix.
67    Clippy(ClippyArgs),
68    /// Run cargo test across the full feature matrix.
69    Test(TestArgs),
70    /// Cross-compile Cadmus for Kobo devices (Linux only).
71    BuildKobo(BuildKoboArgs),
72    /// Build MuPDF and the C wrapper for native development.
73    SetupNative(SetupNativeArgs),
74    /// Run the Cadmus emulator (ensures MuPDF and wrapper are built first).
75    RunEmulator(RunEmulatorArgs),
76    /// Install the Cadmus importer crate (ensures MuPDF and wrapper are built first).
77    InstallImporter(InstallImporterArgs),
78    /// Build the full documentation portal (mdBook + cargo doc + Zola).
79    Docs(DocsArgs),
80    /// Download static asset directories from the latest GitHub release.
81    DownloadAssets,
82    /// Assemble the Kobo distribution directory from build outputs.
83    Dist(DistArgs),
84    /// Package a KoboRoot.tgz ready for device installation.
85    Bundle(BundleArgs),
86    /// CI-specific setup tasks (install-doc-tools, etc.).
87    Ci(CiArgs),
88}
89
90/// Run the xtask CLI with the given arguments.
91///
92/// This is the main entry point for the binary, but can also be called
93/// from tests.
94pub fn run() -> Result<()> {
95    let cli = Cli::parse();
96
97    match cli.command {
98        Command::Fmt(args) => tasks::fmt::run(args),
99        Command::Clippy(args) => tasks::clippy::run(args),
100        Command::Test(args) => tasks::test::run(args),
101        Command::BuildKobo(args) => tasks::build_kobo::run(args),
102        Command::SetupNative(args) => tasks::setup_native::run(args),
103        Command::RunEmulator(args) => tasks::run_emulator::run(args),
104        Command::InstallImporter(args) => tasks::install_importer::run(args),
105        Command::Docs(args) => tasks::docs::run(args),
106        Command::DownloadAssets => tasks::download_assets::run(),
107        Command::Dist(args) => tasks::dist::run(args),
108        Command::Bundle(args) => tasks::bundle::run(args),
109        Command::Ci(args) => tasks::ci::run(args),
110    }
111}