From b58425badd4840802b2d713951fd13748b1085c3 Mon Sep 17 00:00:00 2001 From: Azalea Gui <22280294+hykilpikonna@users.noreply.github.com> Date: Thu, 21 Aug 2025 09:47:48 -0400 Subject: [PATCH] =?UTF-8?q?[F]=20=F0=9F=92=A2=F0=9F=92=A2=F0=9F=92=A2?= =?UTF-8?q?=F0=9F=92=A2=F0=9F=92=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 9 +++++++- Cargo.toml | 2 +- crates/hyfetch/Cargo.toml | 1 + crates/hyfetch/build.rs | 34 ++++++++++++++++++++++------- crates/hyfetch/src/font_logo.rs | 2 +- crates/hyfetch/src/neofetch_util.rs | 2 +- 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3ac78dab..61d48396 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -220,6 +220,12 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "getrandom" version = "0.2.15" @@ -245,7 +251,7 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hyfetch" -version = "2.0.0-rc3" +version = "2.0.0-rc4" dependencies = [ "aho-corasick", "ansi_colours", @@ -258,6 +264,7 @@ dependencies = [ "enable-ansi-support", "enterpolation", "fastrand", + "fs_extra", "indexmap", "itertools", "normpath", diff --git a/Cargo.toml b/Cargo.toml index 48e48e65..55b54963 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["crates/*"] [workspace.package] -version = "2.0.0-rc3" +version = "2.0.0-rc4" authors = ["Azalea Gui "] edition = "2021" rust-version = "1.75.0" diff --git a/crates/hyfetch/Cargo.toml b/crates/hyfetch/Cargo.toml index a1cbc3b9..bfee14da 100644 --- a/crates/hyfetch/Cargo.toml +++ b/crates/hyfetch/Cargo.toml @@ -44,6 +44,7 @@ which = { workspace = true, features = [] } indexmap = { workspace = true, features = ["std"] } regex = { workspace = true, features = ["perf", "std", "unicode"] } unicode-normalization = { workspace = true, features = ["std"] } +fs_extra = "1.3.0" [target.'cfg(windows)'.dependencies] enable-ansi-support = { workspace = true, features = [] } diff --git a/crates/hyfetch/build.rs b/crates/hyfetch/build.rs index 5edb93d5..e726bc4a 100644 --- a/crates/hyfetch/build.rs +++ b/crates/hyfetch/build.rs @@ -1,7 +1,9 @@ +use std::env; use std::fmt::Write as _; -use std::path::Path; -use std::{env, fs}; +use std::fs; +use std::path::{Path, PathBuf}; +use fs_extra::dir::{CopyOptions}; use indexmap::IndexMap; use regex::Regex; use unicode_normalization::UnicodeNormalization as _; @@ -23,15 +25,31 @@ impl AsciiDistro { } } +fn anything_that_exist(paths: &[&Path]) -> Option { + paths.iter().copied().find(|p| p.exists()).map(Path::to_path_buf) +} + fn main() { - let neofetch_path = Path::new(env!("CARGO_WORKSPACE_DIR")).join("neofetch"); + // Path hack to make file paths work in both workspace and manifest directory + let p_ws = PathBuf::from(env::var_os("CARGO_WORKSPACE_DIR").unwrap()); + let p_mn = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()); + let o = PathBuf::from(env::var_os("OUT_DIR").unwrap()); + + for file in &["neofetch", "hyfetch"] { + let src = anything_that_exist(&[&p_ws.join(file), &p_mn.join(file)]) + .expect(&format!("{} not found in workspace or manifest directory", file)); + let dst = o.join(file); + println!("cargo:rerun-if-changed={}", src.display()); - println!("cargo:rerun-if-changed={}", neofetch_path.display()); + // Copy either file or directory + if src.is_dir() { + let opt = CopyOptions { overwrite: true, copy_inside: true, ..CopyOptions::default() }; + fs_extra::dir::copy(&src, &dst, &opt).expect("Failed to copy directory to OUT_DIR"); + } + else { fs::copy(&src, &dst).expect("Failed to copy file to OUT_DIR"); } + } - let out_dir = env::var_os("OUT_DIR").unwrap(); - let out_path = Path::new(&out_dir); - - export_distros(neofetch_path, out_path); + export_distros(&o.join("neofetch"), &o); } 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 dfdfa9bb..5e293d2a 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!("CARGO_WORKSPACE_DIR"), "/hyfetch/data/font_logos.json")); +const FONT_LOGOS: &str = include_str!(concat!(env!("OUT_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 fcd96f71..d6896e02 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!("CARGO_WORKSPACE_DIR"), "/neofetch")); +pub const NEOFETCH_SCRIPT: &str = include_str!(concat!(env!("OUT_DIR"), "/neofetch")); #[derive(Clone, Eq, PartialEq, Debug, AsRefStr, Deserialize, Serialize)] #[serde(tag = "mode")]