From c3ab5bec7db9213414281d6e435633f91a4bd40a Mon Sep 17 00:00:00 2001 From: Alex Nails Date: Wed, 29 Apr 2026 13:39:02 -0700 Subject: [PATCH] ci: consolidate rust + protoc install across workflows (#23700) Co-authored-by: Claude Opus 4.7 (1M context) --- .github/workflows/pr-test.yml | 13 ++++++---- .github/workflows/rerun-test.yml | 8 +++---- rust/sglang-grpc/rust-toolchain.toml | 3 +++ scripts/ci/cuda/ci_install_dependency.sh | 7 ++---- .../cuda/ci_install_gateway_dependencies.sh | 22 ++++++++++------- scripts/ci/utils/install_protoc.sh | 6 ++--- scripts/ci/utils/install_rust_protoc.sh | 24 +++++++++++++++++++ sgl-model-gateway/rust-toolchain.toml | 4 ++++ 8 files changed, 61 insertions(+), 26 deletions(-) create mode 100644 rust/sglang-grpc/rust-toolchain.toml create mode 100755 scripts/ci/utils/install_rust_protoc.sh create mode 100644 sgl-model-gateway/rust-toolchain.toml diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml index db61c614e..2674ef83f 100644 --- a/.github/workflows/pr-test.yml +++ b/.github/workflows/pr-test.yml @@ -725,11 +725,16 @@ jobs: # Needed by setuptools-rust to build the bundled native gRPC extension # (rust/sglang-grpc) when installing the main `sglang` wheel from source. - - name: Install protoc - run: sudo bash scripts/ci/utils/install_protoc.sh + - name: Install protoc + Rust toolchain + timeout-minutes: 10 + run: bash scripts/ci/utils/install_rust_protoc.sh - - name: Install Rust toolchain - run: bash scripts/ci/utils/install_rustup.sh + - name: Rust cache (sglang-grpc) + uses: Swatinem/rust-cache@v2 + with: + workspaces: rust/sglang-grpc + shared-key: "sglang-grpc-cpu" + save-if: ${{ matrix.partition == 0 }} # uv pip targets a venv by default; setup-python has no venv — install into that interpreter (see UV_SYSTEM_PYTHON in https://docs.astral.sh/uv/guides/integration/github/) - name: Install dependencies diff --git a/.github/workflows/rerun-test.yml b/.github/workflows/rerun-test.yml index 1eefbd97e..007d51074 100644 --- a/.github/workflows/rerun-test.yml +++ b/.github/workflows/rerun-test.yml @@ -153,11 +153,9 @@ jobs: # Needed by setuptools-rust to build the bundled native gRPC extension # (rust/sglang-grpc) when installing the main `sglang` wheel from source. - - name: Install protoc - run: sudo bash scripts/ci/utils/install_protoc.sh - - - name: Install Rust toolchain - run: bash scripts/ci/utils/install_rustup.sh + - name: Install protoc + Rust toolchain + timeout-minutes: 10 + run: bash scripts/ci/utils/install_rust_protoc.sh - name: Install dependencies timeout-minutes: 20 diff --git a/rust/sglang-grpc/rust-toolchain.toml b/rust/sglang-grpc/rust-toolchain.toml new file mode 100644 index 000000000..67d745842 --- /dev/null +++ b/rust/sglang-grpc/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.90" +profile = "minimal" diff --git a/scripts/ci/cuda/ci_install_dependency.sh b/scripts/ci/cuda/ci_install_dependency.sh index 1a595fbb1..cc2e58ef9 100755 --- a/scripts/ci/cuda/ci_install_dependency.sh +++ b/scripts/ci/cuda/ci_install_dependency.sh @@ -160,11 +160,8 @@ clean_site_packages() { set -x fi - # Install protoc - bash "${SCRIPT_DIR}/../utils/install_protoc.sh" - - # Install Rust toolchain (needed by setuptools-rust, e.g. the native gRPC extension) - bash "${SCRIPT_DIR}/../utils/install_rustup.sh" + # Install protoc + Rust toolchain (needed by setuptools-rust, e.g. the native gRPC extension) + bash "${SCRIPT_DIR}/../utils/install_rust_protoc.sh" export PATH="${CARGO_HOME:-$HOME/.cargo}/bin:${PATH}" mark_step_done "${FUNCNAME[0]}" diff --git a/scripts/ci/cuda/ci_install_gateway_dependencies.sh b/scripts/ci/cuda/ci_install_gateway_dependencies.sh index f2a4c070e..4fa7c78ab 100755 --- a/scripts/ci/cuda/ci_install_gateway_dependencies.sh +++ b/scripts/ci/cuda/ci_install_gateway_dependencies.sh @@ -1,24 +1,28 @@ #!/bin/bash +# Install dependencies for the sgl-model-gateway CI jobs. +# +# Gateway-specific apt deps are installed here; protoc and the Rust toolchain +# are delegated to the shared installer (the toolchain version is pinned by +# sgl-model-gateway/rust-toolchain.toml, picked up automatically on first +# `cargo` invocation). set -euxo pipefail -# Check if sudo is available +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +GATEWAY_APT_PACKAGES=(libssl-dev pkg-config redis-server) if command -v sudo >/dev/null 2>&1; then sudo apt-get update - sudo apt-get install -y libssl-dev pkg-config protobuf-compiler redis-server + sudo apt-get install -y "${GATEWAY_APT_PACKAGES[@]}" else apt-get update - apt-get install -y libssl-dev pkg-config protobuf-compiler redis-server + apt-get install -y "${GATEWAY_APT_PACKAGES[@]}" fi -# Install rustup (Rust installer and version manager) -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.90 +bash "${SCRIPT_DIR}/../utils/install_rust_protoc.sh" - -# Follow the installation prompts, then reload your shell +# Make cargo/rustc/protoc visible in this shell. . "$HOME/.cargo/env" -source $HOME/.cargo/env -# Verify installation rustc --version cargo --version protoc --version diff --git a/scripts/ci/utils/install_protoc.sh b/scripts/ci/utils/install_protoc.sh index 5d4bd2891..f13f13b4e 100755 --- a/scripts/ci/utils/install_protoc.sh +++ b/scripts/ci/utils/install_protoc.sh @@ -18,7 +18,7 @@ ARCH=$(uname -m) if command -v apt-get &> /dev/null; then # Ubuntu/Debian apt-get update || true # May fail due to unrelated broken packages - PROTOC_APT_PACKAGES=(wget unzip gcc g++ perl make) + PROTOC_APT_PACKAGES=(wget unzip) apt-get install -y --no-install-recommends "${PROTOC_APT_PACKAGES[@]}" || { echo "Warning: apt-get install failed, checking if required packages are available..." for pkg in "${PROTOC_APT_PACKAGES[@]}"; do @@ -32,9 +32,9 @@ if command -v apt-get &> /dev/null; then elif command -v yum &> /dev/null; then # RHEL/CentOS yum update -y - yum install -y wget unzip gcc gcc-c++ perl-core make + yum install -y wget unzip else - echo "ERROR: Neither apt-get nor yum found; cannot install protoc build deps" + echo "ERROR: Neither apt-get nor yum found; cannot install protoc" exit 1 fi diff --git a/scripts/ci/utils/install_rust_protoc.sh b/scripts/ci/utils/install_rust_protoc.sh new file mode 100755 index 000000000..d90cde51e --- /dev/null +++ b/scripts/ci/utils/install_rust_protoc.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Install protoc and a Rust toolchain (rustup/cargo). Required by setuptools-rust +# to build the bundled native gRPC extension (rust/sglang-grpc) when installing +# the main `sglang` wheel from source. Idempotent — both helpers no-op if +# already installed. +# +# protoc installs system-wide (/usr/local) and apt deps, so it needs root. +# rustup installs per-user under $HOME/.cargo, so it must run as the calling +# user (running it under sudo would put cargo in /root/.cargo and the rest of +# the job wouldn't find it). +set -euxo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +if [ "$(id -u)" = "0" ]; then + SUDO="" +elif command -v sudo >/dev/null 2>&1; then + SUDO="sudo" +else + SUDO="" +fi + +${SUDO} bash "${SCRIPT_DIR}/install_protoc.sh" +bash "${SCRIPT_DIR}/install_rustup.sh" diff --git a/sgl-model-gateway/rust-toolchain.toml b/sgl-model-gateway/rust-toolchain.toml new file mode 100644 index 000000000..5cb23e1bd --- /dev/null +++ b/sgl-model-gateway/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "1.90" +profile = "minimal" +components = ["clippy"]