extern crate walkdir;
use walkdir::WalkDir;
use std::env;
use std::fs::File;
use std::path::Path;
use std::io::Write;
fn main() {
let from = env::var("CARGO_MANIFEST_DIR").unwrap();
let from = Path::new(&from);
let from = from.join("static");
let mut out_path = Path::new(&env::var("OUT_DIR").unwrap()).to_owned();
out_path.push("lookup_static.rs");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=static");
let mut out_file = File::create(&out_path).unwrap();
out_file.write(PREFIX.as_bytes()).unwrap();
for entry in WalkDir::new(&from)
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| !e.path_is_symlink() && e.file_type().is_file())
{
let relative = entry.path().strip_prefix(&from).unwrap();
write!(out_file, "\nr#\"{}\"# => Ok(include_bytes!(r#\"{}\"#)),", relative.display(), entry.path().display()).unwrap();
}
out_file.write(SUFFIX.as_bytes()).unwrap();
}
const PREFIX: &str = "
pub fn lookup_static_file(path: &str) -> Result<&'static [u8], ()> {
match path {
";
const SUFFIX: &str = "
_ => Err(()),
}
}
";