Build Rust extensions on demand in source checkouts (#34994)

This commit is contained in:
Lianmin Zheng
2026-08-16 14:58:06 -07:00
committed by GitHub
parent 0e231d365a
commit 67e12131df
39 changed files with 880 additions and 109 deletions
+7 -7
View File
@@ -460,7 +460,7 @@ require_prebuilt_rust_exts() {
return
fi
# Exact EXT_SUFFIX rather than a _core*.so glob: no crate sets abi3, so a module
# Exact EXT_SUFFIX rather than an _*.so glob: no crate sets abi3, so a module
# built for another minor version satisfies the glob while the import system
# ignores it, leaving is_rust_server_built() false and the Rust-server tests
# silently skipped. Stages have no setup-python, so the interpreter is whatever
@@ -469,13 +469,13 @@ require_prebuilt_rust_exts() {
local suffix
suffix=$(python3 -c 'import sysconfig; print(sysconfig.get_config_var("EXT_SUFFIX"))')
local missing=()
local pkg
for pkg in server grpc multimodal; do
[ -f "python/sglang/srt/${pkg}/_core${suffix}" ] || missing+=("${pkg}")
local module
for module in server grpc multimodal; do
[ -f "python/sglang/srt/rust_extensions/_${module}${suffix}" ] || missing+=("${module}")
done
if [ ${#missing[@]} -gt 0 ]; then
echo "::warning::no prebuilt _core${suffix} for: ${missing[*]}; building from source"
ls -l python/sglang/srt/*/_core*.so 2>/dev/null || echo "(no extension modules at all)"
echo "::warning::no prebuilt Rust extension ${suffix} for: ${missing[*]}; building from source"
ls -l python/sglang/srt/rust_extensions/_*.so 2>/dev/null || echo "(no extension modules at all)"
export SGLANG_BUILD_RUST_EXTS=
mark_step_done "${FUNCNAME[0]}"
return
@@ -812,7 +812,7 @@ print(f"sglang resolves to {spec.origin}")
# so a .so that cannot load passes find_spec and only fails inside some suite.
import importlib
for mod in ("server", "grpc", "multimodal"):
name = f"sglang.srt.{mod}._core"
name = f"sglang.srt.rust_extensions._{mod}"
try:
importlib.import_module(name)
except Exception as exc:
+2 -1
View File
@@ -74,7 +74,8 @@ else
rm -f "${REPO_ROOT}/python/pyproject.toml" && mv "${REPO_ROOT}/python/pyproject_other.toml" "${REPO_ROOT}/python/pyproject.toml"
# setuptools-rust builds the sglang-mm extension (sglang.srt.multimodal._core)
# setuptools-rust builds the sglang-mm extension
# (sglang.srt.rust_extensions._multimodal)
# declared in pyproject_other.toml, so a Rust toolchain must be present like
# on the CUDA/AMD CI paths. Idempotent; installs per-user under $HOME/.cargo.
# Export PATH here because the pip install below runs in this same shell
+9 -9
View File
@@ -1,5 +1,5 @@
#!/bin/bash
# Copy the built PyO3 extension modules into rust-ext-staging/<pkg>/ for
# Copy the built PyO3 extension modules into rust-ext-staging/rust_extensions/ for
# upload-artifact. Shared by both jobs of _pr-test-rust-ext-build.yml, so the
# archive layout and the module-count check cannot drift between them.
#
@@ -12,24 +12,24 @@ shopt -s nullglob
# module would silently shift the archive layout.
rm -rf rust-ext-staging
built=()
# Same suffix set across pkgs, or one ABI's Rust-server tests silently skip.
# Same suffix set across modules, or one ABI's Rust-server tests silently skip.
expected_suffixes=""
for pkg in server grpc multimodal; do
found=(python/sglang/srt/"${pkg}"/_core*.so)
mkdir -p rust-ext-staging/rust_extensions
for module in server grpc multimodal; do
found=(python/sglang/srt/rust_extensions/_"${module}"*.so)
if [ ${#found[@]} -eq 0 ]; then
echo "::error::no extension module found for ${pkg}"
echo "::error::no extension module found for ${module}"
exit 1
fi
suffixes=$(printf '%s\n' "${found[@]##*/_core}" | sort)
suffixes=$(printf '%s\n' "${found[@]##*/_${module}}" | sort)
if [ -z "${expected_suffixes}" ]; then
expected_suffixes="${suffixes}"
elif [ "${suffixes}" != "${expected_suffixes}" ]; then
echo "::error::extension modules for ${pkg} do not match server's interpreter set"
echo "::error::extension modules for ${module} do not match server's interpreter set"
printf 'have:\n%s\nwant:\n%s\n' "${suffixes}" "${expected_suffixes}"
exit 1
fi
mkdir -p "rust-ext-staging/${pkg}"
cp "${found[@]}" "rust-ext-staging/${pkg}/"
cp "${found[@]}" rust-ext-staging/rust_extensions/
built+=("${found[@]}")
done
max_allowed="${MAX_GLIBC:-}"