cabinpkg-build 0.14.0

Backend-independent build graph planner for Cabin
Documentation
use std::path::PathBuf;

/// Backend-independent description of everything that needs to happen to
/// realize a build. A backend (currently `cabin-ninja`) walks this graph and
/// emits the equivalent build-system-specific representation.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BuildGraph {
    /// All actions to execute, in topological order. Earlier actions in the
    /// vector never depend on later actions.
    pub actions: Vec<Action>,
    /// Output paths that should be marked as default targets.
    pub default_outputs: Vec<PathBuf>,
    /// One entry per C/C++ source compile, used to emit
    /// `compile_commands.json`. Both languages contribute entries
    /// with their language-appropriate compiler driver and flags
    /// recorded in `arguments`.
    pub compile_commands: Vec<CompileCommand>,
}

/// A single buildable step.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Action {
    pub kind: ActionKind,
    /// Inputs that participate in the command (e.g. `.cc` for compile,
    /// `.o`/`.a` for link).
    pub inputs: Vec<PathBuf>,
    /// Inputs the action implicitly depends on but that are not arguments.
    /// Used by C/C++ compiles whose source is generated by an
    /// upstream action.
    pub implicit_inputs: Vec<PathBuf>,
    /// Files this action produces.
    pub outputs: Vec<PathBuf>,
    /// Optional Makefile-style depfile path; populated for C/C++
    /// compiles so Ninja can wire `-MMD -MF $depfile` into its
    /// `deps = gcc` machinery.
    pub depfile: Option<PathBuf>,
    /// Argv-style command, ready to be shell-quoted by the backend.
    pub command: Vec<String>,
    /// Short, human-readable description for build output (`CXX foo.o`).
    pub description: String,
}

/// Categorization of a build action. Currently a closed set; new variants
/// require explicit handling by every backend.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ActionKind {
    /// Compile a single C translation unit (`.c`) to an object
    /// file. Driven by the C compiler with `-std=c11` plus the
    /// language-neutral profile flags.
    CompileC,
    /// Compile a single C++ translation unit (`.cc` / `.cpp` /
    /// `.cxx` / `.c++` / `.C`) to an object file. Driven by the
    /// C++ compiler with `-std=c++17` plus the language-neutral
    /// profile flags.
    CompileCpp,
    /// Archive a set of object files into a static library.
    ArchiveStaticLibrary,
    /// Link object files plus static archives into an executable.
    /// The link-driver language (C vs. C++) is encoded in the
    /// action's `command` (the first argument is the chosen
    /// compiler driver), so backends do not need to consult any
    /// extra metadata to render the action.
    LinkExecutable,
}

/// One entry of a Clang JSON Compilation Database.
///
/// `arguments` is kept as a list so each backend / consumer can render it
/// however the format requires (LLVM accepts both `command` and
/// `arguments` keys; `cabin-ninja` emits `command`).
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CompileCommand {
    pub directory: PathBuf,
    pub file: PathBuf,
    pub arguments: Vec<String>,
    pub output: PathBuf,
}