-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.rs
44 lines (37 loc) · 1.3 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
extern crate git2;
extern crate syntex;
extern crate serde_codegen;
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use git2::{Repository, DescribeOptions};
fn gen_version() {
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("version.rs");
let mut f = File::create(&dest_path).unwrap();
f.write_all(b"pub const VERSION: &'static str = \"").unwrap();
match Repository::open(Path::new(".")) {
Ok(repo) => {
let describe = repo.describe(DescribeOptions::new().show_commit_oid_as_fallback(true)).unwrap();
f.write_all(describe.format(None).unwrap().trim_left_matches("limonite-").as_bytes()).unwrap();
},
Err(_) => {
f.write_all(env!("CARGO_PKG_VERSION").as_bytes()).unwrap();
}
};
f.write_all(b"\";").unwrap();
}
fn process_serde_macros(input: &str, out: &str) {
let out_dir = env::var_os("OUT_DIR").unwrap();
let src = Path::new(input);
let dst = Path::new(&out_dir).join(out);
let mut registry = syntex::Registry::new();
serde_codegen::register(&mut registry);
registry.expand("", &src, &dst).unwrap();
}
fn main() {
gen_version();
process_serde_macros("src/post.rs.in", "post.rs");
process_serde_macros("src/site.rs.in", "site.rs");
}