{"record":{"id":"450e07abd286fbe5","repo":"zed-industries/zed","slug":"failed-to-compile-parser-with-clang","errorCode":null,"errorMessage":"failed to compile {} parser with clang: {}","messagePattern":"failed to compile (.+?) parser with clang: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/extension/src/extension_builder.rs","lineNumber":351,"sourceCode":"                \"skipping compilation of {grammar_name} parser because the existing compiled grammar is up to date\"\n            );\n        } else {\n            log::info!(\"compiling {grammar_name} parser\");\n            let clang_output = util::command::new_command(&clang_path)\n                .args([\"-fPIC\", \"-shared\", \"-Os\"])\n                .arg(format!(\"-Wl,--export=tree_sitter_{grammar_name}\"))\n                .arg(\"-o\")\n                .arg(&grammar_wasm_path)\n                .arg(\"-I\")\n                .arg(&src_path)\n                .arg(&parser_path)\n                .args(scanner_path.exists().then_some(scanner_path))\n                .output()\n                .await\n                .context(\"failed to run clang\")?;\n\n            if !clang_output.status.success() {\n                bail!(\n                    \"failed to compile {} parser with clang: {}\",\n                    grammar_name,\n                    String::from_utf8_lossy(&clang_output.stderr),\n                );\n            }\n        }\n\n        Ok(())\n    }\n\n    async fn checkout_repo(&self, directory: &Path, url: &str, rev: &str) -> Result<()> {\n        let git_dir = directory.join(\".git\");\n\n        if directory.exists() {\n            let remotes_output = util::command::new_command(\"git\")\n                .arg(\"--git-dir\")\n                .arg(&git_dir)\n                .args([\"remote\", \"get-url\", \"origin\"])","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/extension/src/extension_builder.rs#L333-L369","documentation":"The tree-sitter grammar compilation step failed: the builder invokes the wasi-sdk clang to compile the grammar's parser.c (plus scanner.c/.cc if present) to a wasm module exporting tree_sitter_{grammar_name}, and a non-zero clang exit status bails with clang's stderr. {grammar_name} identifies which grammar in the extension.toml [grammars] table failed.","triggerScenarios":"Running an extension build that includes grammars where clang rejects the C sources: missing generated parser.c at the pinned rev, scanner.c/scanner.cc errors, incompatible tree-sitter ABI (LANGUAGE_VERSION mismatch headers), clang running out of memory, or a broken/partial wasi-sdk in the cache.","commonSituations":"Grammar repo whose src/parser.c was never generated or was removed at the pinned commit; grammar written against a newer tree-sitter CLI than the vendored parser runtime; scanner using C++ features while being compiled as C; corrupted wasi-sdk download in the extension cache dir.","solutions":["Read clang's stderr in the message - it names the file and line that failed","Verify the pinned rev actually contains src/parser.c: clone the grammar repo, 'git checkout <rev>' and inspect src/","If parser.c is missing, generate it with 'tree-sitter generate' upstream and pin to a rev that has it, or pick another rev","Test-compile locally with the cached wasi-sdk clang using the same flags (-I src parser.c scanner.c -Wl,--export=tree_sitter_<name>) to iterate fast","If clang itself failed (not the sources), clear the cached wasi-sdk dir under the extension builder cache to force a clean re-download"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Ensure the pinned rev has generated parser sources before building\nlet has_parser = std::path::Path::new(&format!(\"{cache}/{grammar}/src/parser.c\")).exists();\nanyhow::ensure!(has_parser, \"grammar {grammar} has no src/parser.c at rev {rev}\");","typeGuard":null,"tryCatchPattern":"if let Err(err) = build_result {\n    if err.to_string().contains(\"parser with clang\") {\n        // err contains clang stderr: file/line of the failing C source\n        return Err(err.context(\"grammar C sources failed to compile - see clang diagnostics above\"));\n    }\n    return Err(err);\n}","preventionTips":["Pin grammar revs that contain generated src/parser.c; verify before releasing","Compile new grammar versions locally with tree-sitter first to catch scanner/parser breakage","Keep the wasi-sdk cache clean so clang failures are source failures, not toolchain failures"],"tags":["zed","extension","grammar","tree-sitter","clang","wasi-sdk","c"],"backgroundTag":"native-compile-failure","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}