{"record":{"id":"d4cd5afabdda7d1c","repo":"sgl-project/sglang","slug":"apple-toolchain-not-found-install-the-xcode-comma","errorCode":null,"errorMessage":"Apple toolchain not found. Install the Xcode Command Line Tools with `xcode-select --install` (or a full Xcode install) and retry.","messagePattern":"Apple toolchain not found\\. Install the Xcode Command Line Tools with `xcode-select --install` \\(or a full Xcode install\\) and retry\\.","errorType":"console","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/aot/setup_metal.py","lineNumber":39,"sourceCode":"import sys\nimport sysconfig\nfrom pathlib import Path\n\nroot = Path(__file__).parent.resolve()\n\n\n_BUILD_REQUIRES = [\n    (\"setuptools\", \"setuptools\"),\n    (\"mlx\", \"mlx\"),\n    (\"nanobind\", \"nanobind\"),\n]\n\n\ndef _ensure_toolchain():\n    if sys.platform != \"darwin\" or platform.machine() != \"arm64\":\n        raise SystemExit(\"setup_metal.py only supports macOS (Apple Silicon).\")\n    if shutil.which(\"c++\") is None or shutil.which(\"xcrun\") is None:\n        raise SystemExit(\n            \"Apple toolchain not found. Install the Xcode Command Line Tools \"\n            \"with `xcode-select --install` (or a full Xcode install) and retry.\"\n        )\n    try:\n        subprocess.check_output(\n            [\"xcrun\", \"-sdk\", \"macosx\", \"metal\", \"--version\"],\n            stderr=subprocess.STDOUT,\n        )\n    except (subprocess.CalledProcessError, FileNotFoundError) as exc:\n        raise SystemExit(\n            \"Apple Metal shader compiler not found. Install a full Xcode \"\n            \"(not just Command Line Tools) so that `xcrun -sdk macosx metal` \"\n            \"is available, then retry.\"\n        ) from exc\n\n\ndef _ensure_build_requires():\n    missing = []","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/aot/setup_metal.py#L21-L57","documentation":"setup_metal.py checks that the `c++` compiler and `xcrun` are on PATH before building. If either is missing, it exits with instructions to install the Xcode Command Line Tools, since the Metal extension cannot be compiled without them.","triggerScenarios":"Building the Metal extension on a Mac without Xcode CLT installed, or with a broken/PREPENDED PATH that hides /usr/bin/c++ or /usr/bin/xcrun (common in sanitized conda/venv environments).","commonSituations":"Fresh macOS machines or CI runners without CLT; environments where xcode-select points to an invalid developer dir; PATH stripped by a wrapper script.","solutions":["Run `xcode-select --install` (or install full Xcode) and retry","Verify with `xcode-select -p` that a valid developer dir is selected; run sudo xcode-select -r if broken","Check `which c++ xcrun` inside the same shell/venv used to build; fix PATH if either is missing"],"exampleFix":"# before\npython setup_metal.py build_ext --inplace  # fails: Apple toolchain not found\n# after\nxcode-select --install\npython setup_metal.py build_ext --inplace","handlingStrategy":"validation","validationCode":"assert shutil.which('c++') and shutil.which('xcrun')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run xcode-select --install on fresh Macs","Check xcode-select -p before builds"],"tags":["metal","build","xcode","missing-toolchain","macos"],"backgroundTag":"missing-build-toolchain","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}