-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
45 lines (37 loc) · 1.5 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std::env;
use std::fs::{File, read_to_string};
use std::io::Write;
use std::path::Path;
fn main() {
// don't rebuild if source hasn't changed
println!("cargo:rerun-if-changed=src");
println!("cargo:rerun-if-changed=example.html");
println!("cargo:rerun-if-changed=example.css");
// get crate version
let crate_ver = format!("{}.{}.{}",
env!("CARGO_PKG_VERSION_MAJOR"),
env!("CARGO_PKG_VERSION_MINOR"),
env!("CARGO_PKG_VERSION_PATCH"));
// write example html, submission form html, and css as consts
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("index.rs");
let mut f = File::create(&dest_path).unwrap();
let html = read_to_string("example.template.html").unwrap();
let form = read_to_string("example.form.html").unwrap();
let css = read_to_string("example.css").unwrap();
let mut html = format!(r##"const DEFAULT_INDEX: &str = r#"{}"#;"##, html);
let mut form = format!(r##"const DEFAULT_FORM: &str = r#"{}"#;"##, form);
let mut css = format!(r##"const DEFAULT_CSS: &str = r#"{}"#;"##, css);
form.push('\n');
form.push('\n');
html.push('\n');
html.push('\n');
css.push('\n');
css.push('\n');
f.write(&html.into_bytes()).unwrap();
f.write(&form.into_bytes()).unwrap();
f.write(&css.into_bytes()).unwrap();
// write crate version as a const
let ver = format!(r#"const CRATE_VERSION: &str = "{}";"#, crate_ver);
f.write(&ver.into_bytes()).unwrap();
}