From 082d4cfdf7e644078d02f89b093103c99bac22ad Mon Sep 17 00:00:00 2001 From: thewh1teagle <61390950+thewh1teagle@users.noreply.github.com> Date: Mon, 5 Aug 2024 07:19:13 +0300 Subject: [PATCH] improve build scripts --- core/build.rs | 15 +++++++++++---- desktop/src-tauri/build.rs | 21 +++++++++++---------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/core/build.rs b/core/build.rs index 2c56f522..9f7f94bd 100644 --- a/core/build.rs +++ b/core/build.rs @@ -1,6 +1,13 @@ -use std::env; use std::path::{Path, PathBuf}; use std::process::Command; +use std::{env, fs}; + +fn hard_link_force(src: &Path, dst: &Path) { + if dst.exists() { + std::fs::remove_file(dst).unwrap(); + } + std::fs::hard_link(src, dst).unwrap(); +} fn get_cargo_target_dir() -> Result> { let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR")?); @@ -75,7 +82,7 @@ fn main() { .flatten() { let dst = Path::new(&target_dir).join(Path::new(entry.file_name().unwrap())); - std::fs::copy(entry, dst).unwrap(); + hard_link_force(&entry, &dst); } for entry in glob::glob(&format!("{}/*", ffmpeg_dir.join("bin").to_str().unwrap())) @@ -83,7 +90,7 @@ fn main() { .flatten() { let dst = Path::new(&target_dir).join(Path::new(entry.file_name().unwrap())); - std::fs::copy(entry, dst).unwrap(); + hard_link_force(&entry, &dst); } } @@ -98,7 +105,7 @@ fn main() { for pattern in patterns { for entry in glob::glob(&pattern).unwrap().flatten() { let dst = Path::new(&target_dir).join(Path::new(entry.file_name().unwrap())); - std::fs::copy(entry, dst).unwrap(); + hard_link_force(&entry, &dst); } } } diff --git a/desktop/src-tauri/build.rs b/desktop/src-tauri/build.rs index 8a69f6e7..9a48af65 100644 --- a/desktop/src-tauri/build.rs +++ b/desktop/src-tauri/build.rs @@ -9,22 +9,24 @@ fn commit_hash() -> String { String::from_utf8(output.stdout).unwrap() } -fn copy_files(src: &Path, dst: &Path, overwrite: bool) { - if dst.exists() && !overwrite { - return; - } +fn copy_folder(src: &Path, dst: &Path) { + std::fs::create_dir_all(dst).expect("Failed to create dst directory"); if cfg!(unix) { std::process::Command::new("cp") .arg("-rf") .arg(src) - .arg(dst) + .arg(dst.parent().unwrap()) .status() .expect("Failed to execute cp command"); - } else if cfg!(windows) { + } + + if cfg!(windows) { std::process::Command::new("robocopy.exe") - .args(&["/e", src.to_str().unwrap(), dst.to_str().unwrap()]) + .arg("/e") + .arg(src) + .arg(dst) .status() - .expect("Failed to execute xcopy command"); + .expect("Failed to execute robocopy command"); } } @@ -36,8 +38,7 @@ fn copy_locales() { // Construct the source and target paths for the locales folder let src_locales = src_tauri.join("locales"); let target_locales = target_dir.join("locales"); - let target_locales = target_locales.parent().unwrap(); - copy_files(src_locales.as_path(), target_locales, true); + copy_folder(src_locales.as_path(), &target_locales); } fn extract_whisper_env() {