75 lines
2.5 KiB
Rust
75 lines
2.5 KiB
Rust
use std::env;
|
|
use std::fs;
|
|
use std::path::Path;
|
|
|
|
fn main() {
|
|
// 1. Tauri билд
|
|
tauri_build::build();
|
|
|
|
// Все, что ниже — только для Windows
|
|
if env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
|
|
// --- 2. Работа с ресурсами (Манифест администратора) ---
|
|
let mut res = winres::WindowsResource::new();
|
|
res.set_manifest(
|
|
r#"
|
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
|
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
|
<security>
|
|
<requestedPrivileges>
|
|
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
|
</requestedPrivileges>
|
|
</security>
|
|
</trustInfo>
|
|
</assembly>
|
|
"#,
|
|
);
|
|
|
|
if env::var("HOST").unwrap().contains("linux") {
|
|
res.set_toolkit_path("/usr/bin");
|
|
res.set_windres_path("/usr/bin/x86_64-w64-mingw32-windres");
|
|
}
|
|
|
|
if let Err(e) = res.compile() {
|
|
println!("cargo:warning=Failed to compile Windows resources: {}", e);
|
|
}
|
|
|
|
// --- 3. Копирование Wintun DLL ---
|
|
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("No target arch");
|
|
|
|
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");
|
|
|
|
let out_dir = env::var("OUT_DIR").expect("No out dir");
|
|
let target_dir = Path::new(&out_dir)
|
|
.parent()
|
|
.and_then(|p| p.parent())
|
|
.and_then(|p| p.parent())
|
|
.and_then(|p| p.parent())
|
|
.expect("Не удалось вычислить target");
|
|
|
|
let dest_path = target_dir.join("wintun.dll");
|
|
|
|
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);
|
|
}
|
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
}
|