From 4ac698817d92ff84c98890c508c9fbae417a98d9 Mon Sep 17 00:00:00 2001 From: Azalea Gui <22280294+hykilpikonna@users.noreply.github.com> Date: Thu, 21 Aug 2025 08:31:32 -0400 Subject: [PATCH] [F] Fix cargo publish #405 --- crates/hyfetch/build.rs | 29 +++++++++++++++++++---------- crates/hyfetch/src/font_logo.rs | 2 +- crates/hyfetch/src/neofetch_util.rs | 2 +- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/crates/hyfetch/build.rs b/crates/hyfetch/build.rs index 439d8f68..27d14e72 100644 --- a/crates/hyfetch/build.rs +++ b/crates/hyfetch/build.rs @@ -1,6 +1,7 @@ +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 indexmap::IndexMap; use regex::Regex; @@ -24,17 +25,25 @@ impl AsciiDistro { } fn main() { - let neofetch_path = Path::new(env!("CARGO_WORKSPACE_DIR")).join("neofetch"); + // 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()); - println!( - "cargo:rerun-if-changed={neofetch_path}", - neofetch_path = neofetch_path.display() - ); + 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"); - let out_dir = env::var_os("OUT_DIR").unwrap(); - let out_path = Path::new(&out_dir); + // 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()); - export_distros(neofetch_path, out_path); + // 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); } 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 35dad7b4..9f1998ef 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!("../../../hyfetch/data/font_logos.json"); +const FONT_LOGOS: &str = include_str!(concat!(env!("OUT_DIR"), "/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 e145e4fe..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!("../../../neofetch"); +pub const NEOFETCH_SCRIPT: &str = include_str!(concat!(env!("OUT_DIR"), "/neofetch")); #[derive(Clone, Eq, PartialEq, Debug, AsRefStr, Deserialize, Serialize)] #[serde(tag = "mode")]