Skip to main content

max / makenotwork

2.1 KB · 51 lines History Blame Raw
1 //! Write every staged screen's residual to `src/quasi/residuals.rs`.
2 //!
3 //! The build-time half of the declaration transition (quasicoherent
4 //! `793d99dd`). A residual is a screen's markup with the request taken out of
5 //! it, and it is produced by *rendering*: `quasi_webview::stage::derive` calls
6 //! the screen's staged twin and reads the spans off what the renderer emits. So
7 //! it cannot be produced by this crate's own build script, which cannot link
8 //! the crate it is building. It is produced here instead, by a binary that
9 //! links the crate the ordinary way, and what it writes is Rust source the next
10 //! build compiles.
11 //!
12 //! Rust source and not a serialization format. A format would need a writer, a
13 //! reader, a version and a parse at startup, and the parse is exactly what the
14 //! spike's template intermediate was rejected for. There is no format here: the
15 //! artifact is code, `rustc` is its only reader, and what ships is literals in
16 //! read-only data.
17 //!
18 //! `quasi::residuals::tests::every_committed_residual_matches_a_fresh_one`
19 //! fails when this output is stale, so the regeneration step is:
20 //!
21 //! ```sh
22 //! cargo run --bin export-residuals
23 //! ```
24 //!
25 //! A test rather than only a pre-commit hook, because a residual goes stale for
26 //! two different reasons and a hook catches one of them. A screen changing is
27 //! visible in the diff; **quasi-webview changing is not**, and under the tree's
28 //! `[patch]` block a renderer edit in another repo silently makes every
29 //! committed residual one version behind. `cargo test` runs against the
30 //! renderer actually linked, so it sees both.
31
32 use std::io::Write as _;
33
34 fn main() -> std::io::Result<()> {
35 let source = makenotwork::quasi::residuals::generate();
36
37 if std::env::args().any(|argument| argument == "--stdout") {
38 std::io::stdout().write_all(source.as_bytes())?;
39 return Ok(());
40 }
41
42 let path = concat!(
43 env!("CARGO_MANIFEST_DIR"),
44 "/src/quasi/residuals/compiled.rs"
45 );
46 let mut file = std::fs::File::create(path)?;
47 file.write_all(source.as_bytes())?;
48 println!("wrote {path}");
49 Ok(())
50 }
51