forked from uutils/coreutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
83 lines (73 loc) · 2.95 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
71
72
73
74
75
76
77
78
79
80
81
82
83
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
pub fn main() {
if let Ok(profile) = env::var("PROFILE") {
println!("cargo:rustc-cfg=build={:?}", profile);
}
let feature_prefix = "CARGO_FEATURE_";
let out_dir = env::var("OUT_DIR").unwrap();
let mut crates = Vec::new();
for (key, val) in env::vars() {
if val == "1" && key.starts_with(feature_prefix) {
let krate = key[feature_prefix.len()..].to_lowercase();
match krate.as_ref() {
"default" | "macos" | "unix" | "windows" => continue,
"nightly" | "test_unimplemented" => continue,
s if s.starts_with("feat_") => continue,
_ => {}
}
crates.push(krate.to_string());
}
}
crates.sort();
let mut cf = File::create(Path::new(&out_dir).join("uutils_crates.rs")).unwrap();
let mut mf = File::create(Path::new(&out_dir).join("uutils_map.rs")).unwrap();
mf.write_all(
"
type UtilityMap = HashMap<&'static str, fn(Vec<String>) -> i32>;
fn util_map() -> UtilityMap {
let mut map: UtilityMap = HashMap::new();\n"
.as_bytes(),
)
.unwrap();
for krate in crates {
cf.write_all(format!("extern crate uu_{krate};\n", krate = krate).as_bytes())
.unwrap();
match krate.as_ref() {
"hashsum" => {
mf.write_all(
"map.insert(\"hashsum\", uu_hashsum::uumain);
map.insert(\"md5sum\", uu_hashsum::uumain);
map.insert(\"sha1sum\", uu_hashsum::uumain);
map.insert(\"sha224sum\", uu_hashsum::uumain);
map.insert(\"sha256sum\", uu_hashsum::uumain);
map.insert(\"sha384sum\", uu_hashsum::uumain);
map.insert(\"sha512sum\", uu_hashsum::uumain);
map.insert(\"sha3sum\", uu_hashsum::uumain);
map.insert(\"sha3-224sum\", uu_hashsum::uumain);
map.insert(\"sha3-256sum\", uu_hashsum::uumain);
map.insert(\"sha3-384sum\", uu_hashsum::uumain);
map.insert(\"sha3-512sum\", uu_hashsum::uumain);
map.insert(\"shake128sum\", uu_hashsum::uumain);
map.insert(\"shake256sum\", uu_hashsum::uumain);\n"
.as_bytes(),
)
.unwrap();
}
_ => mf
.write_all(
format!(
"map.insert(\"{krate}\", uu_{krate}::uumain);\n",
krate = krate
)
.as_bytes(),
)
.unwrap(),
}
}
mf.write_all(b"map\n}\n").unwrap();
cf.flush().unwrap();
mf.flush().unwrap();
}