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
extern crate proc_macro;
extern crate syn;
extern crate time;
use proc_macro::TokenStream;
#[proc_macro]
pub fn build_time(input: TokenStream) -> TokenStream {
let fmtstr: syn::LitStr = syn::parse(input).unwrap();
let time = time::now_utc();
let ftime = time::strftime(&fmtstr.value(), &time).unwrap();
let mut out_str = String::new();
out_str.push_str("const BUILD_TIME: &str = \"");
out_str.push_str(&ftime);
out_str.push_str("\";");
out_str.parse().unwrap()
}