-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
build.rs
30 lines (26 loc) · 1.01 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
fn main() {
println!("cargo:rerun-if-env-changed=LAPIN_CODEGEN_DIR");
println!("cargo:rerun-if-env-changed=LAPIN_CODEGEN_FILE");
#[cfg(feature = "codegen-internal")]
codegen()
}
#[cfg(feature = "codegen-internal")]
fn codegen() {
use amq_protocol_codegen::{CodeGenerator, HandlebarsAMQPExtension};
use serde_json::{from_str, Value};
let out_dir = std::env::var("LAPIN_CODEGEN_DIR")
.or_else(|_| std::env::var("OUT_DIR"))
.expect("OUT_DIR is not defined");
let out_file = std::env::var("LAPIN_CODEGEN_FILE").unwrap_or_else(|_| "channel".to_string());
let template = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/channel.rs"));
let extra = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/lapin.json"));
let data = from_str::<Value>(extra).expect("Failed to parse extra file");
CodeGenerator::simple_codegen_with_data(
&out_dir,
&out_file,
"channel",
template,
"protocol",
Some(data),
);
}