-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
78 lines (69 loc) · 2.11 KB
/
build.rs
File metadata and controls
78 lines (69 loc) · 2.11 KB
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
71
72
73
74
75
76
77
78
use std::*;
fn main() {
println!("cargo::rerun-if-changed=src/web.json");
let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
if target_env.starts_with("musl") {
println!("cargo::rustc-link-lib=m");
}
use fs::*;
use io::*;
let json_file = File::open("src/web.json").unwrap();
let reader = BufReader::new(json_file);
let value: serde_json::Value = serde_json::from_reader(reader).unwrap();
let cbor_file = File::create("web.cbor").unwrap();
let writer = BufWriter::new(cbor_file);
cbor4ii::serde::to_writer(writer, &value).unwrap();
let family = std::env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or_default();
let mut cmd = if family == "windows" {
let mut c = process::Command::new("tar");
c.args(["-czf", "web.tar.gz", "web.cbor"]);
c
} else if family == "unix" {
let mut c = process::Command::new("gzip");
c.args(["-kf", "web.cbor"]);
c
} else {
return;
};
assert!(cmd.status().unwrap().success());
}
#[test]
fn build() {
main();
}
#[macro_export]
macro_rules! cdbg {
() => {
#[cfg(debug_assertions)]{
$crate::println!("cargo::warning=[{}:{}:{}]", $crate::file!(), $crate::line!(), $crate::column!())
}
};
($val:expr) => {
#[cfg(debug_assertions)]{
match $val {
tmp => {
$crate::println!("cargo::warning=[{}:{}:{}] {} = {:#?}",
$crate::file!(), $crate::line!(), $crate::column!(), $crate::stringify!($val), &tmp);
tmp
}
}
}
};
($val:expr;) => {
#[cfg(debug_assertions)]{
match $val {
tmp => {
$crate::println!("cargo::error=[{}:{}:{}] {} = {:#?}",
$crate::file!(), $crate::line!(), $crate::column!(), $crate::stringify!($val), &tmp);
tmp
}
}
}
};
($($val:expr),+) => {
($(cdbg!($val)),+)
};
($($val:expr),+;) => {
($(cdbg!($val;)),+)
};
}