mitts 0.2.1

Rust-first build and package tooling with a shared artifact cache
Documentation
/*
 * Mitts Build — Rust-first build and package tooling with shared artifact cache
 * Copyright (c) 2026 Alexander Panasenko
 *
 * Contact: alex@prod.codes
 * Author: https://prod.codes/about/
 * Project: https://github.com/alex09x/mitts
 * SPDX-License-Identifier: MIT OR Apache-2.0
 */

use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap};
use std::path::PathBuf;

/// Distinct type of compilation/build action.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ActionKind {
    CompileRlib,
    CompileBin,
    BuildScript,
    Custom(String),
}

/// A language-neutral build action representing a discrete compilation unit.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Action {
    pub id: String,
    pub kind: ActionKind,
    pub description: String,
    pub toolchain: ToolchainInfo,
    pub inputs: Vec<PathBuf>,
    pub outputs: Vec<PathBuf>,
    pub args: Vec<String>,
    pub env: HashMap<String, String>,
    pub dependencies: Vec<String>,
}

/// Toolchain identification independent of specific compiler details.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ToolchainInfo {
    pub name: String,
    pub version: String,
    pub target_triple: Option<String>,
}

/// Result of executing an action.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ActionResult {
    pub action_id: String,
    pub exit_code: i32,
    pub success: bool,
    pub stdout: String,
    pub stderr: String,
    pub cached: bool,
}

/// Full execution plan composed of ordered actions.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BuildPlan {
    pub actions: Vec<Action>,
    pub target_directory: PathBuf,
    /// Linkable artifact per action id, exactly as dependents consume it
    /// (e.g. the `.rlib`/proc-macro library passed via `--extern`).
    /// Empty when the adapter does not track it (e.g. fast-lock hits).
    #[serde(default)]
    pub artifacts: BTreeMap<String, PathBuf>,
    /// Build cfgs / directives per action id (e.g. rustc-cfg from build scripts).
    #[serde(default)]
    pub unit_cfgs: BTreeMap<String, Vec<String>>,
    /// Extra environment variables per unit (e.g. OUT_DIR and rustc-env from build scripts).
    #[serde(default)]
    pub unit_env: BTreeMap<String, HashMap<String, String>>,
    /// Extra link arguments per unit (e.g. -L native=, -l from build scripts).
    #[serde(default)]
    pub unit_link_args: BTreeMap<String, Vec<String>>,
    /// Extra tracked file/directory inputs (path -> sha256 or "<missing>") from unit dep-info and build script rerun-if-changed.
    #[serde(default)]
    pub tracked_extra_files: BTreeMap<PathBuf, String>,
    /// Extra tracked environment variables (name -> Option<value>) from unit env!/option_env!, dep-info env-dep, and build script rerun-if-env-changed.
    #[serde(default)]
    pub tracked_env_vars: BTreeMap<String, Option<String>>,
    /// Whether any mutable unit had incomplete/tainted input tracking during execution.
    #[serde(default)]
    pub inputs_incomplete: bool,
}