1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Build script for the RUITL runtime crate.
//!
//! Compiles every `.ruitl` template found under `templates/` or `src/templates/`
//! into a sibling `*_ruitl.rs` file using the shared `ruitl_compiler` crate.
//! The CLI (`ruitl compile`) uses the same crate — there is no second parser.
use std::env;
use std::path::{Path, PathBuf};
use std::process;
fn main() {
// docs.rs mounts the crate source read-only while building, and the
// committed sibling `*_ruitl.rs` files already match what we'd emit —
// so there is nothing to do there. Ditto any host that explicitly
// opts out via `RUITL_SKIP_BUILD=1`.
if env::var_os("DOCS_RS").is_some() || env::var_os("RUITL_SKIP_BUILD").is_some() {
return;
}
let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
let manifest_root = PathBuf::from(&manifest_dir);
let candidates = [
manifest_root.join("templates"),
manifest_root.join("src").join("templates"),
// `examples/demo_templates/` hosts compilable templates used by
// `examples/server_integration.rs` to demonstrate real sibling-file
// integration. `examples/syntax_showcase/` (deliberately NOT in this
// list) holds hand-written reference templates that exercise every
// feature but depend on notional user-defined types — read-only
// material for users learning the syntax.
manifest_root.join("examples").join("demo_templates"),
];
let mut compiled: Vec<PathBuf> = Vec::new();
let mut errors: Vec<String> = Vec::new();
for dir in &candidates {
if !dir.exists() {
continue;
}
// Rerun on any change under the templates dir.
println!("cargo:rerun-if-changed={}", dir.display());
emit_rerun_for_ruitl_files(dir);
match ruitl_compiler::compile_dir_sibling(dir) {
Ok(paths) => compiled.extend(paths),
Err(e) => errors.push(format!("{}: {}", dir.display(), e)),
}
}
if !errors.is_empty() {
eprintln!("RUITL template compilation failed:");
for err in &errors {
eprintln!(" {}", err);
}
process::exit(1);
}
if !compiled.is_empty() {
println!(
"cargo:warning=Compiled {} RUITL templates (sibling *_ruitl.rs files)",
compiled.len()
);
}
}
fn emit_rerun_for_ruitl_files(dir: &Path) {
for entry in walkdir::WalkDir::new(dir).into_iter().filter_map(|e| e.ok()) {
let path = entry.path();
if path.is_file() && path.extension().map(|e| e == "ruitl").unwrap_or(false) {
println!("cargo:rerun-if-changed={}", path.display());
}
}
}