Add cross-platform packaging build option

parent dc379f3e
......@@ -178,6 +178,30 @@ Platform-specific alternatives:
.\build.ps1 -Backend all # Windows, prefers CUDA-backed builds when available
```
Packaging options:
```bash
./build.sh all --package
./osxbuild.sh all --package
```
```powershell
.\build.ps1 -Backend all -Package
```
`--package` installs PyInstaller into the build virtual environment and produces a self-contained distributable from the venv that was just created or updated.
Packaging outputs:
- Linux: `dist-package/coderai`
- macOS: `dist-package/coderai` and `dist-package/CoderAI.app`
- Windows: `dist-package/coderai.exe`
Packaging notes:
- macOS does have an equivalent to a standalone packaged app: a `.app` bundle. `osxbuild.sh --package` now builds both a single CLI binary and a macOS app bundle.
- These packages bundle the Python interpreter and Python modules from the venv, but they do not eliminate the need for compatible external GPU/runtime drivers on the target machine.
- CUDA builds on Linux and Windows still require matching NVIDIA driver/runtime support on the destination system.
- Metal builds on macOS still require a compatible macOS system with Metal support.
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:
......
param(
[string]$Backend = "all",
[string]$Venv = ""
[string]$Venv = "",
[switch]$Package
)
$ErrorActionPreference = "Stop"
......@@ -76,6 +77,28 @@ function Install-CpuStack {
try { & $venvPython -m pip install onnxruntime } catch { Write-Warn "onnxruntime CPU install failed; continuing" }
}
function Invoke-PackageBuild {
Write-Info "Packaging CoderAI with PyInstaller..."
& $venvPython -m pip install pyinstaller
New-Item -ItemType Directory -Force -Path "dist-package" | Out-Null
& $venvPython -m PyInstaller --clean --noconfirm --onefile --name coderai `
--collect-all codai `
--collect-all fastapi `
--collect-all uvicorn `
--collect-all pydantic `
--collect-all transformers `
--collect-all diffusers `
--collect-all sentence_transformers `
--collect-all whispercpp `
--collect-all insightface `
--collect-all onnxruntime `
--collect-all PIL `
coderai
Copy-Item "dist\coderai.exe" "dist-package\coderai.exe" -Force
Write-Ok "Packaged executable: dist-package\coderai.exe"
Write-Warn "Target systems still need compatible GPU/runtime drivers such as CUDA when GPU backends are used."
}
switch ($Backend) {
"cuda" {
Install-CudaStack
......@@ -92,6 +115,9 @@ switch ($Backend) {
}
Set-Content -Path ".backend" -Value $Backend
if ($Package) {
Invoke-PackageBuild
}
Write-Ok "Build completed successfully!"
Write-Host ""
Write-Host "To activate the environment in the future, run:"
......
......@@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Build script for CoderAI - Supports NVIDIA (CUDA), Vulkan, OpenCL, and CPU backends
# Usage: ./build.sh [nvidia|vulkan|vulkan-nvidia|cuda|opencl|all] [--flash] [--venv <venv>]
# Usage: ./build.sh [nvidia|vulkan|vulkan-nvidia|cuda|opencl|all] [--flash] [--venv <venv>] [--package]
# Default: all (installs all backends)
# --flash: Enable and install Flash Attention 2 (for NVIDIA GPUs)
# --venv <venv>: Specify custom virtual environment name
......@@ -34,6 +34,7 @@ NC='\033[0m' # No Color
BACKEND="${1:-all}"
FLASH=false
CUSTOM_VENV=""
PACKAGE=false
# Parse arguments
i=1
......@@ -46,6 +47,9 @@ for arg in "$@"; do
i=$((i + 1))
eval "CUSTOM_VENV=\${$i}"
;;
--package)
PACKAGE=true
;;
esac
i=$((i + 1))
done
......@@ -719,10 +723,36 @@ elif [ "$BACKEND" = "all" ]; then
echo ""
fi
package_app() {
echo -e "${YELLOW}Packaging CoderAI with PyInstaller...${NC}"
pip install pyinstaller
mkdir -p dist-package
pyinstaller --clean --noconfirm --onefile --name coderai \
--collect-all codai \
--collect-all fastapi \
--collect-all uvicorn \
--collect-all pydantic \
--collect-all transformers \
--collect-all diffusers \
--collect-all sentence_transformers \
--collect-all whispercpp \
--collect-all insightface \
--collect-all onnxruntime \
--collect-all PIL \
coderai
cp dist/coderai dist-package/coderai
echo -e "${GREEN}✓ Packaged executable: dist-package/coderai${NC}"
echo -e "${YELLOW}Note: The target machine must still provide compatible system GPU/runtime libraries.${NC}"
}
# Create .backend file to track which backend was used
echo "$BACKEND" > .backend
if [ "$PACKAGE" = true ]; then
package_app
fi
echo -e "${GREEN}Build completed successfully!${NC}"
echo ""
echo "To activate the environment in the future, run:"
echo " source $VENV_DIR/bin/activate"
\ No newline at end of file
echo " source $VENV_DIR/bin/activate"
#!/bin/bash
# CoderAI macOS build script
# Usage: ./osxbuild.sh [metal|cpu|all] [--venv <venv>]
# Usage: ./osxbuild.sh [metal|cpu|all] [--venv <venv>] [--package]
set -e
......@@ -12,6 +12,7 @@ NC='\033[0m'
BACKEND="${1:-all}"
CUSTOM_VENV=""
PACKAGE=false
i=1
for arg in "$@"; do
......@@ -20,6 +21,9 @@ for arg in "$@"; do
i=$((i + 1))
eval "CUSTOM_VENV=\${$i}"
;;
--package)
PACKAGE=true
;;
esac
i=$((i + 1))
done
......@@ -107,6 +111,46 @@ install_cpu_stack() {
python -m pip install stable-diffusion-cpp-python || true
}
package_app() {
echo -e "${YELLOW}Packaging CoderAI with PyInstaller...${NC}"
python -m pip install pyinstaller
mkdir -p dist-package
pyinstaller --clean --noconfirm --onefile --name coderai \
--collect-all codai \
--collect-all fastapi \
--collect-all uvicorn \
--collect-all pydantic \
--collect-all transformers \
--collect-all diffusers \
--collect-all sentence_transformers \
--collect-all whispercpp \
--collect-all insightface \
--collect-all onnxruntime \
--collect-all PIL \
coderai
pyinstaller --clean --noconfirm --windowed --name CoderAI \
--collect-all codai \
--collect-all fastapi \
--collect-all uvicorn \
--collect-all pydantic \
--collect-all transformers \
--collect-all diffusers \
--collect-all sentence_transformers \
--collect-all whispercpp \
--collect-all insightface \
--collect-all onnxruntime \
--collect-all PIL \
coderai
cp dist/coderai dist-package/coderai
if [ -d "dist/CoderAI.app" ]; then
rm -rf dist-package/CoderAI.app
cp -R dist/CoderAI.app dist-package/CoderAI.app
fi
echo -e "${GREEN}✓ Packaged CLI binary: dist-package/coderai${NC}"
echo -e "${GREEN}✓ Packaged macOS app bundle: dist-package/CoderAI.app${NC}"
echo -e "${YELLOW}Note: macOS equivalent packaging is a single CLI binary plus a .app bundle; target machines still need compatible GPU/runtime libraries.${NC}"
}
if [ "$BACKEND" = "metal" ]; then
install_metal_stack
install_common_ml_stack
......@@ -119,6 +163,9 @@ else
fi
echo "$BACKEND" > .backend
if [ "$PACKAGE" = true ]; then
package_app
fi
echo -e "${GREEN}Build completed successfully!${NC}"
echo ""
echo "To activate the environment in the future, run:"
......
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