diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-09 22:45:24 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-09 22:45:24 +0800 |
| commit | c9ff9a13735010a6d3937a05e8ce9f00f9fab3ac (patch) | |
| tree | 77ad04e6db77aa037513e4d22866a89f9cf52403 /build.rs | |
| parent | 25761b5ef0d9d385ac2a371b62913f98350d6f56 (diff) | |
Add GTK GUI build system for Unix platforms
Diffstat (limited to 'build.rs')
| -rw-r--r-- | build.rs | 81 |
1 files changed, 81 insertions, 0 deletions
@@ -5,6 +5,9 @@ fn main() { #[cfg(target_os = "windows")] build_win32_gui(); + + #[cfg(target_family = "unix")] + build_gtk_gui(); } fn build_butck_ffi() { @@ -55,6 +58,7 @@ fn build_butck_ffi() { } } +#[allow(dead_code)] fn build_win32_gui() { use std::fs; use std::path::Path; @@ -92,6 +96,83 @@ fn build_win32_gui() { } } +#[allow(dead_code)] +fn build_gtk_gui() { + use std::fs; + use std::path::Path; + use std::process::Command; + + const EXE_NAME: &str = "butckg"; + + let crate_root = env!("CARGO_MANIFEST_DIR"); + let build_script = Path::new(crate_root).join("gui/gtk/cbuild.sh"); + + // Check if build script exists + if !build_script.exists() { + println!("GTK GUI build script not found, skipping GTK build"); + return; + } + + // Check if GTK development files are available + let gtk_check = Command::new("pkg-config") + .arg("--exists") + .arg("gtk+-3.0") + .status(); + + if let Ok(status) = gtk_check { + if !status.success() { + println!("GTK3 development files not found, skipping GTK build"); + println!("Please install GTK3 development packages:"); + println!(" Ubuntu/Debian: sudo apt-get install libgtk-3-dev"); + println!(" Fedora: sudo dnf install gtk3-devel"); + println!(" Arch: sudo pacman -S gtk3"); + return; + } + } else { + println!("Failed to check GTK3 installation, skipping GTK build"); + return; + } + + // Make build script executable + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + if let Ok(metadata) = fs::metadata(&build_script) { + let mut perms = metadata.permissions(); + perms.set_mode(0o755); + fs::set_permissions(&build_script, perms).ok(); + } + } + + // Run build script + let status = Command::new("bash") + .arg(&build_script) + .arg("build") + .status() + .expect("Failed to execute GTK build script"); + + if !status.success() { + panic!( + "GTK build script failed with exit code: {:?}", + status.code() + ); + } + + let exe_path = Path::new(crate_root) + .join("gui/gtk/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 GTK executable to build directory: {}", e); + } + } else { + panic!("GTK 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(); |
