#!/bin/bash set -e PROFILE="release" CARGO_FLAGS="--release" if [ "$1" = "debug" ] || [ "$1" = "--debug" ]; then PROFILE="debug" CARGO_FLAGS="" echo "=== Compiling plugins in DEBUG mode ===" else echo "=== Compiling plugins in RELEASE mode ===" fi PROJECT_DIR="/mnt/extra/00_PROJECTS/hcie-rust-v4" PLUGINS_DIR="$PROJECT_DIR/plugins" BUILD_LIB_DIR="$PROJECT_DIR/build/lib" mkdir -p "$PLUGINS_DIR" echo "=== Building AI/Vision dynamic libraries ===" echo "1. Building hcie-ai..." cargo build --manifest-path "$PROJECT_DIR/hcie-ai/Cargo.toml" $CARGO_FLAGS --features ffi cp "$PROJECT_DIR/target/$PROFILE/libhcie_ai.so" "$PLUGINS_DIR/" echo "2. Building hcie-vision..." cargo build --manifest-path "$PROJECT_DIR/hcie-vision/Cargo.toml" $CARGO_FLAGS --features ffi cp "$PROJECT_DIR/target/$PROFILE/libhcie_vision.so" "$PLUGINS_DIR/" # Copy the C++ backend runtime dependencies next to the plugin so the dynamic # loader finds them without extra LD_LIBRARY_PATH setup. for lib in libvisioncpp.so libvisioncpp.so.0 libvisioncpp.so.0.3.1 \ libggml.so libggml.so.0 libggml.so.0.9.9 \ libggml-cpu.so libggml-cpu.so.0 libggml-cpu.so.0.9.9 \ libggml-base.so libggml-base.so.0 libggml-base.so.0.9.9; do if [ -f "$PROJECT_DIR/target/$PROFILE/$lib" ]; then cp -L "$PROJECT_DIR/target/$PROFILE/$lib" "$PLUGINS_DIR/" elif [ -f "$BUILD_LIB_DIR/$lib" ]; then cp -L "$BUILD_LIB_DIR/$lib" "$PLUGINS_DIR/" fi done # Ensure the backend libraries can still find each other when loaded from the # plugins directory by making their RUNPATH point to the canonical build/lib. if command -v patchelf >/dev/null 2>&1; then for lib in libvisioncpp.so.0 libggml.so.0 libggml-cpu.so.0 libggml-base.so.0; do if [ -f "$PLUGINS_DIR/$lib" ]; then patchelf --set-rpath "$BUILD_LIB_DIR" "$PLUGINS_DIR/$lib" || true fi done fi echo "====================================================" echo "AI/Vision plugins built and copied to $PLUGINS_DIR successfully in $PROFILE mode!" echo "===================================================="