From 796969caf02f656826d15e045ad05dbb5e1db5df Mon Sep 17 00:00:00 2001 From: Simo Lin Date: Sun, 21 Dec 2025 15:32:13 -1000 Subject: [PATCH] Optimize Rust CI builds with proper sccache configuration (#15581) --- .github/workflows/pr-benchmark-rust.yml | 8 ++++---- .github/workflows/pr-test-pd-router.yml | 27 +++++++++++++++---------- .github/workflows/pr-test-rust.yml | 23 +++++++++++++++++---- sgl-model-gateway/README.md | 21 +++++++++++++++++++ 4 files changed, 60 insertions(+), 19 deletions(-) diff --git a/.github/workflows/pr-benchmark-rust.yml b/.github/workflows/pr-benchmark-rust.yml index 7e09331ce..33cab44fc 100644 --- a/.github/workflows/pr-benchmark-rust.yml +++ b/.github/workflows/pr-benchmark-rust.yml @@ -40,7 +40,7 @@ jobs: - name: Configure sccache uses: mozilla-actions/sccache-action@v0.0.9 with: - version: "v0.10.0" + version: "v0.12.0" - name: Rust cache uses: Swatinem/rust-cache@v2 @@ -87,7 +87,7 @@ jobs: - name: Configure sccache uses: mozilla-actions/sccache-action@v0.0.9 with: - version: "v0.10.0" + version: "v0.12.0" - name: Rust cache uses: Swatinem/rust-cache@v2 @@ -159,7 +159,7 @@ jobs: - name: Configure sccache uses: mozilla-actions/sccache-action@v0.0.9 with: - version: "v0.10.0" + version: "v0.12.0" - name: Rust cache uses: Swatinem/rust-cache@v2 @@ -226,7 +226,7 @@ jobs: - name: Configure sccache uses: mozilla-actions/sccache-action@v0.0.9 with: - version: "v0.10.0" + version: "v0.12.0" - name: Rust cache uses: Swatinem/rust-cache@v2 diff --git a/.github/workflows/pr-test-pd-router.yml b/.github/workflows/pr-test-pd-router.yml index 9049b15eb..73b7f01e3 100644 --- a/.github/workflows/pr-test-pd-router.yml +++ b/.github/workflows/pr-test-pd-router.yml @@ -20,6 +20,10 @@ concurrency: group: test-disaggregation-${{ github.ref }} cancel-in-progress: true +env: + RUSTC_WRAPPER: sccache + SCCACHE_GHA_ENABLED: "true" + permissions: contents: read pull-requests: write @@ -50,18 +54,19 @@ jobs: run: | bash scripts/ci/ci_install_rust.sh - - name: Cache Rust dependencies - uses: actions/cache@v4 + - name: Configure sccache + uses: mozilla-actions/sccache-action@v0.0.9 with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - sgl-model-gateway/target/ - key: ${{ runner.os }}-cargo-${{ hashFiles('sgl-model-gateway/Cargo.lock') }} - restore-keys: | - ${{ runner.os }}-cargo- + version: "v0.12.0" + + - name: Rust cache + uses: Swatinem/rust-cache@v2 + with: + workspaces: sgl-model-gateway + shared-key: "rust-cache" + cache-all-crates: true + cache-on-failure: true + save-if: true - name: Cache pip dependencies uses: actions/cache@v4 diff --git a/.github/workflows/pr-test-rust.yml b/.github/workflows/pr-test-rust.yml index 75de0ba8e..8a70f415e 100644 --- a/.github/workflows/pr-test-rust.yml +++ b/.github/workflows/pr-test-rust.yml @@ -55,7 +55,16 @@ jobs: - name: Configure sccache uses: mozilla-actions/sccache-action@v0.0.9 with: - version: "v0.10.0" + version: "v0.12.0" + + - name: Rust cache + uses: Swatinem/rust-cache@v2 + with: + workspaces: "." + shared-key: "rust-cache" + cache-all-crates: true + cache-on-failure: true + save-if: true - name: Test maturin build uses: PyO3/maturin-action@v1 @@ -91,14 +100,16 @@ jobs: - name: Configure sccache uses: mozilla-actions/sccache-action@v0.0.9 with: - version: "v0.10.0" + version: "v0.12.0" - name: Rust cache uses: Swatinem/rust-cache@v2 with: workspaces: sgl-model-gateway + shared-key: "rust-cache" cache-all-crates: true cache-on-failure: true + save-if: true - name: Run lint run: | @@ -153,14 +164,16 @@ jobs: - name: Configure sccache uses: mozilla-actions/sccache-action@v0.0.9 with: - version: "v0.10.0" + version: "v0.12.0" - name: Rust cache uses: Swatinem/rust-cache@v2 with: workspaces: sgl-model-gateway + shared-key: "rust-cache" cache-all-crates: true cache-on-failure: true + save-if: true - name: Install SGLang dependencies run: | @@ -225,14 +238,16 @@ jobs: - name: Configure sccache uses: mozilla-actions/sccache-action@v0.0.9 with: - version: "v0.10.0" + version: "v0.12.0" - name: Rust cache uses: Swatinem/rust-cache@v2 with: workspaces: sgl-model-gateway + shared-key: "rust-cache" cache-all-crates: true cache-on-failure: true + save-if: true - name: Install SGLang dependencies run: | diff --git a/sgl-model-gateway/README.md b/sgl-model-gateway/README.md index a297a0708..b8effb8d3 100644 --- a/sgl-model-gateway/README.md +++ b/sgl-model-gateway/README.md @@ -625,6 +625,27 @@ pytest py_test/ ``` For production builds, use `maturin build --release --out dist` from the `bindings/python/` directory 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. +### Build Caching + +**Local development** uses incremental compilation by default (configured in `.cargo/config.toml`), which is optimal for the edit-compile-test cycle. + +**For release builds or CI**, you can optionally use [sccache](https://github.com/mozilla/sccache) to cache compilation artifacts: + +```bash +# Install sccache +cargo install sccache + +# Option 1: Set environment variable (per-session) +export RUSTC_WRAPPER=sccache +cargo build --release + +# Option 2: Add to your global cargo config (~/.cargo/config.toml) +# [build] +# rustc-wrapper = "sccache" +``` + +> **Note:** sccache and incremental compilation are mutually exclusive—sccache cannot cache incrementally compiled crates. The project defaults to incremental compilation for faster local iteration. Use sccache for clean/release builds where caching across builds matters more. + --- ## Release Management