nativeview-codegen 0.1.0-rc.1

Multi-language ABI, policy, flat-op codec, and hybrid Direct-FFI code generator for Native View Engine.
Documentation
//! Embeds every `templates/` file into the crate (`EMBEDDED_TEMPLATES`), next to the Askama code
//! compiled from them, so `verify_embedded_templates` can prove a binary was built from the
//! templates of the checkout it runs in (a compiler cache can serve another checkout's build).
//! Paths stay relative to `CARGO_MANIFEST_DIR`: nothing absolute is written into `OUT_DIR`
//! (docs/UPSTREAM.md, kache build-script replay).

#[path = "src/embedded_templates/files.rs"]
mod files;

use std::fmt::Write as _;
use std::path::PathBuf;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // A directory is scanned recursively, so added and removed templates rerun this script too.
    println!("cargo:rerun-if-changed=templates");
    let mut out = String::from("pub(crate) static EMBEDDED_TEMPLATES: &[(&str, &[u8])] = &[\n");
    for file in files::template_files(std::path::Path::new("templates"))? {
        writeln!(
            out,
            "    ({file:?}, include_bytes!(concat!(env!(\"CARGO_MANIFEST_DIR\"), \"/templates/\", {file:?}))),"
        )?;
    }
    out.push_str("];\n");
    let path = PathBuf::from(std::env::var("OUT_DIR")?).join("embedded_templates.generated.rs");
    std::fs::write(path, out)?;
    Ok(())
}