{"record":{"id":"1b8e7a041208da99","repo":"zed-industries/zed","slug":"failed-to-build-extension","errorCode":null,"errorMessage":"failed to build extension {}","messagePattern":"failed to build extension (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/extension/src/extension_builder.rs","lineNumber":225,"sourceCode":"    ) -> anyhow::Result<()> {\n        self.install_rust_wasm_target_if_needed().await?;\n\n        let cargo_toml_content = fs::read_to_string(extension_dir.join(\"Cargo.toml\"))?;\n        let cargo_toml: CargoToml = toml::from_str(&cargo_toml_content)?;\n\n        log::info!(\"compiling Rust crate for extension {extension_dir:?}\");\n        let output = util::command::new_command(\"cargo\")\n            .args([\"build\", \"--target\", RUST_TARGET])\n            .args(options.release.then_some(\"--release\"))\n            .arg(\"--target-dir\")\n            .arg(extension_dir.join(\"target\"))\n            // WASI builds do not work with sccache and just stuck, so disable it.\n            .env(\"RUSTC_WRAPPER\", \"\")\n            .current_dir(extension_dir)\n            .output()\n            .await\n            .context(\"running `cargo`\")?;\n        anyhow::ensure!(\n            output.status.success(),\n            \"failed to build extension {}\",\n            String::from_utf8_lossy(&output.stderr)\n        );\n\n        log::info!(\"compiled Rust crate for extension {extension_dir:?}\");\n\n        let mut wasm_path = PathBuf::from(extension_dir);\n        wasm_path.extend([\n            \"target\",\n            RUST_TARGET,\n            if options.release { \"release\" } else { \"debug\" },\n            &cargo_toml\n                .package\n                .name\n                // The wasm32-wasip2 target normalizes `-` in package names to `_` in the resulting `.wasm` file.\n                .replace('-', \"_\"),\n        ]);","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/extension/src/extension_builder.rs#L207-L243","documentation":"The Rust compile step of extension building failed: the builder runs 'cargo build --target wasm32-wasip2' (RUST_TARGET) inside the extension dir with sccache disabled (RUSTC_WRAPPER=\"\"), and a non-zero exit status triggers this bail with cargo's stderr appended. This is the generic wrapper for any Rust compile failure in the extension crate itself.","triggerScenarios":"Any error cargo reports while building the extension crate for wasm32-wasip2: syntax/type errors in the extension code, a dependency that fails to compile for wasm, missing wasm32-wasip2 std (target not installed), lock-file/edition problems, or a rust-toolchain override in the extension dir selecting an incompatible toolchain.","commonSituations":"Extension code that compiles on desktop but uses APIs unavailable under wasm32-wasip2 (e.g. std::process::Command, raw file paths outside zed::fs), a dependency pulling in tokio full features or C code without wasm support, CI where the wasm target was never added, or a pinned old toolchain that lacks the wasip2 target.","solutions":["Reproduce locally in the extension directory to see the full log: 'cargo build --target wasm32-wasip2' (the bail message already carries cargo's stderr - read it first)","Fix the Rust errors it reports; for wasm-incompatible APIs switch to Zed's extension APIs (zed::fs, zed::Command via the language registry) instead of std::process/std::fs","Ensure the target exists: 'rustup target add wasm32-wasip2' (the builder normally auto-installs it - see errors 273-275)","Remove or align any rust-toolchain/rust-toolchain.toml in the extension dir that pins a toolchain without wasip2","Check dependency versions compile for wasm: 'cargo check --target wasm32-wasip2' in CI for the extension"],"exampleFix":"// before: extension code that cannot build for wasm32-wasip2\nlet output = std::process::Command::new(\"rg\").arg(\"--version\").output()?;\n\n// after: use the host API Zed exposes to extensions instead\nlet output = zed::Command::new(\"rg\").args([\"--version\"]).output().await?;","handlingStrategy":"try-catch","validationCode":"// Fail fast in CI before invoking the Zed builder\ncargo check --target wasm32-wasip2 --manifest-path ext/Cargo.toml","typeGuard":null,"tryCatchPattern":"match builder.compile_extension(&dir, &mut manifest, options, fs.clone()).await {\n    Ok(()) => Ok(()),\n    Err(err) if err.to_string().contains(\"failed to build extension\") => {\n        // err already carries cargo's stderr; surface it verbatim to the developer\n        Err(err.context(\"cargo could not build the extension for wasm32-wasip2 - fix the reported Rust errors\"))\n    }\n    Err(err) => Err(err),\n}","preventionTips":["Run 'cargo check --target wasm32-wasip2' in extension CI to catch wasm-incompatible code early","Keep wasm32-wasip2 installed ('rustup target add wasm32-wasip2') in dev and CI images","Avoid std::process/std::env/std::net in extension code; use the zed extension APIs"],"tags":["zed","extension","cargo","wasm","wasi","compile","rust"],"backgroundTag":"wasm-target-build-failure","analyzedSha":"9d272b036335401f339d024ea94968fd51016c40","analyzedAt":"2026-09-12T19:35:53.743Z","contentChangedAt":"2026-09-12T19:35:53.743Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}