//! Embeds every lexicon under `spec/lexicons`, so that the methods the server //! serves, and their MCP tools and CLI commands, follow the lexicons there. use std::path::{Path, PathBuf}; fn walk(dir: &Path, out: &mut Vec) { for entry in std::fs::read_dir(dir).unwrap_or_else(|e| panic!("{}: {e}", dir.display())) { let path = entry.unwrap().path(); if path.is_dir() { walk(&path, out); } else if path.extension().is_some_and(|e| e == "json") { out.push(path); } } } fn main() { let manifest = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); let root = manifest .join("../../spec/lexicons") .canonicalize() .expect("spec/lexicons"); println!("cargo:rerun-if-changed={}", root.display()); let mut files = Vec::new(); walk(&root, &mut files); files.sort(); let mut src = String::from( "/// Every lexicon under `spec/lexicons`, as its JSON text, in path order.\npub static LEXICONS: &[&str] = &[\n", ); for f in &files { // Directories are watched by their mtime, which a changed file does not touch. println!("cargo:rerun-if-changed={}", f.display()); src.push_str(&format!( " include_str!({:?}),\n", f.display().to_string() )); } src.push_str("];\n"); let out = PathBuf::from(std::env::var("OUT_DIR").unwrap()).join("lexicons.rs"); std::fs::write(out, src).unwrap(); }