use std::env; use std::path::Path; use std::process::Command; fn version_env() -> Option<()> { if env::var("MUMBLE_WEB2_VERSION").is_ok() { return Some(()); } let output = Command::new("git") .args(["rev-parse", "--short", "HEAD"]) .output() .ok()?; let git_hash = String::from_utf8(output.stdout).ok()?; let git_hash = git_hash.trim(); // drop trailing newline let status = Command::new("git") .args(["status", "--porcelain"]) .output() .ok()?; let dirty = match status.stdout.is_empty() { true => "", false => "-dirty", }; // Expose it as a compile-time env var println!("cargo::rustc-env=MUMBLE_WEB2_VERSION=git-{git_hash}{dirty}"); // Optional: rebuild when HEAD changes println!("cargo::rerun-if-changed=.git/HEAD"); Some(()) } fn download_deepfilternet() { // Define the target directory and file let assets_dir = "assets"; let target_file = format!("{}/DeepFilterNet3_ll_onnx.tar.gz", assets_dir); let target_path = Path::new(&target_file); // Check if the file already exists if target_path.exists() { println!( "cargo::warning=DeepFilterNet model already exists at {}", target_file ); return; } println!( "cargo::warning=Downloading DeepFilterNet model to {}...", target_file ); // Download the file using curl let url = "https://github.com/Rikorose/DeepFilterNet/raw/refs/heads/main/models/DeepFilterNet3_ll_onnx.tar.gz"; let status = Command::new("curl") .args([ "-L", // Follow redirects "-o", &target_file, // Output file url, ]) .status() .expect("Failed to execute curl command. Make sure curl is installed."); if !status.success() { println!("cargo::error=Failed to download DeepFilterNet model from {url}"); return; } println!( "cargo::warning=Successfully downloaded DeepFilterNet model to {}", target_file ); // Rerun this build script if the target file is deleted println!("cargo::rerun-if-changed={}", target_file); } fn main() { version_env(); download_deepfilternet(); }