zed-industries/zed · error

failed to install the `{RUST_TARGET}` target: {}

Error message

failed to install the `{RUST_TARGET}` target: {}

What it means

This error is thrown by the extension builder when `rustup target add wasm32-wasip1-threads` (RUST_TARGET) exits with a non-zero status while preparing to compile a Rust extension to WebAssembly. The command's captured stderr is embedded in the message so the underlying rustup failure (network error, unknown target, missing rustup toolchain) is visible. It is a deliberate `ensure!` check after running `rustup target add` with stderr piped.

Source

Thrown at crates/extension/src/extension_builder.rs:437

            return Ok(());
        }

        anyhow::ensure!(
            which::which("rustup").is_ok(),
            "the `{RUST_TARGET}` target is not installed, and `rustup` is not available to \
             install it. Add the target to your Rust toolchain (e.g. `targets = \
             [\"{RUST_TARGET}\"]` for Nix rust-overlay/fenix toolchains) or install it via \
             your package manager"
        );

        let output = util::command::new_command("rustup")
            .args(["target", "add", RUST_TARGET])
            .stderr(Stdio::piped())
            .stdout(Stdio::inherit())
            .output()
            .await
            .context("running `rustup target add`")?;
        anyhow::ensure!(
            output.status.success(),
            "failed to install the `{RUST_TARGET}` target: {}",
            String::from_utf8_lossy(&output.stderr)
        );

        Ok(())
    }

    async fn install_wasi_sdk_if_needed(&self) -> Result<PathBuf> {
        if let Some(sdk_path) = env::var_os("WASI_SDK_PATH").filter(|path| !path.is_empty()) {
            let sdk_path = PathBuf::from(sdk_path);
            let clang_path = wasi_sdk_clang_path(&sdk_path);
            if fs::metadata(&clang_path).is_ok_and(|metadata| metadata.is_file()) {
                log::info!("using wasi-sdk from WASI_SDK_PATH: {sdk_path:?}");
                return Ok(clang_path);
            }
            log::warn!(
                "WASI_SDK_PATH is set to {sdk_path:?} but clang was not found at {clang_path:?}, falling back to download"

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Install rustup (https://rustup.rs) and ensure `rustup` is on your PATH.
  2. Run `rustup target add wasm32-wasip1-threads` manually to see the full rustup error.
  3. Update rustup with `rustup self update` if the target name is unrecognized (older rustup versions predate the wasip1-threads naming).
  4. Check network connectivity / proxy settings if rustup fails to download the target components.
  5. Verify the active toolchain supports the target: `rustup toolchain list` and re-add the target for the default toolchain.

Example fix

// before (bare toolchain, no rustup)
$ cargo build  # -> failed to install the `wasm32-wasip1-threads` target: ...

// after
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
$ rustup target add wasm32-wasip1-threads
$ cargo build
Defensive patterns

Strategy: validation

Validate before calling

let ok = std::process::Command::new("rustup")
    .args(["target", "list", "--installed"])
    .output()
    .map(|o| o.status.success())
    .unwrap_or(false);
if !ok { eprintln!("rustup missing or broken; install it before building extensions"); }

Try / catch

match build_extension().await {
    Err(e) if e.to_string().contains("failed to install the `") => {
        eprintln!("Install rustup and run `rustup target add wasm32-wasip1-threads` first: {e}");
    }
    Err(e) => return Err(e),
    Ok(v) => Ok(v),
}

Prevention

When it happens

Trigger: Calling compile_rust_extension (via install_rust_wasm_target_if_needed) when the `rustup target add <RUST_TARGET>` subprocess fails: rustup is not installed or not on PATH, the target triple is not available for the installed toolchain, or the network download of the target components fails.

Common situations: Developers building a Zed extension without rustup installed (using only a bare rustc via distro packages); offline or behind a proxy so rustup cannot download the wasm target; an outdated rustup that does not recognize the `wasm32-wasip1-threads` target name after it was renamed from `wasm32-wasi`.

Related errors


AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-09-12). Data as JSON: /api/errors/03acf1f5a2ad1fb2. Report an issue: GitHub.