#!/usr/bin/env bash # ============================================================================== # nx9-wg Production Release Builder # ============================================================================== # PURPOSE: # Runs release quality gates and compiles an optimized release binary: # 1. Format verification # 2. Check & Clippy (-D warnings) # 3. Full workspace test suite # 4. Release build (cargo build --release --workspace) # 5. Artifact verification (binary size, permissions, SHA-256) # # PREREQUISITES: # - Rust toolchain (stable) # - Linux C build tools (libsqlite3 / pkg-config / ldd) # # BEHAVIOR: # - Non-destructive to existing deployments. # - Does NOT run 'cargo clean' to prevent accidental removal of release artifacts. # - Produces target/release/nx9-wg. # # USAGE: # bash scripts/build-release.sh # ./scripts/build-release.sh # ============================================================================== set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" log() { echo -e "\n\033[1;34m[RELEASE-BUILD]\033[0m \033[1;37m$*\033[0m" } success() { echo -e "\033[1;32m[PASS]\033[0m $*" } error() { echo -e "\033[1;31m[ERROR]\033[0m $*" >&2 exit 1 } cd "${ROOT_DIR}" log "1/4 Verifying code formatting..." cargo fmt --all -- --check || error "Formatting verification failed." success "Formatting verified." log "2/4 Running compiler and Clippy checks..." cargo check --workspace --all-targets || error "Cargo check failed." cargo clippy --workspace --all-targets --all-features -- -D warnings || error "Clippy check failed." success "Lint checks passed with 0 warnings." log "3/4 Running full workspace test suite..." cargo test --workspace --all-targets || error "Workspace test suite failed." success "All unit and integration tests passed." log "4/4 Compiling optimized release binary (cargo build --release --workspace)..." cargo build --release --workspace || error "Release build failed." TARGET_BIN="${ROOT_DIR}/target/release/nx9-wg" if [[ ! -f "${TARGET_BIN}" ]]; then error "Expected release binary not found at ${TARGET_BIN}" fi if [[ ! -x "${TARGET_BIN}" ]]; then error "Release binary is not executable at ${TARGET_BIN}" fi BIN_SIZE="$(du -h "${TARGET_BIN}" | cut -f1)" BIN_SHA="$(sha256sum "${TARGET_BIN}" | awk '{print $1}')" BIN_DATE="$(date -r "${TARGET_BIN}" '+%Y-%m-%d %H:%M:%S')" echo -e "\n=================================================================" echo -e "\033[1;32m RELEASE BUILD SUCCESSFUL!\033[0m" echo -e "=================================================================" echo " Binary Path: ${TARGET_BIN}" echo " Binary Size: ${BIN_SIZE}" echo " Timestamp: ${BIN_DATE}" echo " SHA-256: ${BIN_SHA}" echo " Version: $("${TARGET_BIN}" version | head -n 1)" echo -e "=================================================================\n"