File size: 3,638 Bytes
0f6a233
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# ============================================================
# SAIL Kernel β€” Build Script
# Compiles the Rust kernel and installs it into system Python.
# Run from WSL: bash sail/kernel/build_kernel.sh
# ============================================================

set -e  # Exit immediately on any error

KERNEL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WHEEL_DIR="$KERNEL_DIR/target/wheels"

echo "============================================"
echo "  SAIL Memory-Safe Rust Kernel β€” Build"
echo "============================================"
echo ""

# ── Check dependencies ────────────────────────────────────────
echo "[1/4] Checking dependencies..."

if ! command -v cargo &>/dev/null; then
    echo "  βœ— cargo not found. Loading rustup environment..."
    source "$HOME/.cargo/env" 2>/dev/null || {
        echo "  βœ— Rust not installed. Run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash"
        exit 1
    }
fi

RUST_VER=$(rustc --version)
echo "  βœ“ Rust: $RUST_VER"

if ! /mnt/e/agent/agent_ai/sail/ai_env/bin/python -m maturin --version &>/dev/null; then
    echo "  Installing maturin in ai_env..."
    /mnt/e/agent/agent_ai/sail/ai_env/bin/python -m pip install maturin pyarrow zstandard --quiet
fi
MATURIN_VER=$(/mnt/e/agent/agent_ai/sail/ai_env/bin/python -m maturin --version)
echo "  βœ“ maturin: $MATURIN_VER"

# ── Build release wheel ───────────────────────────────────────
echo ""
echo "[2/4] Building release wheel..."
cd "$KERNEL_DIR"

VIRTUAL_ENV='/mnt/e/agent/agent_ai/sail/ai_env' PYO3_PYTHON=/mnt/e/agent/agent_ai/sail/ai_env/bin/python /mnt/e/agent/agent_ai/sail/ai_env/bin/python -m maturin build --release 2>&1

# ── Find wheel ────────────────────────────────────────────────
echo ""
echo "[3/4] Locating wheel..."
WHEEL=$(ls "$WHEEL_DIR"/sail_kernel-*.whl 2>/dev/null | head -1)

if [ -z "$WHEEL" ]; then
    echo "  βœ— No wheel found in $WHEEL_DIR"
    exit 1
fi
echo "  βœ“ Wheel: $(basename $WHEEL)"

# ── Install wheel ─────────────────────────────────────────────
echo ""
echo "[4/4] Installing into ai_env Python..."
source /mnt/e/agent/agent_ai/sail/ai_env/bin/activate
/mnt/e/agent/agent_ai/sail/ai_env/bin/python -m pip install "$WHEEL" --force-reinstall --quiet
echo "  βœ“ Installed sail_kernel in ai_env"

# ── Quick smoke test ──────────────────────────────────────────
echo ""
echo "── Smoke Test ───────────────────────────────"
python -c "
import sail_kernel
print('  version:', sail_kernel.__version__)
print('  clean_text OK:', sail_kernel.clean_text('<b>Hello</b>'))
print('  token_budget(2 marks):', sail_kernel.compute_budget('Define X. [2 marks]'))
print('  token_budget(8 marks):', sail_kernel.compute_budget('Explain Y (8 marks)'))
score = sail_kernel.score_output('## Ans\n\n**Key**: text\n\n- item 1', 300)
print('  reward_scorer total:', round(score.total_score, 3))
print()
print('  All tests PASSED! βœ“')
"

echo ""
echo "============================================"
echo "  SAIL Kernel built and ready."
echo "  Import with: import sail_kernel"
echo "============================================"