sail / sail_scripts /kernel /build_kernel.sh
muterornament's picture
Industrialize: Backup sovereign training pipeline and native kernel
0f6a233 verified
Raw
History Blame Contribute Delete
3.64 kB
#!/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 "============================================"