Update
This commit is contained in:
parent
34f8dbffab
commit
fd8fe9ce11
4 changed files with 134 additions and 30 deletions
24
src/build.rs
Normal file
24
src/build.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
use std::env;
|
||||
use std::fs::{read_dir, File};
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
fn get_const_name<P: Clone + Into<PathBuf>>(p: &P) -> String {
|
||||
let mut file_name_without_extension = p.clone().into();
|
||||
file_name_without_extension.set_extension("");
|
||||
String::from(file_name_without_extension.file_name().unwrap().to_string_lossy()).to_uppercase()
|
||||
}
|
||||
|
||||
pub fn create_static_output_files(source_dir: &str) {
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
let dest_path = Path::new(&out_dir).join("static_files.rs");
|
||||
let mut f = File::create(&dest_path).unwrap();
|
||||
for maybe_dir_entry in read_dir(source_dir).unwrap() {
|
||||
let file_path = maybe_dir_entry.unwrap().path();
|
||||
let mut buffer = String::new();
|
||||
File::open(file_path.clone()).unwrap().read_to_string(&mut buffer).unwrap();
|
||||
let fence = buffer.chars().filter(|c| *c == '#').collect::<String>() + "#";
|
||||
f.write_all(format!("pub const {}: &'static str = r{1}\"{2}\"{1};\n", get_const_name(&file_path), fence, buffer).as_bytes()).unwrap();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue