sgl-project/sglang · error · RuntimeError

failed to query the Rust toolchain with `{command} {' '.join

Error message

failed to query the Rust toolchain with `{command} {' '.join(arguments)}`

What it means

The loader failed to run a Rust toolchain query command (e.g. `cargo --version` / `rustc --version`) — the process could not start or exited non-zero — so it cannot compute the build fingerprint.

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)

Solutions

  1. Install Rust (rustup) and verify `cargo --version` runs in the same shell/env as Python
  2. Fix PATH so the toolchain is visible to the Python process
  3. Reinstall/repair a corrupted rustup toolchain
  4. 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

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


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/b12038336fa1647b. Report an issue: GitHub.