Add cross-platform packaging build option

parent dc379f3e
...@@ -178,6 +178,30 @@ Platform-specific alternatives: ...@@ -178,6 +178,30 @@ Platform-specific alternatives:
.\build.ps1 -Backend all # Windows, prefers CUDA-backed builds when available .\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. 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: Platform backend notes:
......
param( param(
[string]$Backend = "all", [string]$Backend = "all",
[string]$Venv = "" [string]$Venv = "",
[switch]$Package
) )
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
...@@ -76,6 +77,28 @@ function Install-CpuStack { ...@@ -76,6 +77,28 @@ function Install-CpuStack {
try { & $venvPython -m pip install onnxruntime } catch { Write-Warn "onnxruntime CPU install failed; continuing" } 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) { switch ($Backend) {
"cuda" { "cuda" {
Install-CudaStack Install-CudaStack
...@@ -92,6 +115,9 @@ switch ($Backend) { ...@@ -92,6 +115,9 @@ switch ($Backend) {
} }
Set-Content -Path ".backend" -Value $Backend Set-Content -Path ".backend" -Value $Backend
if ($Package) {
Invoke-PackageBuild
}
Write-Ok "Build completed successfully!" Write-Ok "Build completed successfully!"
Write-Host "" Write-Host ""
Write-Host "To activate the environment in the future, run:" Write-Host "To activate the environment in the future, run:"
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# Build script for CoderAI - Supports NVIDIA (CUDA), Vulkan, OpenCL, and CPU backends # 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) # Default: all (installs all backends)
# --flash: Enable and install Flash Attention 2 (for NVIDIA GPUs) # --flash: Enable and install Flash Attention 2 (for NVIDIA GPUs)
# --venv <venv>: Specify custom virtual environment name # --venv <venv>: Specify custom virtual environment name
...@@ -34,6 +34,7 @@ NC='\033[0m' # No Color ...@@ -34,6 +34,7 @@ NC='\033[0m' # No Color
BACKEND="${1:-all}" BACKEND="${1:-all}"
FLASH=false FLASH=false
CUSTOM_VENV="" CUSTOM_VENV=""
PACKAGE=false
# Parse arguments # Parse arguments
i=1 i=1
...@@ -46,6 +47,9 @@ for arg in "$@"; do ...@@ -46,6 +47,9 @@ for arg in "$@"; do
i=$((i + 1)) i=$((i + 1))
eval "CUSTOM_VENV=\${$i}" eval "CUSTOM_VENV=\${$i}"
;; ;;
--package)
PACKAGE=true
;;
esac esac
i=$((i + 1)) i=$((i + 1))
done done
...@@ -719,10 +723,36 @@ elif [ "$BACKEND" = "all" ]; then ...@@ -719,10 +723,36 @@ elif [ "$BACKEND" = "all" ]; then
echo "" echo ""
fi 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 # Create .backend file to track which backend was used
echo "$BACKEND" > .backend echo "$BACKEND" > .backend
if [ "$PACKAGE" = true ]; then
package_app
fi
echo -e "${GREEN}Build completed successfully!${NC}" echo -e "${GREEN}Build completed successfully!${NC}"
echo "" echo ""
echo "To activate the environment in the future, run:" echo "To activate the environment in the future, run:"
echo " source $VENV_DIR/bin/activate" echo " source $VENV_DIR/bin/activate"
\ No newline at end of file
#!/bin/bash #!/bin/bash
# CoderAI macOS build script # CoderAI macOS build script
# Usage: ./osxbuild.sh [metal|cpu|all] [--venv <venv>] # Usage: ./osxbuild.sh [metal|cpu|all] [--venv <venv>] [--package]
set -e set -e
...@@ -12,6 +12,7 @@ NC='\033[0m' ...@@ -12,6 +12,7 @@ NC='\033[0m'
BACKEND="${1:-all}" BACKEND="${1:-all}"
CUSTOM_VENV="" CUSTOM_VENV=""
PACKAGE=false
i=1 i=1
for arg in "$@"; do for arg in "$@"; do
...@@ -20,6 +21,9 @@ for arg in "$@"; do ...@@ -20,6 +21,9 @@ for arg in "$@"; do
i=$((i + 1)) i=$((i + 1))
eval "CUSTOM_VENV=\${$i}" eval "CUSTOM_VENV=\${$i}"
;; ;;
--package)
PACKAGE=true
;;
esac esac
i=$((i + 1)) i=$((i + 1))
done done
...@@ -107,6 +111,46 @@ install_cpu_stack() { ...@@ -107,6 +111,46 @@ install_cpu_stack() {
python -m pip install stable-diffusion-cpp-python || true 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 if [ "$BACKEND" = "metal" ]; then
install_metal_stack install_metal_stack
install_common_ml_stack install_common_ml_stack
...@@ -119,6 +163,9 @@ else ...@@ -119,6 +163,9 @@ else
fi fi
echo "$BACKEND" > .backend echo "$BACKEND" > .backend
if [ "$PACKAGE" = true ]; then
package_app
fi
echo -e "${GREEN}Build completed successfully!${NC}" echo -e "${GREEN}Build completed successfully!${NC}"
echo "" echo ""
echo "To activate the environment in the future, run:" 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