-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
65 lines (50 loc) · 1.96 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
use std::error::Error;
use serde_json::json;
fn download_buckets() -> reqwest::Result<serde_json::Value> {
let response = reqwest::blocking::get(
"https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/buckets.json",
)?;
response.json()
}
fn get_known_buckets() -> Result<String, Box<dyn Error>> {
let body = download_buckets().unwrap_or_else(|_| {
println!("cargo::warning=Failed to download buckets.json, using default buckets");
json!({
"main": "https://github.com/ScoopInstaller/Main",
"extras": "https://github.com/ScoopInstaller/Extras",
"versions": "https://github.com/ScoopInstaller/Versions",
"nirsoft": "https://github.com/ScoopInstaller/Nirsoft",
"sysinternals": "https://github.com/niheaven/scoop-sysinternals",
"php": "https://github.com/ScoopInstaller/PHP",
"nerd-fonts": "https://github.com/matthewjberger/scoop-nerd-fonts",
"nonportable": "https://github.com/ScoopInstaller/Nonportable",
"java": "https://github.com/ScoopInstaller/Java",
"games": "https://github.com/Calinou/scoop-games"
})
});
let buckets = body.as_object().unwrap();
let mut output = String::new();
for bucket in buckets {
let name = bucket.0;
let url = bucket.1.as_str().unwrap();
output += &format!(
"pub const {}: &str = \"{}\";\n",
heck::AsShoutySnakeCase(name),
url
);
}
let mut map = phf_codegen::Map::new();
for (name, _) in buckets {
map.entry(name, &heck::AsShoutySnakeCase(name).to_string());
}
output += &format!(
"pub static BUCKETS: phf::Map<&'static str, &'static str> = {};",
map.build()
);
Ok(output)
}
fn main() -> Result<(), Box<dyn Error>> {
let out_path = std::env::var("OUT_DIR")?;
std::fs::write(out_path.clone() + "/buckets.rs", get_known_buckets()?)?;
Ok(())
}