xtask_lib/tasks/
install_importer.rs

1//! `cargo xtask install-importer` — install the Cadmus importer crate.
2//!
3//! Ensures MuPDF sources and the `mupdf_wrapper` C library are built for the
4//! native platform, then runs `cargo install --path crates/importer`.  Any
5//! extra arguments are forwarded to `cargo install`.
6
7use anyhow::Result;
8use clap::Args;
9
10use super::setup_native;
11use super::util::{cmd, mupdf_wrapper, workspace};
12
13/// Arguments for `cargo xtask install-importer`.
14#[derive(Debug, Args)]
15pub struct InstallImporterArgs {
16    /// Extra arguments forwarded to `cargo install --path crates/importer`.
17    #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
18    pub extra: Vec<String>,
19}
20
21/// Ensures prerequisites are built then installs the importer.
22///
23/// # Errors
24///
25/// Returns an error if the MuPDF download, wrapper build, or installation
26/// fails.
27pub fn run(args: InstallImporterArgs) -> Result<()> {
28    let root = workspace::root()?;
29
30    setup_native::ensure_mupdf_sources(&root, false)?;
31    mupdf_wrapper::build_native_if_needed(&root)?;
32
33    let importer_path = root.join("crates/importer");
34    let importer_str = importer_path.to_string_lossy().into_owned();
35
36    let mut cargo_args = vec!["install", "--path", &importer_str];
37    let extra_refs: Vec<&str> = args.extra.iter().map(String::as_str).collect();
38    cargo_args.extend_from_slice(&extra_refs);
39
40    cmd::run("cargo", &cargo_args, &root, &[])
41}