11#! /bin/bash
22# Build script for vllm-metal macOS tarball distribution
3- # Creates a tarball containing Python site-packages for vllm-metal and dependencies
3+ # Creates a self-contained tarball with a standalone Python 3.12 + vllm-metal packages.
4+ # The result can be extracted anywhere and run without any system Python dependency.
45#
56# Usage: ./scripts/build-vllm-metal-tarball.sh <VLLM_METAL_RELEASE> <TARBALL>
67# VLLM_METAL_RELEASE - vllm-metal release tag (required)
78# TARBALL - Output tarball path (required)
89#
910# Requirements:
1011# - macOS with Apple Silicon (ARM64)
11- # - Python 3.12+ installed (standard on macOS 14+, or via Homebrew)
1212# - uv (will be installed if missing)
1313
1414set -e
1515
1616VLLM_METAL_RELEASE=" ${1:? Usage: $0 <VLLM_METAL_RELEASE> <TARBALL>} "
1717TARBALL_ARG=" ${2:? Usage: $0 <VLLM_METAL_RELEASE> <TARBALL>} "
1818WORK_DIR=$( mktemp -d)
19- VENV_DIR=" $WORK_DIR /venv"
2019
2120# Convert tarball path to absolute before we cd elsewhere
2221TARBALL=" $( cd " $( dirname " $TARBALL_ARG " ) " && pwd) /$( basename " $TARBALL_ARG " ) "
@@ -37,56 +36,52 @@ if ! command -v uv &> /dev/null; then
3736 export PATH=" $HOME /.local/bin:$PATH "
3837fi
3938
40- # Python 3.12 required (vllm-metal wheel is built for cp312)
41- if command -v python3.12 & > /dev/null; then
42- PYTHON_BIN=" python3.12"
43- elif command -v python3 & > /dev/null && [ " $( python3 --version 2>&1 | grep -oE ' [0-9]+\.[0-9]+' ) " = " 3.12" ]; then
44- PYTHON_BIN=" python3"
45- else
46- echo " Error: Python 3.12 is required (the vllm-metal wheel is built for cp312)"
47- echo " Install with: brew install python@3.12"
48- exit 1
49- fi
39+ # Install standalone Python 3.12 via uv (from python-build-standalone, relocatable)
40+ echo " Installing standalone Python 3.12 via uv..."
41+ uv python install 3.12
5042
51- PYTHON_VERSION=$( $PYTHON_BIN --version 2>&1 | grep -oE ' [0-9]+\.[0-9]+' )
52- echo " Using Python $PYTHON_VERSION from: $( which $PYTHON_BIN ) "
43+ PYTHON_BIN=$( uv python find 3.12)
44+ PYTHON_PREFIX=$( cd " $( dirname " $PYTHON_BIN " ) /.." && pwd)
45+ echo " Using standalone Python from: $PYTHON_PREFIX "
5346
54- echo " Creating Python venv..."
55- uv venv " $VENV_DIR " --python " $PYTHON_BIN "
47+ # Copy the standalone Python to our work area
48+ PYTHON_DIR=" $WORK_DIR /python"
49+ cp -Rp " $PYTHON_PREFIX " " $PYTHON_DIR "
5650
57- export VIRTUAL_ENV= " $VENV_DIR "
58- export PATH= " $VENV_DIR /bin: $PATH "
51+ # Remove the externally-managed marker so we can install packages into it
52+ rm -f " $PYTHON_DIR /lib/python3.12/EXTERNALLY-MANAGED "
5953
6054echo " Installing vLLM $VLLM_VERSION from source (CPU requirements)..."
6155cd " $WORK_DIR "
6256curl -fsSL -O " https://github.com/vllm-project/vllm/releases/download/v$VLLM_VERSION /vllm-$VLLM_VERSION .tar.gz"
6357tar xf " vllm-$VLLM_VERSION .tar.gz"
6458cd " vllm-$VLLM_VERSION "
65- uv pip install -r requirements/cpu.txt --index-strategy unsafe-best-match
66- uv pip install .
59+ uv pip install --python " $PYTHON_DIR /bin/python3 " --system - r requirements/cpu.txt --index-strategy unsafe-best-match
60+ uv pip install --python " $PYTHON_DIR /bin/python3 " --system .
6761cd " $WORK_DIR "
6862rm -rf " vllm-$VLLM_VERSION " " vllm-$VLLM_VERSION .tar.gz"
6963
7064echo " Installing vllm-metal from pre-built wheel..."
7165curl -fsSL -O " $VLLM_METAL_WHEEL_URL "
72- uv pip install vllm_metal-* .whl
66+ uv pip install --python " $PYTHON_DIR /bin/python3 " --system vllm_metal-* .whl
7367rm -f vllm_metal-* .whl
7468
75- echo " Packaging site-packages..."
76- SITE_PACKAGES_DIR=" $VENV_DIR /lib/python$PYTHON_VERSION /site-packages"
77- if [ ! -d " $SITE_PACKAGES_DIR " ]; then
78- echo " Error: site-packages directory not found at $SITE_PACKAGES_DIR "
79- exit 1
80- fi
69+ # Strip files not needed at runtime to reduce tarball size
70+ echo " Stripping unnecessary files..."
71+ rm -rf " $PYTHON_DIR /include"
72+ rm -rf " $PYTHON_DIR /share"
73+ PYLIB=" $PYTHON_DIR /lib/python3.12"
74+ rm -rf " $PYLIB /test" " $PYLIB /tests"
75+ rm -rf " $PYLIB /idlelib" " $PYLIB /idle_test"
76+ rm -rf " $PYLIB /tkinter" " $PYLIB /turtledemo"
77+ rm -rf " $PYLIB /ensurepip"
78+ find " $PYTHON_DIR " -type d -name " __pycache__" -exec rm -rf {} + 2> /dev/null || true
8179
82- tar -czf " $TARBALL " -C " $SITE_PACKAGES_DIR " .
80+ echo " Packaging standalone Python with vllm-metal..."
81+ tar -czf " $TARBALL " -C " $PYTHON_DIR " .
8382
8483SIZE=$( du -h " $TARBALL " | cut -f1)
8584echo " Created: $TARBALL ($SIZE )"
8685echo " "
87- echo " To use this tarball:"
88- echo " 1. Upload to GitHub releases"
89- echo " 2. Model-runner will auto-download on first use"
90- echo " 3. Or manually extract for testing:"
91- echo " python3.12 -m venv ~/.model-runner/vllm-metal"
92- echo " tar -xzf $TARBALL -C ~/.model-runner/vllm-metal/lib/python$PYTHON_VERSION /site-packages/"
86+ echo " This tarball is fully self-contained (includes Python 3.12 + all packages)."
87+ echo " To use: extract to a directory and run bin/python3 -m vllm_metal.server"
0 commit comments