#!/usr/bin/env bash set -euo pipefail VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/') RELEASE_DIR="release/v${VERSION}" BINARY_NAME="mouth" echo "=== Mouth Release Build v${VERSION} ===" echo "" # Ensure we're in the project root if [ ! -f Cargo.toml ]; then echo "ERROR: Must be run from the project root (where Cargo.toml is)" exit 1 fi # Clean previous release artifacts for this version rm -rf "${RELEASE_DIR}" mkdir -p "${RELEASE_DIR}" # Track build results BUILT=() FAILED=() build_target() { local target="$1" local label="$2" local ext="${3:-}" echo "--- Building ${label} (${target}) ---" if cargo build --release --target "${target}" 2>&1; then local binary="target/${target}/release/${BINARY_NAME}${ext}" if [ -f "${binary}" ]; then local archive="${RELEASE_DIR}/${BINARY_NAME}-v${VERSION}-${target}" if [ -n "${ext}" ]; then # Windows: zip local zip_name="${archive}.zip" zip -j "${zip_name}" "${binary}" 2>/dev/null || { # Fallback if zip not installed cp "${binary}" "${archive}${ext}" echo " -> ${archive}${ext}" BUILT+=("${archive}${ext}") return } echo " -> ${zip_name}" BUILT+=("${zip_name}") else # Linux/macOS: tar.gz local tar_name="${archive}.tar.gz" tar -czf "${tar_name}" -C "target/${target}/release" "${BINARY_NAME}" echo " -> ${tar_name}" BUILT+=("${tar_name}") fi else echo " WARN: Binary not found at ${binary}" FAILED+=("${label}") fi else echo " FAILED: ${label}" FAILED+=("${label}") fi echo "" } # ============================================================ # Build targets # ============================================================ # Linux x86_64 (native — always available) build_target "x86_64-unknown-linux-gnu" "Linux x86_64" # Windows x86_64 (MSVC target via cargo-xwin) # ort requires the MSVC target — the GNU/MinGW target has no prebuilt # ONNX Runtime binaries. cargo-xwin cross-compiles using the MSVC # toolchain from Linux without needing a Windows machine. # # Install once: # cargo install cargo-xwin # rustup target add x86_64-pc-windows-msvc # if command -v cargo-xwin &>/dev/null && rustup target list --installed | grep -q x86_64-pc-windows-msvc; then echo "--- Building Windows x86_64 (x86_64-pc-windows-msvc via cargo-xwin) ---" if cargo xwin build --release --target x86_64-pc-windows-msvc 2>&1; then local_binary="target/x86_64-pc-windows-msvc/release/${BINARY_NAME}.exe" if [ -f "${local_binary}" ]; then archive="${RELEASE_DIR}/${BINARY_NAME}-v${VERSION}-x86_64-pc-windows-msvc" zip_name="${archive}.zip" zip -j "${zip_name}" "${local_binary}" 2>/dev/null || { cp "${local_binary}" "${archive}.exe" echo " -> ${archive}.exe" BUILT+=("${archive}.exe") } if [ -f "${zip_name}" ]; then echo " -> ${zip_name}" BUILT+=("${zip_name}") fi else echo " WARN: Binary not found" FAILED+=("Windows x86_64 (MSVC)") fi else echo " FAILED: Windows x86_64 (MSVC)" FAILED+=("Windows x86_64 (MSVC)") fi echo "" else echo "--- Skipping Windows x86_64 ---" echo " cargo-xwin not installed or x86_64-pc-windows-msvc target missing." echo " To enable Windows builds from Linux:" echo " cargo install cargo-xwin" echo " rustup target add x86_64-pc-windows-msvc" echo "" FAILED+=("Windows x86_64 (not configured)") fi # ============================================================ # Summary # ============================================================ echo "=== Build Summary ===" echo "" if [ ${#BUILT[@]} -gt 0 ]; then echo "Successful builds:" for b in "${BUILT[@]}"; do local_size=$(du -h "${b}" | cut -f1) echo " ${b} (${local_size})" done fi if [ ${#FAILED[@]} -gt 0 ]; then echo "" echo "Failed / skipped builds:" for f in "${FAILED[@]}"; do echo " ${f}" done fi echo "" echo "Release artifacts in: ${RELEASE_DIR}/" echo "" # Generate checksums if [ ${#BUILT[@]} -gt 0 ]; then echo "--- Checksums (SHA256) ---" cd "${RELEASE_DIR}" sha256sum * > checksums-sha256.txt 2>/dev/null || shasum -a 256 * > checksums-sha256.txt cat checksums-sha256.txt cd - > /dev/null fi