#!/bin/bash # Coverage runner script for Foxhunt HFT Trading System # Handles rustc flag incompatibilities with coverage tools set -e echo "🔍 Foxhunt Coverage Analysis" echo "==============================" echo "" # Backup original config if [ -f .cargo/config.toml ]; then echo "📋 Backing up .cargo/config.toml..." cp .cargo/config.toml .cargo/config.toml.coverage-backup fi # Create coverage-compatible config (remove stack-protector flag) echo "⚙️ Creating coverage-compatible config..." cat > .cargo/config.toml << 'EOF' [env] # Fix PostgreSQL authentication errors during compilation # Uses offline sqlx query checking instead of live database connection SQLX_OFFLINE = "true" [build] rustflags = [ "-D", "unsafe_op_in_unsafe_fn", "-D", "clippy::undocumented_unsafe_blocks", "-W", "rust_2024_idioms", "-C", "force-frame-pointers=yes", # Note: stack-protector flag removed for coverage tool compatibility "-C", "relocation-model=pic", ] [target.x86_64-unknown-linux-gnu] rustflags = [ "-C", "link-arg=-Wl,-z,relro,-z,now", "-C", "link-arg=-Wl,--as-needed", # CRITICAL HFT PERFORMANCE FLAGS - FIXES SIMD 10,000x REGRESSION "-C", "target-cpu=native", "-C", "target-feature=+avx2,+fma,+bmi2", "-C", "opt-level=3", "-C", "codegen-units=1", ] # Profile-specific optimizations for maximum SIMD performance [profile.release] opt-level = 3 lto = "fat" codegen-units = 1 panic = "abort" strip = false debug = false overflow-checks = false # Benchmarking profile with SIMD optimizations [profile.bench] inherits = "release" debug = false # HFT-specific profile for production with aggressive SIMD optimization [profile.hft] inherits = "release" opt-level = 3 lto = "fat" codegen-units = 1 panic = "abort" strip = false overflow-checks = false EOF # Cleanup function cleanup() { echo "" echo "🔄 Restoring original config..." if [ -f .cargo/config.toml.coverage-backup ]; then mv .cargo/config.toml.coverage-backup .cargo/config.toml echo "✅ Config restored" fi } # Ensure cleanup on exit trap cleanup EXIT INT TERM # Run coverage tool echo "" echo "🚀 Running cargo-tarpaulin..." echo "" cargo tarpaulin \ --workspace \ --timeout 600 \ --out Xml \ --output-dir coverage/ \ --force-clean \ "$@" EXIT_CODE=$? if [ $EXIT_CODE -eq 0 ]; then echo "" echo "✅ Coverage analysis complete!" echo "📊 Report saved to: coverage/cobertura.xml" else echo "" echo "❌ Coverage analysis failed with exit code: $EXIT_CODE" fi exit $EXIT_CODE