File size: 3,770 Bytes
ceb9df4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | #!/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
|