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
- Restore or regenerate Cargo.lock (run `cargo generate-lockfile` in the workspace) and commit it
- Remove the Cargo.lock entry from .gitignore
- 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
- Commit Cargo.lock; never gitignore it in binary-crate workspaces
- CI preflight asserts Cargo.lock exists
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
- Rust sources under {crate.workspace} changed during the buil
- Rust workspace for {python_module} was not found at {workspa
- {manifest} declares python-module {python_module!r} but must
- failed to build {crate.python_module} with Cargo
- Cargo completed but did not produce the expected artifact {a
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/dfec3c3f1cd99cb2.
Report an issue: GitHub.