-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
70 lines (59 loc) · 1.29 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*!
# HTMinL: Build
*/
use argyle::KeyWordsBuilder;
use dowser::Extension;
use std::{
fs::File,
io::Write,
path::{
Path,
PathBuf,
},
};
/// # Build.
///
/// We might as well pre-compile the arguments and extensions we're looking for.
pub fn main() {
println!("cargo:rerun-if-env-changed=CARGO_PKG_VERSION");
build_cli();
build_ext();
}
/// # Build CLI Keys.
fn build_cli() {
let mut builder = KeyWordsBuilder::default();
builder.push_keys([
"-h", "--help",
"-p", "--progress",
"-V", "--version",
]);
builder.push_keys_with_values(["-l", "--list"]);
builder.save(out_path("argyle.rs"));
}
/// # Build Extensions.
fn build_ext() {
let out = format!(
r"
/// # Extension: HTM.
const E_HTM: Extension = {};
/// # Extension: HTML.
const E_HTML: Extension = {};
",
Extension::codegen(b"htm"),
Extension::codegen(b"html"),
);
write(&out_path("htminl-extensions.rs"), out.as_bytes());
}
/// # Write File.
fn write(path: &Path, data: &[u8]) {
File::create(path).and_then(|mut f| f.write_all(data).and_then(|_| f.flush()))
.expect("Unable to write file.");
}
/// # Output Path.
///
/// Append the sub-path to OUT_DIR and return it.
fn out_path(stub: &str) -> PathBuf {
std::fs::canonicalize(std::env::var("OUT_DIR").expect("Missing OUT_DIR."))
.expect("Missing OUT_DIR.")
.join(stub)
}