#!/usr/bin/env bash # Cross-platform build script for BEX Engine # Targets GLIBC 2.31+ (Ubuntu 20.04 / Debian 11 / most modern distros) # # Strategy: Use musl-static or manylinux2_28 build environment # This ensures the resulting binary works on: # - Ubuntu 20.04+ # - Debian 11+ # - Fedora 34+ # - Alpine (musl) # - RHEL 8+ # - Any system with GLIBC >= 2.28 # # Usage: # ./build-portable.sh # Build dynamically linked (GLIBC 2.28+) # ./build-portable.sh --musl # Build fully static (no GLIBC dependency) # ./build-portable.sh --docker # Build in Docker for reproducibility set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" BUILD_MODE="${1:-dynamic}" OUTPUT_DIR="dist" mkdir -p "$OUTPUT_DIR" echo "=== BEX Engine Portable Build ===" echo "Mode: $BUILD_MODE" echo "" case "$BUILD_MODE" in --musl|musl) echo "Building fully static binary (musl)..." echo "This produces a binary with ZERO system library dependencies." echo "" # Ensure musl target is installed rustup target add x86_64-unknown-linux-musl 2>/dev/null || true # Build with musl (fully static) RUSTFLAGS="-C target-feature=+crt-static" \ cargo build --release --target x86_64-unknown-linux-musl cp target/x86_64-unknown-linux-musl/release/bex "$OUTPUT_DIR/bex" cp target/x86_64-unknown-linux-musl/release/libbex_runtime.a "$OUTPUT_DIR/libbex_runtime.a" echo "" echo "Built static binary: $OUTPUT_DIR/bex" echo "No GLIBC dependency — runs on any Linux x86_64" ;; --docker|docker) echo "Building in Docker (manylinux2_28 / GLIBC 2.28)..." echo "This produces a binary compatible with all modern Linux distros." echo "" # Use a Debian 11 (Bullseye) based image for GLIBC 2.31 docker run --rm -v "$SCRIPT_DIR:/src" -w /src \ rust:1.79-bullseye \ bash -c ' apt-get update -qq && apt-get install -y -qq pkg-config libssl-dev >/dev/null 2>&1 cargo build --release cp target/release/bex /src/dist/bex cp target/release/libbex_runtime.so /src/dist/libbex_runtime.so 2>/dev/null || true cp target/release/libbex_runtime.a /src/dist/libbex_runtime.a 2>/dev/null || true ' echo "" echo "Built with GLIBC 2.31 (Debian 11 Bullseye)" echo "Compatible with: Ubuntu 20.04+, Debian 11+, Fedora 34+, RHEL 8+" ;; *) echo "Building with system toolchain..." echo "" cargo build --release cp target/release/bex "$OUTPUT_DIR/bex" 2>/dev/null || true cp target/release/libbex_runtime.so "$OUTPUT_DIR/libbex_runtime.so" 2>/dev/null || true cp target/release/libbex_runtime.a "$OUTPUT_DIR/libbex_runtime.a" 2>/dev/null || true # Check GLIBC version requirement if command -v objdump &>/dev/null; then echo "" echo "GLIBC version requirements:" objdump -T "$OUTPUT_DIR/bex" 2>/dev/null | grep GLIBC_ | sed 's/.*GLIBC_/GLIBC_/' | sort -Vu || true fi ;; esac echo "" echo "=== Build Complete ===" ls -la "$OUTPUT_DIR/bex" "$OUTPUT_DIR/libbex_runtime"* 2>/dev/null echo "" # Verify the binary if [ -f "$OUTPUT_DIR/bex" ]; then echo "Binary info:" file "$OUTPUT_DIR/bex" 2>/dev/null || true echo "" # Quick sanity test if "$OUTPUT_DIR/bex" --help >/dev/null 2>&1; then echo "✓ Binary runs successfully on this system" else echo "⚠ Binary may not run on this system (different GLIBC)" echo " Use --musl for a fully static build, or --docker for GLIBC 2.31" fi fi