#!/bin/bash # Unified build script for RLogg # Usage: ./build.sh [linux|windows] # If no argument is provided, builds for both Linux and Windows. set -e # Configuration DIST_DIR="dist" VERSION=$(grep -m1 '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/') LINUX_TARGET="x86_64-unknown-linux-gnu" WINDOWS_TARGET="x86_64-pc-windows-gnu" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color echo "RLogg Builder v$VERSION" echo "======================" mkdir -p "$DIST_DIR" check_cross() { if ! command -v cross &> /dev/null; then echo -e "${YELLOW}Installing 'cross' for cross-compilation...${NC}" cargo install cross --git https://github.com/cross-rs/cross fi } build_linux() { echo -e "${BLUE}=== Building for Linux ($LINUX_TARGET) ===${NC}" if cargo build --release --target "$LINUX_TARGET"; then cp "target/$LINUX_TARGET/release/rlogg" "$DIST_DIR/rlogg-$VERSION-linux-x86_64" strip "$DIST_DIR/rlogg-$VERSION-linux-x86_64" 2>/dev/null || true echo -e "${GREEN}✓ Linux build success: $DIST_DIR/rlogg-$VERSION-linux-x86_64${NC}" else echo -e "${RED}✗ Linux build failed${NC}" return 1 fi } build_windows() { echo -e "${BLUE}=== Building for Windows ($WINDOWS_TARGET) ===${NC}" check_cross # Clean specific target to avoid conflicts # cargo clean --release --target "$WINDOWS_TARGET" 2>/dev/null || true if cross build --release --target "$WINDOWS_TARGET"; then cp "target/$WINDOWS_TARGET/release/rlogg.exe" "$DIST_DIR/rlogg-$VERSION-windows-x86_64.exe" echo -e "${GREEN}✓ Windows build success: $DIST_DIR/rlogg-$VERSION-windows-x86_64.exe${NC}" else echo -e "${RED}✗ Windows build failed${NC}" return 1 fi } # Main logic if [ $# -eq 0 ]; then echo "No target specified, building for ALL platforms..." build_linux build_windows else case "$1" in linux) build_linux ;; windows|win) build_windows ;; *) echo "Usage: $0 [linux|windows]" exit 1 ;; esac fi echo "" echo -e "${GREEN}Build process completed.${NC}" ls -lh "$DIST_DIR"