rusteal_codegen/rust_gen/
manual.rs1use std::path::Path;
2
3include!(concat!(env!("OUT_DIR"), "/manual_files.rs"));
4
5pub fn write_manual_module(src_dir: &Path) {
6 let manual_dir = src_dir.join("manual");
7
8 if let Ok(entries) = std::fs::read_dir(&manual_dir) {
9 for entry in entries.flatten() {
10 let name = entry.file_name();
11
12 if !MANUAL_FILES.iter().any(|(file, _)| name == *file) {
13 let path = entry.path();
14
15 let removed = if path.is_dir() {
16 std::fs::remove_dir_all(&path)
17 } else {
18 std::fs::remove_file(&path)
19 };
20
21 removed.unwrap_or_else(|e| panic!("Failed to clean {}: {e}", path.display()));
22 }
23 }
24 }
25
26 std::fs::create_dir_all(&manual_dir)
27 .unwrap_or_else(|e| panic!("Failed to create {}: {e}", manual_dir.display()));
28
29 for (name, contents) in MANUAL_FILES {
30 crate::write_if_changed(&manual_dir.join(name), contents)
31 .unwrap_or_else(|e| panic!("Failed to write manual/{name}: {e}"));
32 }
33
34 eprintln!(" manual/: {} files", MANUAL_FILES.len());
35}
36
37pub fn gating_features() -> std::collections::BTreeSet<&'static str> {
38 const MARKER: &str = "feature = \"";
39 let mut features = std::collections::BTreeSet::new();
40
41 for (_, contents) in MANUAL_FILES {
42 let mut rest = *contents;
43
44 while let Some(at) = rest.find(MARKER) {
45 rest = &rest[at + MARKER.len()..];
46
47 if let Some(end) = rest.find('"') {
48 features.insert(&rest[..end]);
49 rest = &rest[end..];
50 }
51 }
52 }
53
54 features
55}