#!/bin/bash set -e # Cross-compilation build script for AVIF Maker # Uses Docker directly (not cross tool) for Apple Silicon compatibility SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" cd "$PROJECT_DIR" VERSION=${1:-$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')} DIST_DIR="dist/$VERSION" # Handle --setup-docker flag if [[ "$1" == "--setup-docker" ]]; then echo "Building Docker images for cross-compilation..." echo "" echo "Building Linux x86_64 image..." docker build --platform linux/amd64 -t avif-maker-linux-x86_64 -f docker/Dockerfile.linux-x86_64 . echo "" echo "Building Linux ARM64 image..." docker build --platform linux/amd64 -t avif-maker-linux-arm64 -f docker/Dockerfile.linux-arm64 . echo "" echo "Building Windows x86_64 image..." docker build --platform linux/amd64 -t avif-maker-windows-x86_64 -f docker/Dockerfile.windows-x86_64 . echo "" echo "Docker images built successfully!" echo "You can now run: ./scripts/build-all.sh" exit 0 fi mkdir -p "$DIST_DIR" echo "Building AVIF Maker v$VERSION" echo "================================" # Check if Docker images exist if ! docker image inspect avif-maker-linux-x86_64 >/dev/null 2>&1; then echo "Docker images not found. Run './scripts/build-all.sh --setup-docker' first." exit 1 fi # Linux x86_64 echo "" echo "Building and packaging Linux x86_64..." docker run --rm --platform linux/amd64 \ -v "$PROJECT_DIR:/build" \ -w /build \ avif-maker-linux-x86_64 \ bash -c " set -e echo 'Compiling...' cargo build --release --target x86_64-unknown-linux-gnu echo 'Stripping binary...' strip target/x86_64-unknown-linux-gnu/release/avif-maker echo 'Creating .deb package...' cargo deb --target x86_64-unknown-linux-gnu --no-build -o dist/$VERSION/ echo 'Creating .rpm package...' cargo generate-rpm --target x86_64-unknown-linux-gnu -o dist/$VERSION/ " # Create tarball (can run on host) echo "Creating tarball..." tar -czvf "$DIST_DIR/avif-maker-$VERSION-linux-x86_64.tar.gz" \ -C target/x86_64-unknown-linux-gnu/release avif-maker # Linux ARM64 # NOTE: ARM64 cross-compilation is currently disabled due to upstream zune-jpeg NEON bug. # Build ARM64 natively on a Linux ARM64 system instead. echo "" echo "Skipping Linux ARM64 (upstream zune-jpeg bug with NEON cross-compilation)" echo "To build ARM64, run natively on a Linux ARM64 system." # Windows x86_64 echo "" echo "Building Windows x86_64..." docker run --rm --platform linux/amd64 \ -v "$PROJECT_DIR:/build" \ -w /build \ avif-maker-windows-x86_64 \ cargo build --release --target x86_64-pc-windows-gnu zip -j "$DIST_DIR/avif-maker-$VERSION-windows-x86_64.zip" \ target/x86_64-pc-windows-gnu/release/avif-maker.exe # macOS (native build) echo "" echo "Building macOS..." cargo build --release # Create .app bundle echo "Creating .app bundle..." cargo bundle --release # Find the .app bundle APP_PATH="target/release/bundle/osx/AVIF Maker.app" if [[ -d "$APP_PATH" ]]; then # Create DMG echo "Creating DMG..." DMG_NAME="avif-maker-$VERSION-macos.dmg" rm -f "$DIST_DIR/$DMG_NAME" hdiutil create -volname "AVIF Maker" -srcfolder "$APP_PATH" -ov -format UDZO "$DIST_DIR/$DMG_NAME" # Also create a zip of the .app for those who prefer it echo "Creating .app zip..." (cd "target/release/bundle/osx" && zip -r "../../../../$DIST_DIR/avif-maker-$VERSION-macos.app.zip" "AVIF Maker.app") else echo "Warning: .app bundle not found at expected path" fi echo "" echo "================================" echo "Build complete! Artifacts in $DIST_DIR/" echo "" ls -la "$DIST_DIR/"