summaryrefslogtreecommitdiff
path: root/build.rs
blob: d69d05e410c8ac06f6c4a16330d12582a67c083b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
fn main() {
    #[cfg(target_os = "windows")]
    build_win32_gui();
}

fn build_win32_gui() {
    use std::fs;
    use std::path::{Path, PathBuf};
    use std::process::Command;
    use std::str::FromStr;

    const EXE_NAME: &str = "butckg.exe";

    let crate_root = env!("CARGO_MANIFEST_DIR");
    let build_script = Path::new(crate_root).join("gui\\win32\\scripts\\build.ps1");

    let status = Command::new("powershell")
        .arg("-ExecutionPolicy")
        .arg("Bypass")
        .arg("-File")
        .arg(&build_script)
        .status()
        .expect("Failed to execute build script");

    if !status.success() {
        eprintln!(
            "Warning: Build script failed with exit code: {:?}",
            status.code()
        );
        return;
    }

    let exe_path = Path::new(crate_root)
        .join("gui\\win32\\build\\bin")
        .join(EXE_NAME);
    if exe_path.exists() {
        let out_dir = std::env::var("OUT_DIR").unwrap();
        let out_dir_path = PathBuf::from_str(&out_dir).unwrap();
        let target_dir = out_dir_path
            .parent()
            .unwrap()
            .parent()
            .unwrap()
            .parent()
            .unwrap();

        let dest_path = target_dir.join(EXE_NAME);
        if let Err(e) = fs::copy(&exe_path, &dest_path) {
            eprintln!(
                "Warning: Failed to copy executable to build directory: {}",
                e
            );
        }
    } else {
        eprintln!("Warning: Executable not found at: {:?}", exe_path);
    }
}