-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.rs
More file actions
33 lines (29 loc) · 1.12 KB
/
build.rs
File metadata and controls
33 lines (29 loc) · 1.12 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
// SPDX-FileCopyrightText: 2021 - 2024 Robin Vobruba <hoijui.quaero@gmail.com>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use std::env;
use std::fs;
use std::path::Path;
const LICENSES_CACHE_FILE: &str = "resources/licenses-cache.bin.zstd";
const LICENSES_CACHE_URL: &str =
"https://github.com/o2sh/onefetch/raw/main/resources/license.cache.zstd";
fn download_licenses_cache() -> Result<(), Box<dyn std::error::Error>> {
let cache_file = Path::new(&env::var("OUT_DIR")?).join(LICENSES_CACHE_FILE);
if !cache_file.exists() {
fs::create_dir_all(cache_file.parent().unwrap())?;
let url = reqwest::Url::parse(LICENSES_CACHE_URL)?;
let content = reqwest::blocking::get(url)?.bytes()?;
fs::write(cache_file, content)?;
}
println!("cargo:rerun-if-env-changed=OUT_DIR");
Ok(())
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
// NOTE As <https://docs.rs> does not allow the build process to use the network,
// we have to disable downloading the licenses.
if std::env::var("DOCS_RS").is_ok() {
Ok(())
} else {
download_licenses_cache()
}
}