diff --git a/crates/hyfetch/build.rs b/crates/hyfetch/build.rs index 27d14e72..5edb93d5 100644 --- a/crates/hyfetch/build.rs +++ b/crates/hyfetch/build.rs @@ -1,7 +1,6 @@ -use std::env; use std::fmt::Write as _; -use std::fs; -use std::path::{Path, PathBuf}; +use std::path::Path; +use std::{env, fs}; use indexmap::IndexMap; use regex::Regex; @@ -25,25 +24,14 @@ impl AsciiDistro { } fn main() { - // 1. Get workspace and OUT_DIR paths - let workspace_dir = PathBuf::from(env::var_os("CARGO_WORKSPACE_DIR").unwrap()); - let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); + let neofetch_path = Path::new(env!("CARGO_WORKSPACE_DIR")).join("neofetch"); - let src_neofetch = workspace_dir.join("neofetch"); - let src_font_logos = workspace_dir.join("hyfetch/data/font_logos.json"); - let dst_neofetch = out_dir.join("neofetch"); - let dst_font_logos = out_dir.join("font_logos.json"); + println!("cargo:rerun-if-changed={}", neofetch_path.display()); - // Tell Cargo to re-run if original files change - println!("cargo:rerun-if-changed={}", src_neofetch.display()); - println!("cargo:rerun-if-changed={}", src_font_logos.display()); + let out_dir = env::var_os("OUT_DIR").unwrap(); + let out_path = Path::new(&out_dir); - // 2. Copy neofetch script and font logos to OUT_DIR - fs::copy(&src_neofetch, &dst_neofetch).expect("Failed to copy neofetch script to OUT_DIR"); - fs::copy(&src_font_logos, &dst_font_logos).expect("Failed to copy font logos data to OUT_DIR"); - - // 3. Export distros from neofetch script - export_distros(&dst_neofetch, &out_dir); + export_distros(neofetch_path, out_path); } fn export_distros

(neofetch_path: P, out_path: &Path) diff --git a/crates/hyfetch/src/font_logo.rs b/crates/hyfetch/src/font_logo.rs index 59c14f47..dfdfa9bb 100644 --- a/crates/hyfetch/src/font_logo.rs +++ b/crates/hyfetch/src/font_logo.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; use std::fs::{self, File}; use std::io::{Read, Write}; -const FONT_LOGOS: &str = include_str!(concat!(env!("OUT_DIR"), "/font_logos.json")); +const FONT_LOGOS: &str = include_str!(concat!(env!("CARGO_WORKSPACE_DIR"), "/hyfetch/data/font_logos.json")); pub fn get_font_logo(backend: Backend) -> Result { // Check if the cache file exists and return its contents if it does diff --git a/crates/hyfetch/src/neofetch_util.rs b/crates/hyfetch/src/neofetch_util.rs index d6896e02..fcd96f71 100644 --- a/crates/hyfetch/src/neofetch_util.rs +++ b/crates/hyfetch/src/neofetch_util.rs @@ -53,7 +53,7 @@ _/\_\_ _/_/\_ pub const NEOFETCH_COLOR_PATTERNS: [&str; 6] = ["${c1}", "${c2}", "${c3}", "${c4}", "${c5}", "${c6}"]; pub static NEOFETCH_COLORS_AC: OnceLock = OnceLock::new(); -pub const NEOFETCH_SCRIPT: &str = include_str!(concat!(env!("OUT_DIR"), "/neofetch")); +pub const NEOFETCH_SCRIPT: &str = include_str!(concat!(env!("CARGO_WORKSPACE_DIR"), "/neofetch")); #[derive(Clone, Eq, PartialEq, Debug, AsRefStr, Deserialize, Serialize)] #[serde(tag = "mode")]