Files
mev-beta/scripts/build.sh
Krypto Kajun 850223a953 fix(multicall): resolve critical multicall parsing corruption issues
- Added comprehensive bounds checking to prevent buffer overruns in multicall parsing
- Implemented graduated validation system (Strict/Moderate/Permissive) to reduce false positives
- Added LRU caching system for address validation with 10-minute TTL
- Enhanced ABI decoder with missing Universal Router and Arbitrum-specific DEX signatures
- Fixed duplicate function declarations and import conflicts across multiple files
- Added error recovery mechanisms with multiple fallback strategies
- Updated tests to handle new validation behavior for suspicious addresses
- Fixed parser test expectations for improved validation system
- Applied gofmt formatting fixes to ensure code style compliance
- Fixed mutex copying issues in monitoring package by introducing MetricsSnapshot
- Resolved critical security vulnerabilities in heuristic address extraction
- Progress: Updated TODO audit from 10% to 35% complete

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-17 00:12:55 -05:00

102 lines
2.9 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Reusable, agnostic build script
# Can be used in any Go project by adjusting configuration
# Configuration variables
BINARY_NAME="${BINARY_NAME:-$(basename $(pwd))}"
BINARY_DIR="${BINARY_DIR:-bin}"
MAIN_FILE="${MAIN_FILE:-cmd/mev-bot/main.go}"
BUILD_TAGS="${BUILD_TAGS:-}"
LDFLAGS="${LDFLAGS:-}"
OUTPUT="${OUTPUT:-$BINARY_DIR/$BINARY_NAME}"
GOOS="${GOOS:-$(go env GOOS)}"
GOARCH="${GOARCH:-$(go env GOARCH)}"
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-n|--name)
BINARY_NAME="$2"
shift 2
;;
-o|--output)
OUTPUT="$2"
shift 2
;;
-m|--main)
MAIN_FILE="$2"
shift 2
;;
-t|--tags)
BUILD_TAGS="$2"
shift 2
;;
-l|--ldflags)
LDFLAGS="$2"
shift 2
;;
--goos)
GOOS="$2"
shift 2
;;
--goarch)
GOARCH="$2"
shift 2
;;
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo "Build a Go application with configurable options"
echo ""
echo "Options:"
echo " -n, --name NAME Binary name (default: current directory name)"
echo " -o, --output PATH Output path (default: bin/BINARY_NAME)"
echo " -m, --main PATH Main package path (default: .)"
echo " -t, --tags TAGS Build tags"
echo " -l, --ldflags FLAGS Ldflags to pass to go build"
echo " --goos OS Target OS (default: $(go env GOOS))"
echo " --goarch ARCH Target architecture (default: $(go env GOARCH))"
echo " -h, --help Show this help"
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
echo "Building $BINARY_NAME for $GOOS/$GOARCH..."
# Ensure local Go cache directories exist when not provided
PROJECT_ROOT="$(pwd)"
if [[ -z "${GOCACHE:-}" ]]; then
export GOCACHE="${PROJECT_ROOT}/.gocache"
fi
if [[ -z "${GOMODCACHE:-}" ]]; then
export GOMODCACHE="${PROJECT_ROOT}/.gomodcache"
fi
if [[ -z "${GOPATH:-}" ]]; then
export GOPATH="${PROJECT_ROOT}/.gopath"
fi
if [[ -z "${GOFLAGS:-}" && -d "${PROJECT_ROOT}/vendor" ]]; then
export GOFLAGS="-mod=vendor"
fi
mkdir -p "$GOCACHE" "$GOMODCACHE" "${GOPATH}/pkg/mod"
# Create binary directory
mkdir -p "$(dirname "$OUTPUT")"
# Set environment variables for cross-compilation
export GOOS="$GOOS"
export GOARCH="$GOARCH"
# Build the application
echo "go build -o $OUTPUT $BUILD_TAGS:+-tags $BUILD_TAGS $LDFLAGS:+-ldflags $LDFLAGS $MAIN_FILE"
go build -o "$OUTPUT" ${BUILD_TAGS:+-tags "$BUILD_TAGS"} ${LDFLAGS:+-ldflags "$LDFLAGS"} "$MAIN_FILE"
echo "Build completed successfully!"
echo "Binary: $OUTPUT"