zed-industries/zed · error
failed to build extension {}
Error message
failed to build extension {} What it means
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.
Source
Thrown at crates/extension/src/extension_builder.rs:225
) -> anyhow::Result<()> {
self.install_rust_wasm_target_if_needed().await?;
let cargo_toml_content = fs::read_to_string(extension_dir.join("Cargo.toml"))?;
let cargo_toml: CargoToml = toml::from_str(&cargo_toml_content)?;
log::info!("compiling Rust crate for extension {extension_dir:?}");
let output = util::command::new_command("cargo")
.args(["build", "--target", RUST_TARGET])
.args(options.release.then_some("--release"))
.arg("--target-dir")
.arg(extension_dir.join("target"))
// WASI builds do not work with sccache and just stuck, so disable it.
.env("RUSTC_WRAPPER", "")
.current_dir(extension_dir)
.output()
.await
.context("running `cargo`")?;
anyhow::ensure!(
output.status.success(),
"failed to build extension {}",
String::from_utf8_lossy(&output.stderr)
);
log::info!("compiled Rust crate for extension {extension_dir:?}");
let mut wasm_path = PathBuf::from(extension_dir);
wasm_path.extend([
"target",
RUST_TARGET,
if options.release { "release" } else { "debug" },
&cargo_toml
.package
.name
// The wasm32-wasip2 target normalizes `-` in package names to `_` in the resulting `.wasm` file.
.replace('-', "_"),
]);View on GitHub (pinned to 9d272b0363)
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
Example fix
// before: extension code that cannot build for wasm32-wasip2
let output = std::process::Command::new("rg").arg("--version").output()?;
// after: use the host API Zed exposes to extensions instead
let output = zed::Command::new("rg").args(["--version"]).output().await?; Defensive patterns
Strategy: try-catch
Validate before calling
// Fail fast in CI before invoking the Zed builder cargo check --target wasm32-wasip2 --manifest-path ext/Cargo.toml
Try / catch
match builder.compile_extension(&dir, &mut manifest, options, fs.clone()).await {
Ok(()) => Ok(()),
Err(err) if err.to_string().contains("failed to build extension") => {
// err already carries cargo's stderr; surface it verbatim to the developer
Err(err.context("cargo could not build the extension for wasm32-wasip2 - fix the reported Rust errors"))
}
Err(err) => Err(err),
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- DAP returned IPv6 host {addr}, which the v0.6.0 extension AP
- extension {} has invalid zed:api-version section: {:?}
- failed to fetch '{url}': status code {}
- Unknown settings category: {}
- failed to fetch '{url}': status code {}
AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-09-12).
Data as JSON: /api/errors/1b8e7a041208da99.
Report an issue: GitHub.