sgl-project/sglang · error · FileNotFoundError

Cargo completed but did not produce the expected artifact {a

Error message

Cargo completed but did not produce the expected artifact {artifact}

What it means

Cargo exited successfully but the expected shared-library artifact (e.g. lib<name>.so under target/<triple>/release) is not at the computed path, so the loader cannot stage it.

Source

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

    ]
    if crate.features:
        command.extend(("--features", ",".join(crate.features)))

    environment = os.environ.copy()
    environment["CARGO_TARGET_DIR"] = os.fspath(target_dir)
    environment["PYO3_PYTHON"] = sys.executable
    logger.info("Building %s with `%s`", crate.python_module, " ".join(command))
    try:
        subprocess.run(command, cwd=crate.workspace, env=environment, check=True)
    except (OSError, subprocess.CalledProcessError) as exc:
        raise RuntimeError(f"failed to build {crate.python_module} with Cargo") from exc

    release_dir = target_dir / "release"
    if target := environment.get("CARGO_BUILD_TARGET"):
        release_dir = target_dir / target / "release"
    artifact = release_dir / _cargo_library_filename(crate.library)
    if not artifact.is_file():
        raise FileNotFoundError(
            f"Cargo completed but did not produce the expected artifact {artifact}"
        )
    return artifact


def _cargo_library_filename(library: str) -> str:
    if sys.platform == "win32":
        return f"{library}.dll"
    if sys.platform == "darwin":
        return f"lib{library}.dylib"
    return f"lib{library}.so"


def _stage_atomically(source: Path, destination: Path) -> None:
    destination.parent.mkdir(parents=True, exist_ok=True)
    descriptor, temporary_name = tempfile.mkstemp(
        prefix=f".{destination.name}.", dir=destination.parent
    )

View on GitHub (pinned to 0132848349)

Solutions

  1. Check the computed artifact path vs `find <target_dir> -name '*.so'` and fix lib.name/CARGO_BUILD_TARGET consistency
  2. Clear the target dir and rebuild
  3. Verify [lib] name and crate-type produce a cdylib
Defensive patterns

Strategy: validation

Validate before calling

# after building, confirm expected artifact exists
expected = target_dir / os.environ.get("CARGO_BUILD_TARGET", "") / "release"
assert any(expected.glob("lib*.so")) or any(expected.glob("*.dll"))

Prevention

When it happens

Trigger: CARGO_BUILD_TARGET triple mismatch, lib.name differing from the artifact actually produced, or build scripts placing output elsewhere; also unusual cargo configs changing target dir layout.

Common situations: Cross-compilation env vars set (CARGO_BUILD_TARGET) inconsistently; renamed lib without rebuilding; stale/overridden CARGO_TARGET_DIR behavior.

Related errors


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