sgl-project/sglang · error · ValueError

{manifest} declares python-module {python_module!r} but must

Error message

{manifest} declares python-module {python_module!r} but must also set `package.name` and `lib.name`

What it means

A Cargo manifest declares `[package.metadata.sglang] python-module` matching the requested module but omits `package.name` or `lib.name`, which the loader needs to locate the built library file.

Source

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

        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)
        if declared_module != python_module:
            continue

        package_name = package.get("name")
        library = document.get("lib", {}).get("name")
        if not package_name or not library:
            raise ValueError(
                f"{manifest} declares python-module {python_module!r} but must "
                "also set `package.name` and `lib.name`"
            )
        matches.append(
            _CrateSpec(
                package=package_name,
                library=library,
                python_module=python_module,
                workspace=workspace,
                features=tuple(sglang_metadata.get("features", ())),
            )
        )

    if not matches:
        raise ModuleNotFoundError(
            f"no Cargo package under {workspace} declares "
            f'`[package.metadata.sglang] python-module = "{python_module}"`; '
            f"declared modules: {sorted(declared_modules)}",

View on GitHub (pinned to 0132848349)

Solutions

  1. Set both `package.name` and `lib.name` in the crate's Cargo.toml
  2. Validate the manifest with `cargo metadata` or `tomllib` parsing
  3. Copy a working sibling crate's Cargo.toml as template

Example fix

# before
[package]
name = ""
[lib]
name = ""
[package.metadata.sglang]
python-module = "sglang._rust.x"
# after
[package]
name = "sglang-rust-x"
[lib]
name = "sglang_rust_x"
[package.metadata.sglang]
python-module = "sglang._rust.x"
Defensive patterns

Strategy: validation

Validate before calling

import tomllib
m = tomllib.loads(Path(manifest).read_text())
assert m.get("package",{}).get("name") and m.get("lib",{}).get("name"), "Cargo.toml needs package.name and lib.name"

Prevention

When it happens

Trigger: Adding a new Rust crate for a Python module with the sglang python-module metadata but leaving the manifest's package.name or [lib] name unset/empty.

Common situations: Hand-editing a new crate's Cargo.toml; template copy that drops fields; TOML typo like `lib.name` nested under the wrong table.

Related errors


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