Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/znippy

xtask/src/main.rs

//! **znippy's ONE build path** — `cargo xtask build --suite ORIGINAL [--atom <a>]`.
//!
//! The entire body of the verb is
//! [`nornir_build_thing::suite_cli::run`](nornir_build_thing::suite_cli::run). This
//! file names no package, no bin, no feature string and no profile: everything it
//! builds comes from `.nornir/build-variants.toml`, so the declaration and the build
//! cannot drift apart the way `holger-build` (three hardcoded tiers, blind to the
//! other ten variants on disk) and `dwarves/src/service.rs` (a hand-written
//! `--features embed-nornir,server` against a declaration saying `embed-all,read-fat`)
//! did.
//!
//! ## What was here before
//!
//! Measured 2026-08-03: znippy's `xtask` was a 16-line `src/lib.rs` with **no build
//! verb at all** — no `suite_cli`, no cargo spawn, not even a `main`. The crate
//! existed only to host `examples/nornir-bench.rs` and `benches/nornir.rs`. So the
//! repo's build recipes lived exclusively in `.nornir/*.md` prose
//! (`cargo build --release -p znippy-cli`, `cargo build -p znippy-cli --release`,
//! `cargo build --workspace`) — three spellings, two of them naming a binary that no
//! longer exists. Prose that names a cargo invocation IS a second declaration; the
//! fix is one verb that reads the first.
//!
//! The bench hosting is untouched: `cargo run -p xtask --release --example
//! nornir-bench` still works exactly as `nornir bench run znippy` subprocesses it,
//! and the lib target is still there. This adds a `[[bin]]`, it replaces nothing.

use std::path::{Path, PathBuf};

use anyhow::{bail, Result};
use nornir_build_thing::suite_cli;

/// The repo root — the parent of this crate's directory.
///
/// Taken from `CARGO_MANIFEST_DIR` rather than the current directory so the verb
/// resolves the same declaration whether it is invoked through the `cargo xtask`
/// alias from the repo root or by path from anywhere else. A build verb that reads a
/// different file depending on where you stood is a second declaration again.
fn repo_root() -> PathBuf {
    Path::new(env!("CARGO_MANIFEST_DIR"))
        .parent()
        .expect("xtask/ always has a parent")
        .to_path_buf()
}

fn main() -> Result<()> {
    let argv: Vec<String> = std::env::args().skip(1).collect();
    match argv.first().map(String::as_str) {
        Some("build") => {
            let args = suite_cli::parse(&argv[1..])?;
            let built = suite_cli::run(&repo_root(), &args)?;
            if !args.list {
                eprintln!("built: {}", built.join(", "));
            }
            Ok(())
        }
        Some(other) => bail!("unknown verb '{other}'\n\n{}", suite_cli::USAGE),
        None => bail!("{}", suite_cli::USAGE),
    }
}