Prhub

#23700 ci: consolidate rust + protoc install across workflows

原始 PR 作者 alexnails 合并时间 2026-04-30 04:39 文件变更 8 提交数 4 评论 4 代码增减 +61 / -26

执行摘要

统一 CI 中 Rust 与 protoc 安装流程

消除 CI 中重复的安装步骤,确保 Rust toolchain 版本一致,并利用缓存减少 CPU job 的构建时间。具体引用 PR body:"Eliminates the 6-line Install protoc + Install Rust toolchain stanza copy-pasted across CPU jobs and the duplicate rustup-install line in the gateway script."

建议合并,该 PR 通过集中化脚本和版本锁定显著提升 CI 可维护性,值得作为 CI 标准化参考。

讨论亮点

无公开讨论,PR 合并前无 review 争议。

实现拆解

  1. 创建统一安装入口脚本scripts/ci/utils/install_rust_protoc.sh 封装了 sudo 判断,依次调用 install_protoc.shinstall_rustup.sh,保证幂等性。
  2. 锁定 Rust 工具链版本:在 rust/sglang-grpc/sgl-model-gateway/ 下分别添加 rust-toolchain.toml,channel 固定为 1.90
  3. 改造 CI 调用点
    • scripts/ci/cuda/ci_install_gateway_dependencies.sh:移除手写 rustup 安装,改为调用新脚本。
    • scripts/ci/cuda/ci_install_dependency.sh:同样替换。
    • .github/workflows/pr-test.ymlrerun-test.ymlpr-test-rust.yml:将原先两步(Install protoc + Install Rust toolchain)合并为一步,并添加 timeout-minutes: 10
  4. 添加 Rust 缓存:在 pr-test.yml 的 stage-a-test-cpu 中引入 Swatinem/rust-cache@v2,缓存 rust/sglang-grpc 构建产物,并通过 save-if 限制只有第一个分区保存避免竞态。
  5. 精简 protoc 安装依赖install_protoc.sh 移除了 wgetunzip 之外的不必要 apt 包(gccg++perlmake),因为 protoc 官方包已是静态二进制。
文件 模块 状态 重要度
scripts/ci/utils/install_rust_protoc.sh 安装脚本 added 4.83
scripts/ci/cuda/ci_install_gateway_dependencies.sh 依赖安装 modified 4.38
sgl-model-gateway/rust-toolchain.toml Rust 配置 added 4.16
.github/workflows/pr-test.yml CI 配置 modified 4.09
rust/sglang-grpc/rust-toolchain.toml Rust 配置 added 3.68
.github/workflows/rerun-test.yml CI 配置 modified 3.55
scripts/ci/utils/install_protoc.sh 安装工具 modified 3.41
scripts/ci/cuda/ci_install_dependency.sh 依赖安装 modified 3.21

关键源码片段

scripts/ci/utils/install_rust_protoc.sh infrastructure

核心统一安装脚本,被所有 workflow 调用,替代原先分散的步骤。

#!/bin/bash
# 安装 protoc(全局)和 Rust 工具链(用户),幂等地调用子脚本。
#
# protoc 需要 root 权限(写入 /usr/local),rustup 必须以普通用户运行。
set -euxo pipefail
​
# 获取脚本所在目录,用于定位子脚本
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"# 检测是否需要 sudo(若已为 root 则无需)
if [ "$(id -u)" = "0" ]; then
  SUDO=""
elif command -v sudo >/dev/null 2>&1; then
  SUDO="sudo"
else
  SUDO=""
fi# 先安装 protoc(需要 root),再安装 rustup(普通用户)
${SUDO} bash "${SCRIPT_DIR}/install_protoc.sh"
bash "${SCRIPT_DIR}/install_rustup.sh"

评论区精华

没有提炼出高价值讨论线程

当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。

风险与影响

低风险。主要风险点:安装脚本需要 root 权限安装 protoc 但 rustup 需要用户权限,脚本通过 SUDO 判断正确处理;rust-cache 在多分区并行时可能竞态,但已通过 save-if: ${{ matrix.partition == 0 }} 限制。

仅影响 CI 构建流程,对用户功能无影响。统一后降低 CI 维护成本,toolchain 版本一致减少因版本差异导致的构建失败。

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论