Unverified Commit 400bddf2 authored by Chang Su's avatar Chang Su Committed by GitHub
Browse files

[router] fix router release workflow and add build test in PR (#12315)

parent 1e90fe2e
...@@ -25,10 +25,10 @@ jobs: ...@@ -25,10 +25,10 @@ jobs:
ls: dir ls: dir
target: x86_64 target: x86_64
python-architecture: x64 python-architecture: x64
interpreter: 3.8 3.9 3.10 3.11 3.12 3.13 interpreter: 3.9 3.10 3.11 3.12 3.13
- os: macos - os: macos
target: aarch64 target: aarch64
interpreter: 3.8 3.9 3.10 3.11 3.12 3.13 interpreter: 3.9 3.10 3.11 3.12 3.13
- os: ubuntu - os: ubuntu
platform: linux platform: linux
target: aarch64 target: aarch64
...@@ -94,7 +94,7 @@ jobs: ...@@ -94,7 +94,7 @@ jobs:
with: with:
target: ${{ matrix.target }} target: ${{ matrix.target }}
manylinux: ${{ matrix.manylinux || 'auto' }} manylinux: ${{ matrix.manylinux || 'auto' }}
args: --release --out dist --interpreter ${{ matrix.interpreter || '3.8 3.9 3.10 3.11 3.12 3.13' }} args: --release --out dist --interpreter ${{ matrix.interpreter || '3.9 3.10 3.11 3.12 3.13 3.14' }}
rust-toolchain: stable rust-toolchain: stable
docker-options: -e CI -e CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc -e CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ docker-options: -e CI -e CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc -e CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++
before-script-linux: | before-script-linux: |
......
...@@ -148,7 +148,9 @@ jobs: ...@@ -148,7 +148,9 @@ jobs:
source "$HOME/.cargo/env" source "$HOME/.cargo/env"
echo "Building sgl-router..." echo "Building sgl-router..."
cd sgl-router cd sgl-router
cargo build && python3 -m build && pip install --force-reinstall dist/*.whl pip install maturin
maturin build --release --out dist
pip install --force-reinstall dist/*.whl
- name: Start disaggregation servers - name: Start disaggregation servers
id: start_servers id: start_servers
......
...@@ -21,6 +21,55 @@ env: ...@@ -21,6 +21,55 @@ env:
SCCACHE_GHA_ENABLED: "true" SCCACHE_GHA_ENABLED: "true"
jobs: jobs:
maturin-build-test:
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-ci')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: sglang-repo
- name: Move sgl-router folder to root
run: |
mv sglang-repo/sgl-router/* .
rm -rf sglang-repo
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install protoc and dependencies
run: |
sudo apt-get update
sudo apt-get install -y wget unzip gcc g++ perl make
cd /tmp
wget https://github.com/protocolbuffers/protobuf/releases/download/v32.0/protoc-32.0-linux-x86_64.zip
sudo unzip protoc-32.0-linux-x86_64.zip -d /usr/local
rm protoc-32.0-linux-x86_64.zip
protoc --version
- name: Configure sccache
uses: mozilla-actions/sccache-action@v0.0.9
with:
version: "v0.10.0"
- name: Test maturin build
uses: PyO3/maturin-action@v1
with:
args: --release --out dist
rust-toolchain: stable
sccache: true
- name: List built wheel
run: ls -lh dist/
- name: Test wheel install
run: |
pip install dist/*.whl
python -c "import sglang_router; print('Python package: OK')"
python -c "from sglang_router.sglang_router_rs import Router; print('Rust extension: OK')"
python -m sglang_router.launch_router --help > /dev/null && echo "Entry point: OK"
unit-test-rust: unit-test-rust:
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-ci') if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-ci')
runs-on: ubuntu-latest runs-on: ubuntu-latest
...@@ -116,8 +165,8 @@ jobs: ...@@ -116,8 +165,8 @@ jobs:
source "$HOME/.cargo/env" source "$HOME/.cargo/env"
export RUSTC_WRAPPER=sccache export RUSTC_WRAPPER=sccache
cd sgl-router cd sgl-router
pip install setuptools-rust wheel build pip install maturin
python3 -m build maturin build --release --out dist
pip install --force-reinstall dist/*.whl pip install --force-reinstall dist/*.whl
...@@ -213,8 +262,8 @@ jobs: ...@@ -213,8 +262,8 @@ jobs:
source "$HOME/.cargo/env" source "$HOME/.cargo/env"
export RUSTC_WRAPPER=sccache export RUSTC_WRAPPER=sccache
cd sgl-router cd sgl-router
pip install setuptools-rust wheel build pip install maturin
python3 -m build maturin build --release --out dist
pip install --force-reinstall dist/*.whl pip install --force-reinstall dist/*.whl
- name: Run Python E2E response API tests - name: Run Python E2E response API tests
...@@ -237,7 +286,7 @@ jobs: ...@@ -237,7 +286,7 @@ jobs:
finish: finish:
needs: [unit-test-rust, pytest-rust, pytest-rust-2] needs: [maturin-build-test, unit-test-rust, pytest-rust, pytest-rust-2]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Finish - name: Finish
......
...@@ -25,10 +25,10 @@ jobs: ...@@ -25,10 +25,10 @@ jobs:
ls: dir ls: dir
target: x86_64 target: x86_64
python-architecture: x64 python-architecture: x64
interpreter: 3.8 3.9 3.10 3.11 3.12 3.13 interpreter: 3.9 3.10 3.11 3.12 3.13
- os: macos - os: macos
target: aarch64 target: aarch64
interpreter: 3.8 3.9 3.10 3.11 3.12 3.13 interpreter: 3.9 3.10 3.11 3.12 3.13
- os: ubuntu - os: ubuntu
platform: linux platform: linux
target: aarch64 target: aarch64
...@@ -79,7 +79,7 @@ jobs: ...@@ -79,7 +79,7 @@ jobs:
with: with:
target: ${{ matrix.target }} target: ${{ matrix.target }}
manylinux: ${{ matrix.manylinux || 'auto' }} manylinux: ${{ matrix.manylinux || 'auto' }}
args: --release --out dist --interpreter ${{ matrix.interpreter || '3.8 3.9 3.10 3.11 3.12 3.13' }} args: --release --out dist --interpreter ${{ matrix.interpreter || '3.9 3.10 3.11 3.12 3.13 3.14' }}
rust-toolchain: stable rust-toolchain: stable
docker-options: -e CI -e CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc -e CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ docker-options: -e CI -e CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc -e CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++
before-script-linux: | before-script-linux: |
......
...@@ -127,9 +127,14 @@ strip = true # Strip debug symbols ...@@ -127,9 +127,14 @@ strip = true # Strip debug symbols
[profile.dev] [profile.dev]
opt-level = 0 opt-level = 0
debug = true debug = 1
split-debuginfo = "unpacked" split-debuginfo = "unpacked"
incremental = true incremental = true
codegen-units = 256
[profile.dev.package."*"]
opt-level = 2
debug = false
[profile.dev.build-override] [profile.dev.build-override]
......
...@@ -3,3 +3,4 @@ include Cargo.toml # Rust project configuration ...@@ -3,3 +3,4 @@ include Cargo.toml # Rust project configuration
include build.rs # Build script for protobuf generation include build.rs # Build script for protobuf generation
recursive-include src *.rs # Rust source files recursive-include src *.rs # Rust source files
recursive-include src/proto *.proto # Protobuf definitions recursive-include src/proto *.proto # Protobuf definitions
recursive-include py_src *.py # Python source files
...@@ -67,14 +67,16 @@ cargo build --release ...@@ -67,14 +67,16 @@ cargo build --release
### Python Package ### Python Package
```bash ```bash
pip install setuptools-rust wheel build pip install maturin
python -m build
pip install dist/*.whl
# Rebuild & reinstall in one step during development # Fast development mode (debug build, no wheel, instant)
python -m build && pip install --force-reinstall dist/*.whl maturin develop
# Production build (optimized, creates wheel)
maturin build --release
pip install --force-reinstall dist/*.whl
``` ```
> **Note:** Editable installs (`pip install -e .`) are currently not supported; prefer wheel builds for development. > **Note:** Use `maturin develop` for fast iteration during development (builds in debug mode and installs directly). Use `maturin build --release` for production wheels with full optimizations (opt-level="z", lto="fat"). The package uses abi3 support for Python 3.8+ compatibility.
## Quick Start ## Quick Start
...@@ -562,20 +564,19 @@ curl -X POST "http://localhost:8080/add_worker?url=http://worker3:8000&api_key=w ...@@ -562,20 +564,19 @@ curl -X POST "http://localhost:8080/add_worker?url=http://worker3:8000&api_key=w
## Development & Testing ## Development & Testing
```bash ```bash
# Build Rust components # Build Rust components (debug mode, fast)
cargo build cargo build
# Run Rust tests # Run Rust tests
cargo test cargo test
# Build & install Python bindings # Fast Python development (rebuilds and installs in debug mode)
python -m build maturin develop
pip install --force-reinstall dist/*.whl
# Run Python tests # Run Python tests
pytest pytest
``` ```
When modifying runtime behavior, rebuild the wheel or run the binary directly. Use `python -m sglang_router.launch_server` to co-launch router and SGLang workers in small clusters for local validation. For production builds, use `maturin build --release` to create optimized wheels. During development, `maturin develop` rebuilds and installs instantly without creating wheel files. Use `python -m sglang_router.launch_server` to co-launch router and SGLang workers in small clusters for local validation.
--- ---
......
from typing import Optional from typing import Optional
from sglang_router.router_args import RouterArgs from sglang_router.router_args import RouterArgs
from sglang_router_rs import BackendType, HistoryBackendType, PolicyType, PyOracleConfig from sglang_router.sglang_router_rs import (
from sglang_router_rs import Router as _Router BackendType,
HistoryBackendType,
PolicyType,
PyOracleConfig,
)
from sglang_router.sglang_router_rs import Router as _Router
def policy_from_str(policy_str: Optional[str]) -> PolicyType: def policy_from_str(policy_str: Optional[str]) -> PolicyType:
......
...@@ -406,7 +406,7 @@ class TestPolicyFromStr: ...@@ -406,7 +406,7 @@ class TestPolicyFromStr:
def test_valid_policies(self): def test_valid_policies(self):
"""Test conversion of valid policy strings.""" """Test conversion of valid policy strings."""
from sglang_router_rs import PolicyType from sglang_router.sglang_router_rs import PolicyType
assert policy_from_str("random") == PolicyType.Random assert policy_from_str("random") == PolicyType.Random
assert policy_from_str("round_robin") == PolicyType.RoundRobin assert policy_from_str("round_robin") == PolicyType.RoundRobin
......
...@@ -10,7 +10,7 @@ from unittest.mock import MagicMock, patch ...@@ -10,7 +10,7 @@ from unittest.mock import MagicMock, patch
import pytest import pytest
from sglang_router.launch_router import RouterArgs, launch_router from sglang_router.launch_router import RouterArgs, launch_router
from sglang_router.router import policy_from_str from sglang_router.router import policy_from_str
from sglang_router_rs import PolicyType from sglang_router.sglang_router_rs import PolicyType
class TestRouterConfigValidation: class TestRouterConfigValidation:
......
...@@ -28,7 +28,7 @@ def setup_logger(): ...@@ -28,7 +28,7 @@ def setup_logger():
return logger return logger
from sglang_router_rs import PolicyType from sglang_router.sglang_router_rs import PolicyType
class TestSetupLogger: class TestSetupLogger:
...@@ -742,7 +742,7 @@ def test_router_defaults_and_start(monkeypatch): ...@@ -742,7 +742,7 @@ def test_router_defaults_and_start(monkeypatch):
assert captured["decode_selector"] is None assert captured["decode_selector"] is None
assert captured["cors_allowed_origins"] is None assert captured["cors_allowed_origins"] is None
assert captured["worker_urls"] == ["http://w1:8000"] assert captured["worker_urls"] == ["http://w1:8000"]
from sglang_router_rs import PolicyType from sglang_router.sglang_router_rs import PolicyType
assert captured["policy"] == PolicyType.RoundRobin assert captured["policy"] == PolicyType.RoundRobin
......
[build-system] [build-system]
requires = ["setuptools>=45", "wheel", "setuptools-rust>=1.5.2"] requires = ["maturin>=1.0,<2.0"]
build-backend = "setuptools.build_meta" build-backend = "maturin"
[project] [project]
name = "sglang-router" name = "sglang-router"
...@@ -41,10 +41,6 @@ dev = [ ...@@ -41,10 +41,6 @@ dev = [
] ]
# https://github.com/PyO3/setuptools-rust?tab=readme-ov-file [tool.maturin]
[tool.setuptools.packages] python-source = "py_src"
find = { where = ["py_src"] } module-name = "sglang_router.sglang_router_rs"
# workaround for https://github.com/pypa/twine/issues/1216
[tool.setuptools]
license-files = []
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
//! - Worker trait and implementations //! - Worker trait and implementations
//! - Error types //! - Error types
//! - Circuit breaker for reliability //! - Circuit breaker for reliability
//! - Token buckets for rate limiting
//! - Workflow engine for multi-step operations //! - Workflow engine for multi-step operations
//! - Common utilities //! - Common utilities
......
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