Skip to main content

rusteal_codegen/rust_gen/
manual.rs

1// Hand-written binding extensions: glam conversions, FKey helpers, world and
2// widget wrappers.
3//
4// They live in this crate's `manual/` directory, are embedded at build time and
5// written verbatim into every generated `bindings` crate, where they compile
6// against the generated modules (`crate::core_ue`, `crate::engine`, ...).
7
8use std::path::Path;
9
10include!(concat!(env!("OUT_DIR"), "/manual_files.rs"));
11
12/// Write `src/manual/`, replacing whatever a previous run left behind.
13pub fn write_manual_module(src_dir: &Path) {
14    let manual_dir = src_dir.join("manual");
15    if manual_dir.exists() {
16        std::fs::remove_dir_all(&manual_dir)
17            .unwrap_or_else(|e| panic!("Failed to clean {}: {e}", manual_dir.display()));
18    }
19    std::fs::create_dir_all(&manual_dir)
20        .unwrap_or_else(|e| panic!("Failed to create {}: {e}", manual_dir.display()));
21
22    for (name, contents) in MANUAL_FILES {
23        std::fs::write(manual_dir.join(name), contents)
24            .unwrap_or_else(|e| panic!("Failed to write manual/{name}: {e}"));
25    }
26    eprintln!("  manual/: {} files", MANUAL_FILES.len());
27}
28
29/// The Cargo features `manual/` gates its modules on (`#[cfg(feature = "...")]`).
30/// A project enables only some of them, so the generated manifest declares all
31/// of them as expected `cfg` values.
32pub fn gating_features() -> std::collections::BTreeSet<&'static str> {
33    const MARKER: &str = "feature = \"";
34    let mut features = std::collections::BTreeSet::new();
35    for (_, contents) in MANUAL_FILES {
36        let mut rest = *contents;
37        while let Some(at) = rest.find(MARKER) {
38            rest = &rest[at + MARKER.len()..];
39            if let Some(end) = rest.find('"') {
40                features.insert(&rest[..end]);
41                rest = &rest[end..];
42            }
43        }
44    }
45    features
46}