use std::{env, path::PathBuf, str::FromStr}; fn main() { build_butck_ffi(); #[cfg(target_os = "windows")] build_win32_gui(); } fn build_butck_ffi() { // Check if cbindgen is installed let cbindgen_check = std::process::Command::new("cbindgen") .arg("--version") .output(); if let Err(e) = cbindgen_check { if e.kind() == std::io::ErrorKind::NotFound { eprintln!("Error: cbindgen is not installed. Please install it with:"); eprintln!(" cargo install cbindgen"); std::process::exit(1); } else { eprintln!("Error: Failed to check cbindgen installation: {}", e); std::process::exit(1); } } let target_dir = get_target_dir(); // Try to run cbindgen to generate C bindings // > cbindgen --config cbindgen.toml ffi --output ffi/.temp/jvlib.h --quiet let output = std::process::Command::new("cbindgen") .args([ "--config", "cbindgen.toml", ".", "--output", &format!("{}/lib_butck.h", target_dir.display()), "--quiet", ]) .output(); match output { Ok(output) if output.status.success() => { // Successfully generated bindings } Ok(_) => { eprintln!("cbindgen failed to generate bindings"); } Err(e) if e.kind() == std::io::ErrorKind::NotFound => { eprintln!("cbindgen not found, skipping C binding generation"); } Err(e) => { eprintln!("Failed to run cbindgen: {}", e); } } } fn build_win32_gui() { use std::fs; use std::path::Path; use std::process::Command; 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() { panic!("Build script failed with exit code: {:?}", status.code()); } let exe_path = Path::new(crate_root) .join("gui\\win32\\build\\bin") .join(EXE_NAME); if exe_path.exists() { let target_dir = get_target_dir(); let dest_path = target_dir.join(EXE_NAME); if let Err(e) = fs::copy(&exe_path, &dest_path) { panic!("Failed to copy executable to build directory: {}", e); } } else { panic!("Executable not found at: {:?}", exe_path); } } fn get_target_dir() -> PathBuf { let out_dir = std::env::var("OUT_DIR").unwrap(); let out_dir_path = PathBuf::from_str(&out_dir).unwrap(); out_dir_path .parent() .unwrap() .parent() .unwrap() .parent() .unwrap() .to_path_buf() }