crates/nornir-build-thing/src/emit.rs
//! **nornir's half of the emitter** — `code → toml`, one-directional.
//!
//! The WRITER is `nbt::emit` (one writer for every repo's recipe crate); what
//! lives here is this repo's own [`EMITTED_HEADER`] and the three calls. The
//! committed `.nornir/build-variants.toml` is [`emitted_toml`]'s output and
//! nothing else: an edit to it has ZERO effect on what the recipe declares, and
//! the only way to change the description is to change the code and re-emit.
use std::path::{Path, PathBuf};
use anyhow::Result;
use nbt::emit;
use nbt::plugin::BuildThing;
use crate::recipe::NornirBuildThing;
/// The header every emission starts with — says what the file is, and what it
/// is not.
pub const EMITTED_HEADER: &str = "\
# nornir — .nornir/build-variants.toml — EMITTED, NOT SOURCE.
#
# Generated by `cargo run -p nornir-build-thing -- emit` from
# crates/nornir-build-thing (the Rust `impl BuildThing`). The code is the one
# source; this file DESCRIBES the build. Editing it changes NOTHING: re-emit
# after changing the code. Do not edit by hand.
#
# Model: variant → features → settings/sub-settings → typ. ONE delivery
# (ORIGINAL) and FIVE atoms — the fleet build matrix's five rows and nothing
# else: the DAEMON (`nornir-server`, the only service-shaped row and so the only
# one that may carry `embeds`), the fat CLI, the CLI that REACHES holger
# (`linkage = mixed`, and mixed is a defined value), the GUI on `viz` alone, and
# the one-box `solo` shape. The fat/mixed axis is ONE feature — `embed-holger` —
# rather than a naming convention; skade, iceberg and parquet are plain deps, so
# no feature choice can make nornir thin. `nornir-watch` and `nornir-mcp` left
# the set on 2026-08-03 and their reasons are in crates/nornir-build-thing's
# recipe.rs, beside the rows.";
/// The emission — what `.nornir/build-variants.toml` must contain.
pub fn emitted_toml() -> Result<String> {
emit::emitted_toml(EMITTED_HEADER, &NornirBuildThing)
}
/// Regenerate `<repo_root>/.nornir/build-variants.toml` from the code.
pub fn write_emitted(repo_root: &Path) -> Result<PathBuf> {
emit::write_emitted(EMITTED_HEADER, &NornirBuildThing, repo_root)
}
/// The repo root, from this crate's manifest directory.
#[must_use]
pub fn repo_root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.parent()
.and_then(Path::parent)
.expect("crates/nornir-build-thing has 2 ancestor(s)")
.to_path_buf()
}
/// The set this recipe declares.
#[must_use]
pub fn declared() -> nbt::variant::BuildVariantSet {
NornirBuildThing.variants()
}