Skip to content

Commit

Permalink
improve build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Aug 5, 2024
1 parent 27ebf9a commit 082d4cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
15 changes: 11 additions & 4 deletions core/build.rs
Original file line number Diff line number Diff line change
@@ -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<std::path::PathBuf, Box<dyn std::error::Error>> {
let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR")?);
Expand Down Expand Up @@ -75,15 +82,15 @@ 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()))
.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);
}
}

Expand All @@ -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);
}
}
}
Expand Down
21 changes: 11 additions & 10 deletions desktop/src-tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand All @@ -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() {
Expand Down

0 comments on commit 082d4cf

Please sign in to comment.