added a nix flake for building
This commit is contained in:
38
build.rs
38
build.rs
@@ -1,15 +1,33 @@
|
||||
use std::fs::{File, create_dir};
|
||||
use std::path::Path;
|
||||
use std::fs::File;
|
||||
use std::path::PathBuf;
|
||||
|
||||
// This file is kind of ugly, I tried to make nix build work
|
||||
|
||||
fn main() {
|
||||
let dest_path = Path::new("themes/Catppuccin-Macchiato.tmTheme");
|
||||
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
let local_theme_path = PathBuf::from(&manifest_dir).join("themes/Catppuccin-Macchiato.tmTheme");
|
||||
|
||||
if !dest_path.exists() {
|
||||
let mut response = reqwest::blocking::get("https://raw.githubusercontent.com/catppuccin/bat/refs/heads/main/themes/Catppuccin%20Macchiato.tmTheme")
|
||||
.expect("Failed to download theme");
|
||||
let final_path = if let Ok(nix_theme_path) = std::env::var("THEME_PATH") {
|
||||
// In case of nix build
|
||||
println!("cargo:rerun-if-env-changed=THEME_PATH");
|
||||
nix_theme_path
|
||||
} else {
|
||||
// In case of cargo
|
||||
if !local_theme_path.exists() {
|
||||
println!("cargo:warning=Theme not found, downloading...");
|
||||
|
||||
create_dir("themes").expect("Could not create themes dir");
|
||||
let mut file = File::create(dest_path).expect("Failed to create theme file");
|
||||
std::io::copy(&mut response, &mut file).expect("Failed to save theme");
|
||||
}
|
||||
std::fs::create_dir_all(local_theme_path.parent().unwrap())
|
||||
.expect("Could not create themes directory");
|
||||
|
||||
let mut response = reqwest::blocking::get("https://raw.githubusercontent.com/catppuccin/bat/refs/heads/main/themes/Catppuccin%20Macchiato.tmTheme")
|
||||
.expect("Failed to download theme");
|
||||
|
||||
let mut file = File::create(&local_theme_path).expect("Failed to create theme file");
|
||||
std::io::copy(&mut response, &mut file).expect("Failed to save theme");
|
||||
}
|
||||
|
||||
local_theme_path.to_str().unwrap().to_string()
|
||||
};
|
||||
|
||||
println!("cargo:rustc-env=THEME_FILE_PATH={}", final_path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user