Add macOS and Windows build scripts

parent c51704c4
......@@ -128,6 +128,22 @@ source venv_all/bin/activate
python coderai # starts on http://127.0.0.1:8776
```
macOS:
```bash
./osxbuild.sh all
source venv_osx_all/bin/activate
python coderai
```
Windows PowerShell:
```powershell
.\build.ps1 -Backend all
.\venv_win_all\Scripts\Activate.ps1
python coderai
```
That's it. Open `http://127.0.0.1:8776/admin` and log in with `admin` / `admin`.
---
......@@ -152,8 +168,43 @@ cd coderai
./build.sh vulkan # AMD/Intel only
```
Platform-specific alternatives:
```bash
./osxbuild.sh all # macOS, prefers Metal-backed builds when available
```
```powershell
.\build.ps1 -Backend all # Windows, prefers CUDA-backed builds when available
```
The build script creates a virtual environment, installs dependencies, and builds GPU-accelerated backends including `stable-diffusion-cpp-python` with CUDA+Vulkan support.
Platform backend notes:
- Linux: CUDA for NVIDIA, Vulkan for AMD/Intel/NVIDIA, OpenCL fallback where supported.
- macOS: Metal is the correct GPU acceleration path instead of CUDA. `osxbuild.sh` uses PyTorch MPS plus `GGML_METAL` / `SD_METAL` builds where available.
- Windows: CUDA remains the primary NVIDIA acceleration path. `build.ps1` focuses on CUDA or CPU installs.
- There is no general-purpose CUDA workflow for current macOS systems; Apple GPU acceleration uses Metal.
### Platform Support Matrix
| Capability | Linux | macOS | Windows |
|---|---|---|---|
| Core server / admin UI | Yes | Yes | Yes |
| Default path handling | Yes | Yes | Yes |
| PyTorch GPU acceleration | CUDA | Metal (MPS) | CUDA |
| `llama-cpp-python` GPU path | CUDA / Vulkan | Metal | CUDA |
| `stable-diffusion-cpp-python` GPU path | CUDA / Vulkan / OpenCL | Metal | CUDA |
| `whisper.cpp` accelerated path | Vulkan / CPU fallback | Metal / CPU fallback | CPU fallback |
| InsightFace / ONNX runtime | `onnxruntime-gpu` | `onnxruntime-silicon` or CPU | `onnxruntime-gpu` |
| Build script included in repo | `build.sh` | `osxbuild.sh` | `build.ps1` |
Notes:
- "Yes" means CoderAI has an intended path for that platform, not that every optional dependency is guaranteed to install on every machine.
- macOS GPU acceleration is Metal-based; there is no standard modern CUDA path for macOS.
- Windows currently uses CUDA as the main NVIDIA acceleration path; Vulkan/OpenCL build flows are not the primary Windows setup in this repository.
- Some optional audio and media packages may still vary by Python version, hardware, and upstream wheel availability.
### Manual Installation
```bash
......
param(
[string]$Backend = "all",
[string]$Venv = ""
)
$ErrorActionPreference = "Stop"
$Backend = $Backend.ToLowerInvariant()
$validBackends = @("cuda", "cpu", "all")
if ($validBackends -notcontains $Backend) {
throw "Invalid backend '$Backend'. Use one of: cuda, cpu, all"
}
function Write-Info($msg) { Write-Host $msg -ForegroundColor Cyan }
function Write-Warn($msg) { Write-Host $msg -ForegroundColor Yellow }
function Write-Ok($msg) { Write-Host $msg -ForegroundColor Green }
Write-Info "========================================"
Write-Info " CoderAI Windows Build Script"
Write-Info " Backend: $Backend"
Write-Info "========================================"
$python = if (Get-Command py -ErrorAction SilentlyContinue) { "py" } else { "python" }
$pythonArgs = if ($python -eq "py") { @("-3") } else { @() }
if ([string]::IsNullOrWhiteSpace($Venv)) {
switch ($Backend) {
"cuda" { $Venv = "venv_win_cuda" }
"cpu" { $Venv = "venv_win_cpu" }
default { $Venv = "venv_win_all" }
}
}
if (-not (Test-Path $Venv)) {
Write-Info "Creating virtual environment: $Venv"
& $python @pythonArgs -m venv $Venv
} else {
Write-Warn "Using existing virtual environment: $Venv"
}
$venvPython = Join-Path $Venv "Scripts\python.exe"
$venvActivate = Join-Path $Venv "Scripts\Activate.ps1"
& $venvPython -m pip install --upgrade pip setuptools wheel
& $venvPython -m pip install -r requirements.txt
function Install-CommonMLStack {
& $venvPython -m pip install "imageio[ffmpeg]" scipy soundfile sentence-transformers openai-whisper argostranslate edge-tts kokoro-tts timm
& $venvPython -m pip install realesrgan basicsr
& $venvPython -m pip install demucs deepfilternet rnnoise voicefixer
& $venvPython -m pip install insightface onnxruntime-gpu
& $venvPython -m pip install f5-tts seed-vc
try { & $venvPython -m pip install audiocraft } catch { Write-Warn "audiocraft install failed; continuing" }
}
function Install-CudaStack {
Write-Info "Installing PyTorch with CUDA support..."
& $venvPython -m pip install torch torchvision torchaudio
Write-Info "Installing NVIDIA-specific requirements..."
try { & $venvPython -m pip install -r requirements-nvidia.txt } catch { Write-Warn "Some NVIDIA-specific packages failed; continuing" }
Write-Info "Installing llama-cpp-python with CUDA support..."
$env:CMAKE_ARGS = "-DGGML_CUDA=ON"
try { & $venvPython -m pip install --upgrade llama-cpp-python --no-cache-dir } finally { Remove-Item Env:CMAKE_ARGS -ErrorAction SilentlyContinue }
Write-Info "Installing stable-diffusion-cpp-python with CUDA support..."
$env:CMAKE_ARGS = "-DSD_CUDA=ON -DSD_WEBM=OFF"
try { & $venvPython -m pip install stable-diffusion-cpp-python --no-cache-dir } catch { Write-Warn "stable-diffusion-cpp-python CUDA build failed; continuing" } finally { Remove-Item Env:CMAKE_ARGS -ErrorAction SilentlyContinue }
}
function Install-CpuStack {
Write-Info "Installing CPU-oriented runtime..."
& $venvPython -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
& $venvPython -m pip install --upgrade llama-cpp-python
try { & $venvPython -m pip install stable-diffusion-cpp-python } catch { Write-Warn "stable-diffusion-cpp-python CPU install failed; continuing" }
try { & $venvPython -m pip install onnxruntime } catch { Write-Warn "onnxruntime CPU install failed; continuing" }
}
switch ($Backend) {
"cuda" {
Install-CudaStack
Install-CommonMLStack
}
"cpu" {
Install-CpuStack
Install-CommonMLStack
}
default {
Install-CudaStack
Install-CommonMLStack
}
}
Set-Content -Path ".backend" -Value $Backend
Write-Ok "Build completed successfully!"
Write-Host ""
Write-Host "To activate the environment in the future, run:"
Write-Host " $venvActivate"
Write-Host ""
Write-Host "Recommended runtime notes:"
Write-Host " - Windows keeps CUDA as the primary NVIDIA acceleration path"
Write-Host " - Metal is macOS-only and not used on Windows"
#!/bin/bash
# CoderAI macOS build script
# Usage: ./osxbuild.sh [metal|cpu|all] [--venv <venv>]
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
BACKEND="${1:-all}"
CUSTOM_VENV=""
i=1
for arg in "$@"; do
case $arg in
--venv)
i=$((i + 1))
eval "CUSTOM_VENV=\${$i}"
;;
esac
i=$((i + 1))
done
BACKEND=$(echo "$BACKEND" | tr '[:upper:]' '[:lower:]')
if [[ "$BACKEND" != "metal" && "$BACKEND" != "cpu" && "$BACKEND" != "all" ]]; then
echo -e "${RED}Error: Invalid backend '$BACKEND'${NC}"
echo "Usage: ./osxbuild.sh [metal|cpu|all] [--venv <venv>]"
exit 1
fi
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} CoderAI macOS Build Script${NC}"
echo -e "${BLUE} Backend: ${GREEN}$BACKEND${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
PYTHON_BIN="${PYTHON_BIN:-python3}"
PYTHON_VERSION=$($PYTHON_BIN --version 2>&1 | python3 -c 'import sys,re; print(re.search(r"(\d+\.\d+)", sys.stdin.read()).group(1))')
echo -e "${GREEN}✓ Python version: $PYTHON_VERSION${NC}"
if [ -n "$CUSTOM_VENV" ]; then
VENV_DIR="$CUSTOM_VENV"
elif [ "$BACKEND" = "metal" ]; then
VENV_DIR="venv_osx_metal"
elif [ "$BACKEND" = "cpu" ]; then
VENV_DIR="venv_osx_cpu"
else
VENV_DIR="venv_osx_all"
fi
if [ ! -d "$VENV_DIR" ]; then
echo -e "${YELLOW}Creating virtual environment: $VENV_DIR${NC}"
"$PYTHON_BIN" -m venv "$VENV_DIR"
else
echo -e "${YELLOW}Using existing virtual environment: $VENV_DIR${NC}"
fi
source "$VENV_DIR/bin/activate"
export PIP_NO_INPUT=1
export PIP_REQUIRE_VIRTUALENV=1
python -m pip install --upgrade pip setuptools wheel
python -m pip install -r requirements.txt
install_common_ml_stack() {
python -m pip install "imageio[ffmpeg]" scipy soundfile sentence-transformers openai-whisper argostranslate edge-tts kokoro-tts timm || true
python -m pip install realesrgan basicsr || true
python -m pip install demucs deepfilternet rnnoise voicefixer || true
python -m pip install insightface onnxruntime-silicon || python -m pip install insightface onnxruntime || true
python -m pip install f5-tts seed-vc || true
python -m pip install audiocraft || true
}
install_metal_stack() {
echo -e "${YELLOW}Installing PyTorch with Apple Silicon / MPS support...${NC}"
python -m pip install torch torchvision torchaudio
echo -e "${YELLOW}Installing llama-cpp-python with Metal support...${NC}"
CMAKE_ARGS="-DGGML_METAL=ON" python -m pip install --upgrade llama-cpp-python --no-cache-dir || {
echo -e "${YELLOW}Warning: Metal build failed, installing CPU llama-cpp-python${NC}"
python -m pip install --upgrade llama-cpp-python
}
echo -e "${YELLOW}Installing stable-diffusion-cpp-python with Metal support...${NC}"
CMAKE_ARGS="-DSD_METAL=ON -DSD_WEBM=OFF" python -m pip install stable-diffusion-cpp-python --no-cache-dir || {
echo -e "${YELLOW}Warning: Metal stable-diffusion-cpp-python not available${NC}"
}
echo -e "${YELLOW}Installing whispercpp with Metal support when possible...${NC}"
python -m pip uninstall -y whispercpp >/dev/null 2>&1 || true
TMP_DIR="${TMPDIR:-/tmp}/coderai-whispercpp"
rm -rf "$TMP_DIR"
git clone --depth 1 https://github.com/ggerganov/whisper.cpp "$TMP_DIR" >/dev/null 2>&1 || true
if [ -d "$TMP_DIR/bindings/python" ]; then
(cd "$TMP_DIR/bindings/python" && CMAKE_ARGS="-DWHISPER_METAL=ON -DGGML_METAL=ON" python -m pip install . --no-cache-dir --force-reinstall) || \
(cd "$TMP_DIR/bindings/python" && python -m pip install . --no-cache-dir --force-reinstall) || true
fi
}
install_cpu_stack() {
echo -e "${YELLOW}Installing CPU-only runtime...${NC}"
python -m pip install torch torchvision torchaudio
python -m pip install --upgrade llama-cpp-python
python -m pip install stable-diffusion-cpp-python || true
}
if [ "$BACKEND" = "metal" ]; then
install_metal_stack
install_common_ml_stack
elif [ "$BACKEND" = "cpu" ]; then
install_cpu_stack
install_common_ml_stack
else
install_metal_stack
install_common_ml_stack
fi
echo "$BACKEND" > .backend
echo -e "${GREEN}Build completed successfully!${NC}"
echo ""
echo "To activate the environment in the future, run:"
echo " source $VENV_DIR/bin/activate"
echo ""
echo "Recommended runtime notes:"
echo " - macOS uses Metal (MPS / GGML_METAL / SD_METAL) instead of CUDA"
echo " - NVIDIA CUDA is not the standard macOS path"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment