{"record":{"id":"534df971af95a210","repo":"sgl-project/sglang","slug":"cargo-completed-but-did-not-produce-the-expected-a","errorCode":null,"errorMessage":"Cargo completed but did not produce the expected artifact {artifact}","messagePattern":"Cargo completed but did not produce the expected artifact (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/rust_extensions/loader.py","lineNumber":357,"sourceCode":"    ]\n    if crate.features:\n        command.extend((\"--features\", \",\".join(crate.features)))\n\n    environment = os.environ.copy()\n    environment[\"CARGO_TARGET_DIR\"] = os.fspath(target_dir)\n    environment[\"PYO3_PYTHON\"] = sys.executable\n    logger.info(\"Building %s with `%s`\", crate.python_module, \" \".join(command))\n    try:\n        subprocess.run(command, cwd=crate.workspace, env=environment, check=True)\n    except (OSError, subprocess.CalledProcessError) as exc:\n        raise RuntimeError(f\"failed to build {crate.python_module} with Cargo\") from exc\n\n    release_dir = target_dir / \"release\"\n    if target := environment.get(\"CARGO_BUILD_TARGET\"):\n        release_dir = target_dir / target / \"release\"\n    artifact = release_dir / _cargo_library_filename(crate.library)\n    if not artifact.is_file():\n        raise FileNotFoundError(\n            f\"Cargo completed but did not produce the expected artifact {artifact}\"\n        )\n    return artifact\n\n\ndef _cargo_library_filename(library: str) -> str:\n    if sys.platform == \"win32\":\n        return f\"{library}.dll\"\n    if sys.platform == \"darwin\":\n        return f\"lib{library}.dylib\"\n    return f\"lib{library}.so\"\n\n\ndef _stage_atomically(source: Path, destination: Path) -> None:\n    destination.parent.mkdir(parents=True, exist_ok=True)\n    descriptor, temporary_name = tempfile.mkstemp(\n        prefix=f\".{destination.name}.\", dir=destination.parent\n    )","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/rust_extensions/loader.py#L339-L375","documentation":"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.","triggerScenarios":"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.","commonSituations":"Cross-compilation env vars set (CARGO_BUILD_TARGET) inconsistently; renamed lib without rebuilding; stale/overridden CARGO_TARGET_DIR behavior.","solutions":["Check the computed artifact path vs `find <target_dir> -name '*.so'` and fix lib.name/CARGO_BUILD_TARGET consistency","Clear the target dir and rebuild","Verify [lib] name and crate-type produce a cdylib"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# after building, confirm expected artifact exists\nexpected = target_dir / os.environ.get(\"CARGO_BUILD_TARGET\", \"\") / \"release\"\nassert any(expected.glob(\"lib*.so\")) or any(expected.glob(\"*.dll\"))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep lib.name consistent with package name and crate-type=cdylib","Clean target dir after changing lib.name or target triple"],"tags":["rust","cargo","artifact","build-output"],"backgroundTag":"missing-build-artifact","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}