summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.rs81
-rw-r--r--gui/gtk/.gitignore56
-rw-r--r--gui/gtk/CMakeLists.txt56
-rwxr-xr-xgui/gtk/cbuild.sh90
-rwxr-xr-xgui/gtk/scripts/_entry.sh90
-rwxr-xr-xgui/gtk/scripts/build.sh37
-rwxr-xr-xgui/gtk/scripts/clean.sh31
-rwxr-xr-xgui/gtk/scripts/run.sh37
-rw-r--r--gui/gtk/src/main.c51
-rw-r--r--gui/win32/CMakeLists.txt1
10 files changed, 530 insertions, 0 deletions
diff --git a/build.rs b/build.rs
index 0bd7e8d..7527903 100644
--- a/build.rs
+++ b/build.rs
@@ -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();
diff --git a/gui/gtk/.gitignore b/gui/gtk/.gitignore
new file mode 100644
index 0000000..eb3cee1
--- /dev/null
+++ b/gui/gtk/.gitignore
@@ -0,0 +1,56 @@
+build/
+build*/
+*/build/
+*/build*/
+
+CMakeCache.txt
+CMakeFiles/
+cmake_install.cmake
+Makefile
+CMakeScripts/
+CTestTestfile.cmake
+*.cbp
+*.cmake
+
+*.exe
+*.ilk
+*.obj
+*.pdb
+*.user
+*.aps
+*.ncb
+*.suo
+*.tlog
+*.log
+*.idb
+*.pch
+*.res
+*.sbr
+*.exp
+*.lib
+*.dll
+*.dll.a
+*.a
+*.o
+*.out
+*.app
+*.dylib
+*.framework
+
+.vscode/
+.idea/
+*.sln
+*.vcxproj
+*.vcxproj.filters
+*.vcxproj.user
+*.sdf
+*.opensdf
+*.db
+
+bin/
+Debug/
+Release/
+x64/
+x86/
+
+.clangd
diff --git a/gui/gtk/CMakeLists.txt b/gui/gtk/CMakeLists.txt
new file mode 100644
index 0000000..2ed840c
--- /dev/null
+++ b/gui/gtk/CMakeLists.txt
@@ -0,0 +1,56 @@
+cmake_minimum_required(VERSION 3.10)
+project(butckg VERSION 1.0.0 LANGUAGES C)
+
+set(CMAKE_C_STANDARD 11)
+set(CMAKE_C_STANDARD_REQUIRED ON)
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+
+# Output directory
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+
+# Find GTK3
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
+
+# Include directories
+include_directories(${GTK3_INCLUDE_DIRS})
+link_directories(${GTK3_LIBRARY_DIRS})
+
+# Add definitions
+add_definitions(${GTK3_CFLAGS_OTHER})
+
+# Executable
+add_executable(butckg
+ src/main.c
+)
+
+# Link libraries
+target_link_libraries(butckg PRIVATE ${GTK3_LIBRARIES})
+
+# Target properties
+set_target_properties(butckg PROPERTIES
+ RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
+)
+
+# lib_butck
+target_include_directories(butckg PRIVATE ${CMAKE_SOURCE_DIR}/../../.temp/target/release)
+
+target_link_directories(butckg PRIVATE
+ ${CMAKE_SOURCE_DIR}/../../.temp/target/release
+)
+
+target_link_libraries(butckg PRIVATE
+ lib_butck
+)
+
+# Check if library files exist
+if(EXISTS "${CMAKE_SOURCE_DIR}/../../.temp/target/release/lib_butck.so")
+ message(STATUS "Found lib_butck.so")
+ add_custom_command(TARGET butckg POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ "${CMAKE_SOURCE_DIR}/../../.temp/target/release/lib_butck.so"
+ $<TARGET_FILE_DIR:butckg>
+ )
+else()
+ message(WARNING "lib_butck.so NotFound - building without Rust library")
+endif()
diff --git a/gui/gtk/cbuild.sh b/gui/gtk/cbuild.sh
new file mode 100755
index 0000000..cf3aeaf
--- /dev/null
+++ b/gui/gtk/cbuild.sh
@@ -0,0 +1,90 @@
+#!/bin/bash
+
+# Butchunker GTK Build Script
+# Usage: ./cbuild.sh [build|clean|run|rebuild|env]
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+BUILD_DIR="$SCRIPT_DIR/build"
+
+function setup_environment() {
+ echo "Setting up environment and generating .clangd configuration..."
+ "$SCRIPT_DIR/scripts/_entry.sh"
+}
+
+function build_project() {
+ echo "Building Butchunker GTK..."
+
+ # Setup environment first
+ setup_environment
+
+ # Create build directory if it doesn't exist
+ mkdir -p "$BUILD_DIR"
+
+ # Run CMake and make
+ cd "$BUILD_DIR"
+ if cmake .. && make; then
+ echo "Build successful!"
+ return 0
+ else
+ echo "Build failed!"
+ return 1
+ fi
+}
+
+function clean_project() {
+ echo "Cleaning build directory..."
+ rm -rf "$BUILD_DIR"
+ echo "Clean complete!"
+}
+
+function run_project() {
+ echo "Running Butchunker GTK..."
+
+ # Setup environment first
+ setup_environment
+
+ # Check if executable exists
+ if [ -f "$BUILD_DIR/bin/butckg" ]; then
+ "$BUILD_DIR/bin/butckg"
+ else
+ echo "Error: Executable not found. Run './cbuild.sh build' first."
+ return 1
+ fi
+}
+
+function rebuild_project() {
+ clean_project
+ build_project
+}
+
+# Main script logic
+case "${1:-}" in
+ "build")
+ build_project
+ ;;
+ "clean")
+ clean_project
+ ;;
+ "run")
+ run_project
+ ;;
+ "rebuild")
+ rebuild_project
+ ;;
+ "env")
+ setup_environment
+ ;;
+ *)
+ echo "Usage: $0 [build|clean|run|rebuild|env]"
+ echo ""
+ echo "Commands:"
+ echo " build - Build the project"
+ echo " clean - Clean build directory"
+ echo " run - Build and run the project"
+ echo " rebuild - Clean and rebuild the project"
+ echo " env - Setup environment and generate .clangd config"
+ exit 1
+ ;;
+esac
+
+exit $?
diff --git a/gui/gtk/scripts/_entry.sh b/gui/gtk/scripts/_entry.sh
new file mode 100755
index 0000000..a80788e
--- /dev/null
+++ b/gui/gtk/scripts/_entry.sh
@@ -0,0 +1,90 @@
+#!/bin/bash
+
+# Butchunker GTK Entry Script
+# This script sets up the environment and generates .clangd configuration
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
+
+# Get GTK include paths
+GTK_INCLUDE_PATHS=""
+if pkg-config --exists gtk+-3.0; then
+ # Get include paths from pkg-config and split them
+ GTK_INCLUDE_PATHS=$(pkg-config --cflags-only-I gtk+-3.0)
+fi
+
+# Get Rust library include path
+RUST_INCLUDE_PATH="$PROJECT_ROOT/../../.temp/target/release"
+
+# Generate .clangd configuration file
+CLANGD_CONTENT="CompileFlags:
+ CompilationDatabase: build/
+ Add:
+ - -I\${workspaceFolder}/include"
+
+# Add GTK include paths
+if [ -n "$GTK_INCLUDE_PATHS" ]; then
+ # Process each -I flag separately
+ for flag in $GTK_INCLUDE_PATHS; do
+ if [[ "$flag" == -I* ]]; then
+ path="${flag#-I}"
+ CLANGD_CONTENT="$CLANGD_CONTENT
+ - -I$path"
+ fi
+ done
+fi
+
+# Add Rust include path
+CLANGD_CONTENT="$CLANGD_CONTENT
+ - -I\${workspaceFolder}/../../.temp/target/release
+ Remove: []
+
+Diagnostics:
+ ClangTidy:
+ Add:
+ - \"*\"
+ Remove:
+ - modernize-use-trailing-return-type
+ UnusedIncludes: Strict
+
+Index:
+ Background: Build
+"
+
+# Write .clangd file
+CLANGD_PATH="$PROJECT_ROOT/.clangd"
+echo "$CLANGD_CONTENT" > "$CLANGD_PATH"
+echo "Generated .clangd configuration at: $CLANGD_PATH"
+
+# Source common functions if exists
+if [ -f "$SCRIPT_DIR/_common.sh" ]; then
+ source "$SCRIPT_DIR/_common.sh"
+fi
+
+# Default action
+ACTION="${1:-help}"
+
+case "$ACTION" in
+ "build")
+ echo "Building Butchunker GTK..."
+ "$SCRIPT_DIR/build.sh"
+ ;;
+ "clean")
+ echo "Cleaning Butchunker GTK..."
+ "$SCRIPT_DIR/clean.sh"
+ ;;
+ "run")
+ echo "Running Butchunker GTK..."
+ "$SCRIPT_DIR/run.sh"
+ ;;
+ "help"|*)
+ echo "Butchunker GTK Build System"
+ echo "Usage: $0 [build|clean|run]"
+ echo ""
+ echo "Commands:"
+ echo " build - Build the project"
+ echo " clean - Clean build directory"
+ echo " run - Run the application"
+ exit 0
+ ;;
+esac
diff --git a/gui/gtk/scripts/build.sh b/gui/gtk/scripts/build.sh
new file mode 100755
index 0000000..ae8aebf
--- /dev/null
+++ b/gui/gtk/scripts/build.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+# Butchunker GTK Build Script
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
+BUILD_DIR="$PROJECT_ROOT/build"
+
+# Check if GTK3 is available
+if ! pkg-config --exists gtk+-3.0; then
+ echo "Error: GTK3 development files not found!"
+ echo "Please install GTK3 development packages:"
+ echo " Ubuntu/Debian: sudo apt-get install libgtk-3-dev"
+ echo " Fedora: sudo dnf install gtk3-devel"
+ echo " Arch: sudo pacman -S gtk3"
+ exit 1
+fi
+
+# Create build directory
+mkdir -p "$BUILD_DIR"
+
+# Navigate to build directory
+cd "$BUILD_DIR" || exit 1
+
+# Run CMake
+if ! cmake ..; then
+ exit 1
+fi
+
+# Run make
+if ! make -j$(nproc); then
+ echo "Make failed!"
+ exit 1
+fi
+
+# Check if Rust library exists
+RUST_LIB="$PROJECT_ROOT/../../.temp/target/release/lib_butck.so"
diff --git a/gui/gtk/scripts/clean.sh b/gui/gtk/scripts/clean.sh
new file mode 100755
index 0000000..1c8aa5a
--- /dev/null
+++ b/gui/gtk/scripts/clean.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+# Butchunker GTK Clean Script
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
+BUILD_DIR="$PROJECT_ROOT/build"
+
+# Remove build directory if it exists
+if [ -d "$BUILD_DIR" ]; then
+ rm -rf "$BUILD_DIR"
+fi
+
+# Also clean any other generated files
+
+# Remove CMake cache files if they exist outside build directory
+if [ -f "$PROJECT_ROOT/CMakeCache.txt" ]; then
+ rm -f "$PROJECT_ROOT/CMakeCache.txt"
+fi
+
+if [ -d "$PROJECT_ROOT/CMakeFiles" ]; then
+ rm -rf "$PROJECT_ROOT/CMakeFiles"
+fi
+
+if [ -f "$PROJECT_ROOT/cmake_install.cmake" ]; then
+ rm -f "$PROJECT_ROOT/cmake_install.cmake"
+fi
+
+if [ -f "$PROJECT_ROOT/Makefile" ]; then
+ rm -f "$PROJECT_ROOT/Makefile"
+fi
diff --git a/gui/gtk/scripts/run.sh b/gui/gtk/scripts/run.sh
new file mode 100755
index 0000000..e5f60b7
--- /dev/null
+++ b/gui/gtk/scripts/run.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+# Butchunker GTK Run Script
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
+BUILD_DIR="$PROJECT_ROOT/build"
+EXECUTABLE="$BUILD_DIR/bin/butckg"
+
+# Check if executable exists
+if [ ! -f "$EXECUTABLE" ]; then
+ exit 1
+fi
+
+# Check if executable is executable
+if [ ! -x "$EXECUTABLE" ]; then
+ chmod +x "$EXECUTABLE"
+fi
+
+# Check if Rust library exists and copy it if needed
+RUST_LIB="$PROJECT_ROOT/../../.temp/target/release/lib_butck.so"
+if [ -f "$RUST_LIB" ]; then
+ # Copy library to executable directory if not already there
+ LIB_DEST="$BUILD_DIR/bin/lib_butck.so"
+ if [ ! -f "$LIB_DEST" ] || [ "$RUST_LIB" -nt "$LIB_DEST" ]; then
+ cp "$RUST_LIB" "$LIB_DEST"
+ fi
+fi
+
+# Set LD_LIBRARY_PATH to include the build directory
+export LD_LIBRARY_PATH="$BUILD_DIR/bin:$LD_LIBRARY_PATH"
+
+# Run the executable
+"$EXECUTABLE"
+
+EXIT_CODE=$?
+exit $EXIT_CODE
diff --git a/gui/gtk/src/main.c b/gui/gtk/src/main.c
new file mode 100644
index 0000000..c25715c
--- /dev/null
+++ b/gui/gtk/src/main.c
@@ -0,0 +1,51 @@
+#include <gtk/gtk.h>
+#include <lib_butck.h>
+
+// Callback function for button click
+static void on_button_clicked(GtkWidget *widget, gpointer data) {
+ g_print("Hello, World!\n");
+}
+
+// Callback function for window close
+static void on_window_destroy(GtkWidget *widget, gpointer data) {
+ gtk_main_quit();
+}
+
+int main(int argc, char *argv[]) {
+ GtkWidget *window;
+ GtkWidget *button;
+ GtkWidget *box;
+
+ // Initialize GTK
+ gtk_init(&argc, &argv);
+
+ // Create main window
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(window), "Butchunker - GTK");
+ gtk_window_set_default_size(GTK_WINDOW(window), 400, 300);
+ gtk_container_set_border_width(GTK_CONTAINER(window), 10);
+
+ // Connect destroy signal
+ g_signal_connect(window, "destroy", G_CALLBACK(on_window_destroy), NULL);
+
+ // Create vertical box container
+ box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
+ gtk_container_add(GTK_CONTAINER(window), box);
+
+ // Create label
+ GtkWidget *label = gtk_label_new("Welcome to Butchunker!");
+ gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
+
+ // Create button
+ button = gtk_button_new_with_label("Click Me!");
+ g_signal_connect(button, "clicked", G_CALLBACK(on_button_clicked), NULL);
+ gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
+
+ // Show all widgets
+ gtk_widget_show_all(window);
+
+ // Start GTK main loop
+ gtk_main();
+
+ return 0;
+}
diff --git a/gui/win32/CMakeLists.txt b/gui/win32/CMakeLists.txt
index ac6536d..6a72a2e 100644
--- a/gui/win32/CMakeLists.txt
+++ b/gui/win32/CMakeLists.txt
@@ -3,6 +3,7 @@ project(butckg VERSION 1.0.0 LANGUAGES C RC)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
enable_language(RC)
# Output directory