//! Write every staged screen's residual to `src/quasi/residuals.rs`. //! //! The build-time half of the declaration transition (quasicoherent //! `793d99dd`). A residual is a screen's markup with the request taken out of //! it, and it is produced by *rendering*: `quasi_webview::stage::derive` calls //! the screen's staged twin and reads the spans off what the renderer emits. So //! it cannot be produced by this crate's own build script, which cannot link //! the crate it is building. It is produced here instead, by a binary that //! links the crate the ordinary way, and what it writes is Rust source the next //! build compiles. //! //! Rust source and not a serialization format. A format would need a writer, a //! reader, a version and a parse at startup, and the parse is exactly what the //! spike's template intermediate was rejected for. There is no format here: the //! artifact is code, `rustc` is its only reader, and what ships is literals in //! read-only data. //! //! `quasi::residuals::tests::every_committed_residual_matches_a_fresh_one` //! fails when this output is stale, so the regeneration step is: //! //! ```sh //! cargo run --bin export-residuals //! ``` //! //! A test rather than only a pre-commit hook, because a residual goes stale for //! two different reasons and a hook catches one of them. A screen changing is //! visible in the diff; **quasi-webview changing is not**, and under the tree's //! `[patch]` block a renderer edit in another repo silently makes every //! committed residual one version behind. `cargo test` runs against the //! renderer actually linked, so it sees both. use std::io::Write as _; fn main() -> std::io::Result<()> { let source = makenotwork::quasi::residuals::generate(); if std::env::args().any(|argument| argument == "--stdout") { std::io::stdout().write_all(source.as_bytes())?; return Ok(()); } let path = concat!( env!("CARGO_MANIFEST_DIR"), "/src/quasi/residuals/compiled.rs" ); let mut file = std::fs::File::create(path)?; file.write_all(source.as_bytes())?; println!("wrote {path}"); Ok(()) }