diff --git a/pkg/build.sh b/pkg/build.sh index fe81235..da0ceaa 100755 --- a/pkg/build.sh +++ b/pkg/build.sh @@ -10,6 +10,11 @@ TARGET="release" VERSION=$(grep '^version' tiles/Cargo.toml | head -1 | awk -F'"' '{print $2}') OS=$(uname -s | tr '[:upper:]' '[:lower:]') ARCH=$(uname -m) +case "${OS}" in + darwin) STACK_SPEC="server/stack/macos/venvstacks.toml" ;; + linux) STACK_SPEC="server/stack/linux/venvstacks.toml" ;; + *) echo "Unsupported OS for venvstack bundle: ${OS}" >&2; exit 1 ;; +esac OUT_NAME="${BINARY_NAME}-v${VERSION}-${ARCH}-${OS}" @@ -76,15 +81,15 @@ rm -rf "${SERVER_DIR}/stack_export_prod" echo "🔒 Locking the venvstack...." -venvstacks lock server/stack/venvstacks.toml +venvstacks lock "${STACK_SPEC}" echo "🛠️ Building the venvstack...." -venvstacks build server/stack/venvstacks.toml +venvstacks build "${STACK_SPEC}" echo "📦 Publishing the venvstack...." -venvstacks publish --tag-outputs --output-dir ../stack_export_prod server/stack/venvstacks.toml +venvstacks publish --tag-outputs --output-dir ../../stack_export_prod "${STACK_SPEC}" cp -r "${SERVER_DIR}" "${PKG_LIBS_PATH}" diff --git a/pkg/scripts/postinstall b/pkg/scripts/postinstall index 7c25563..f7c7f9a 100755 --- a/pkg/scripts/postinstall +++ b/pkg/scripts/postinstall @@ -13,5 +13,7 @@ done rm -f *.tar.xz ./cpython3.13/bin/python cpython3.13/postinstall.py -./framework-mlx/bin/python framework-mlx/postinstall.py +if [[ -x ./framework-mlx/bin/python ]]; then + ./framework-mlx/bin/python framework-mlx/postinstall.py +fi ./app-server/bin/python app-server/postinstall.py diff --git a/scripts/bundler.sh b/scripts/bundler.sh index c57a23b..d68707a 100755 --- a/scripts/bundler.sh +++ b/scripts/bundler.sh @@ -15,6 +15,11 @@ TARGET="release" VERSION=$(grep '^version' tiles/Cargo.toml | head -1 | awk -F'"' '{print $2}') OS=$(uname -s | tr '[:upper:]' '[:lower:]') ARCH=$(uname -m) +case "${OS}" in + darwin) STACK_SPEC="server/stack/macos/venvstacks.toml" ;; + linux) STACK_SPEC="server/stack/linux/venvstacks.toml" ;; + *) echo "Unsupported OS for venvstack bundle: ${OS}" >&2; exit 1 ;; +esac # Name for final tar.gz @@ -74,15 +79,15 @@ rm -rf "${SERVER_DIR}/stack_export_prod" echo "🔒 Locking the venvstack...." -venvstacks lock server/stack/venvstacks.toml +venvstacks lock "${STACK_SPEC}" echo "🛠️ Building the venvstack...." -venvstacks build server/stack/venvstacks.toml +venvstacks build "${STACK_SPEC}" echo "📦 Publishing the venvstack...." -venvstacks publish --tag-outputs --output-dir ../stack_export_prod server/stack/venvstacks.toml +venvstacks publish --tag-outputs --output-dir ../../stack_export_prod "${STACK_SPEC}" cp -r "${SERVER_DIR}" "${DIST_DIR}/tmp/" diff --git a/scripts/install.sh b/scripts/install.sh index 02b32b0..af7d8e5 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -78,7 +78,9 @@ done rm -rf *.tar.xz cpython3.13/bin/python cpython3.13/postinstall.py -framework-mlx/bin/python framework-mlx/postinstall.py +if [[ -x framework-mlx/bin/python ]]; then + framework-mlx/bin/python framework-mlx/postinstall.py +fi app-server/bin/python app-server/postinstall.py rm -rf "${TMPDIR}" diff --git a/server/.gitignore b/server/.gitignore index 74ee4e0..964d25f 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -3,5 +3,7 @@ __pycache__/ .venv/ backend/__pycache__ stack/_build +stack/*/_build +stack/*/requirements stack/stack_export stack_export_prod diff --git a/server/stack/linux/venvstacks.toml b/server/stack/linux/venvstacks.toml new file mode 100644 index 0000000..0a470d7 --- /dev/null +++ b/server/stack/linux/venvstacks.toml @@ -0,0 +1,28 @@ +[[runtimes]] +name = "cpython3.13" +python_implementation = "cpython@3.13.11" +requirements = [] +platforms = [ + "linux_x86_64", +] + + +[[applications]] +name = "server" +launch_module = "../../main.py" +runtime = "cpython3.13" +requirements = [ + "fastapi==0.119.0", + "uvicorn==0.38.0", + "openai-harmony==0.0.8", + "llama-cpp-python @ https://github.com/abetlen/llama-cpp-python/releases/download/v0.3.25-cu124/llama_cpp_python-0.3.25-py3-none-linux_x86_64.whl#sha256=d4651fe74e66275aa1f6f16027bc9113c91cc828c421c156151c3d392a27020d", + "nvidia-cuda-runtime-cu12", + "nvidia-cublas-cu12", + "openresponses-types", + "httpx==0.28.1", + ] + +[tool.uv] +environments = [ + "sys_platform == 'linux' and platform_machine == 'x86_64'", +] diff --git a/server/stack/macos/venvstacks.toml b/server/stack/macos/venvstacks.toml new file mode 100644 index 0000000..f99f8fa --- /dev/null +++ b/server/stack/macos/venvstacks.toml @@ -0,0 +1,33 @@ +[[runtimes]] +name = "cpython3.13" +python_implementation = "cpython@3.13.11" +requirements = [] +platforms = [ + "macosx_arm64", +] + + +[[frameworks]] +name = "mlx" +runtime = "cpython3.13" +requirements = [ + "mlx==0.31.1" +] + +[[applications]] +name = "server" +launch_module = "../../main.py" +frameworks = ["mlx"] +requirements = [ + "fastapi==0.119.0", + "uvicorn==0.38.0", + "mlx-lm==0.31.0", + "openai-harmony==0.0.8", + "openresponses-types", + "httpx==0.28.1", + ] + +[tool.uv] +environments = [ + "sys_platform == 'darwin' and platform_machine == 'arm64'", +]