sgl-project/sglang · error · FileNotFoundError

{lockfile} is required for reproducible `cargo build --locke

Error message

{lockfile} is required for reproducible `cargo build --locked` builds

What it means

The discovered Cargo workspace has Cargo.toml but no Cargo.lock; the loader enforces `cargo build --locked` for reproducibility and refuses to build without a lockfile.

Source

Thrown at python/sglang/srt/rust_extensions/loader.py:152

def _import_bundled_extension(module_name: str) -> ModuleType | None:
    try:
        return importlib.import_module(module_name)
    except ModuleNotFoundError as exc:
        if exc.name == module_name:
            return None
        raise


def _discover_crate(workspace: Path, python_module: str) -> _CrateSpec:
    workspace = Path(workspace).resolve()
    workspace_manifest = workspace / "Cargo.toml"
    lockfile = workspace / "Cargo.lock"
    if not workspace_manifest.is_file():
        raise FileNotFoundError(
            f"Rust workspace for {python_module} was not found at {workspace}"
        )
    if not lockfile.is_file():
        raise FileNotFoundError(
            f"{lockfile} is required for reproducible `cargo build --locked` builds"
        )

    matches: list[_CrateSpec] = []
    declared_modules: list[str] = []
    for manifest in _source_files(workspace):
        if manifest.name != "Cargo.toml":
            continue
        with manifest.open("rb") as file:
            document = tomllib.load(file)
        package = document.get("package")
        if not isinstance(package, dict):
            continue
        sglang_metadata = package.get("metadata", {}).get("sglang", {})
        declared_module = sglang_metadata.get("python-module")
        if declared_module is None:
            continue
        declared_modules.append(declared_module)

View on GitHub (pinned to 0132848349)

Solutions

  1. Restore or regenerate Cargo.lock (run `cargo generate-lockfile` in the workspace) and commit it
  2. Remove the Cargo.lock entry from .gitignore
  3. If installable, use the prebuilt wheel extension instead of source builds
Defensive patterns

Strategy: validation

Validate before calling

lock = Path(workspace) / "Cargo.lock"
if not lock.is_file():
    subprocess.run(["cargo", "generate-lockfile"], cwd=workspace, check=True)

Prevention

When it happens

Trigger: Calling load_rust_extension on a workspace whose Cargo.lock was deleted, gitignored, or never generated.

Common situations: A .gitignore that excludes Cargo.lock; fresh fork missing the lockfile; CI caching that strips the file.

Related errors


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