crates/edda-build-thing/src/emit.rs
//! **edda's half of the emitter** — `code → toml`, one-directional.
//!
//! The WRITER is `nornir_build_thing::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 (`tests/toml_parity.rs` measures that), 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 nornir_build_thing::emit;
use nornir_build_thing::plugin::BuildThing;
use crate::recipe::EddaBuildThing;
/// The header every emission starts with — says what the file is, and what it is
/// not.
pub const EMITTED_HEADER: &str = "\
# edda — .nornir/build-variants.toml — EMITTED, NOT SOURCE.
#
# Generated by `cargo run -p edda-build-thing -- emit` from
# crates/edda-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. TWO rows, and they
# are the two executables the shared-lib samling ships: the `autonom` coverage
# CLI and the `robotui` accessible robot UI. The two static-musl appliance
# PID-1s `korp-installer` and `korp-start` were declared here until 2026-09-26,
# when the crate moved to tunnr (owner ruling: the installer boots tunnr-kernel
# and lives next to it); they are `tunnr/korp-installer` and `tunnr/korp-start`.
#
# edda's ~66 LIBRARY crates are deliberately not rows: a library is delivered to
# the registry by `dwarves crate-release`, not by a build point, and a variant is
# a claim about an ARTIFACT this repo produces. The reasoning per row is in
# crates/edda-build-thing/src/recipe.rs, never in this file.";
/// The emission — what `.nornir/build-variants.toml` must contain.
pub fn emitted_toml() -> Result<String> {
emit::emitted_toml(EMITTED_HEADER, &EddaBuildThing)
}
/// Regenerate `<repo_root>/.nornir/build-variants.toml` from the code.
pub fn write_emitted(repo_root: &Path) -> Result<PathBuf> {
emit::write_emitted(EMITTED_HEADER, &EddaBuildThing, 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/edda-build-thing has 2 ancestor(s)")
.to_path_buf()
}
/// The set this recipe declares.
#[must_use]
pub fn declared() -> nornir_build_thing::variant::BuildVariantSet {
EddaBuildThing.variants()
}