sgl-project/sglang · error · RuntimeError
failed to query the Rust toolchain with
Error message
failed to query the Rust toolchain with `{command} {' '.join(arguments)}` What it means
The loader ran the Rust toolchain query (e.g. `cargo metadata`/`rustc -vV` style command, shown in the message) and it failed — non-zero exit or unusable output. Typically means cargo/rustc is missing, broken, or the manifest directory is invalid.
Solutions
- Install Rust (rustup) and verify `cargo --version` runs in the same shell/env as Python
- Fix PATH so the toolchain is visible to the Python process
- Reinstall/repair a corrupted rustup toolchain
- Prefer the prebuilt wheel extension to avoid needing a toolchain
Defensive patterns
Strategy: fallback
Validate before calling
import shutil
assert shutil.which("cargo") and shutil.which("rustc"), "Rust toolchain required for source builds" Try / catch
try:
load_rust_extension(...)
except RuntimeError as e:
if "Rust toolchain" in str(e): install_rust_or_use_wheel() Prevention
- Install rustup in CI images that build from source
- Prefer prebuilt wheels on machines without Rust
When it happens
Trigger: load_rust_extension with cargo/rustc missing from PATH, not executable, or crashing (corrupt toolchain, permission denied).
Common situations: CI image without Rust installed; activated conda env shadowing cargo; broken rustup installation; PATH not propagated to the Python process.
Related errors
- Can not import FA3 in sgl_kernel. Please check your…
- Cargo completed but did not produce the expected artifact
- Command contains only environment variable assignments, no…
- cuda.bindings.driver is required for CUDA VMM operations
- Environment variable SGLANG_LOCAL_IP_NIC requires package…
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/b12038336fa1647b.
Report an issue: GitHub.
Appendix: source
Thrown at python/sglang/srt/rust_extensions/loader.py:283
directories[:] = sorted(
name for name in directories if name not in _IGNORED_SOURCE_DIRECTORIES
)
root_path = Path(root)
for filename in sorted(filenames):
yield root_path / filename
def _command_version(command: str, *arguments: str, cwd: Path) -> str:
try:
result = subprocess.run(
[command, *arguments],
check=True,
capture_output=True,
text=True,
cwd=cwd,
)
except (OSError, subprocess.CalledProcessError) as exc:
raise RuntimeError(
f"failed to query the Rust toolchain with `{command} {' '.join(arguments)}`"
) from exc
return result.stdout.strip()
def _json_digest(value: object) -> str:
serialized = json.dumps(
value, sort_keys=True, separators=(",", ":"), ensure_ascii=True
).encode()
return hashlib.sha256(serialized).hexdigest()
def _cache_root(cache_dir: Path | None) -> Path:
if cache_dir is not None:
return Path(cache_dir).expanduser().resolve()
sglang_cache = envs.SGLANG_CACHE_DIR.get()
return Path(sglang_cache).expanduser().resolve() / "rust_extensions"
View on GitHub (pinned to 0132848349)