use std::env; use std::fs; use std::path::Path; fn main() { let mut attrs = tauri_build::Attributes::new(); // Проверяем, что целевая ОС — Windows if env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" { let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("No target arch"); let target_triple = env::var("TARGET").expect("No TARGET triple"); // например, x86_64-pc-windows-gnu let profile = env::var("PROFILE").expect("No PROFILE"); // debug или release let arch_folder = match target_arch.as_str() { "x86_64" => "amd64", "aarch64" => "arm64", "arm" => "arm", "x86" => "x86", _ => panic!("Unsupported architecture for Wintun: {}", target_arch), }; let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("No manifest dir"); let dll_source = Path::new(&manifest_dir) .join("bin") .join(arch_folder) .join("wintun.dll"); // --- ИСПРАВЛЕННЫЙ ПУТЬ --- // Строим путь: CARGO_MANIFEST_DIR / target / TRIPLE / PROFILE let dest_dir = Path::new(&manifest_dir) .parent() // выход из src-tauri в корень проекта .expect("No parent dir") .join("src-tauri") .join("target") .join(&target_triple) .join(&profile); let dest_path = dest_dir.join("wintun.dll"); // Создаем папку назначения, если её нет (важно при первой сборке) if !dest_dir.exists() { fs::create_dir_all(&dest_dir).ok(); } if dll_source.exists() { fs::copy(&dll_source, &dest_path).expect("Failed to copy wintun.dll"); // Вывод в консоль для проверки пути при сборке println!("cargo:warning=Wintun DLL copied to: {:?}", dest_path); } else { println!("cargo:warning=Wintun DLL NOT FOUND at: {:?}", dll_source); } println!("cargo:rerun-if-changed=bin/{}/wintun.dll", arch_folder); // --- Манифест (Admin Rights) --- let manifest = r#" "#; let windows_attrs = tauri_build::WindowsAttributes::new().app_manifest(manifest); attrs = attrs.windows_attributes(windows_attrs); } println!("cargo:rerun-if-changed=build.rs"); tauri_build::try_build(attrs).expect("failed to run tauri-build"); }