zed-industries/zed · error
failed to retrieve the `{RUST_TARGET}` target libdir: {}
Error message
failed to retrieve the `{RUST_TARGET}` target libdir: {} What it means
Raised in `install_rust_wasm_target_if_needed` (crates/extension/src/extension_builder.rs:411) when `rustc --print target-libdir --target wasm32-wasip1` (RUST_TARGET) exits non-zero while building a Rust extension. The builder needs the target's libdir to verify the wasm target stdlib is installed; rustc refusing to answer means the target is not known to the installed toolchain or rustc itself is broken/mismatched.
Source
Thrown at crates/extension/src/extension_builder.rs:411
fetch_output.status.success(),
"failed to fetch revision {rev} in directory {directory:?}"
);
anyhow::bail!(
"failed to checkout revision {rev} in directory {directory:?}: {}",
String::from_utf8_lossy(&checkout_output.stderr)
);
}
Ok(())
}
async fn install_rust_wasm_target_if_needed(&self) -> Result<()> {
let rustc_output = util::command::new_command("rustc")
.args(["--print", "target-libdir", "--target", RUST_TARGET])
.output()
.await
.context("running rustc")?;
anyhow::ensure!(
rustc_output.status.success(),
"failed to retrieve the `{RUST_TARGET}` target libdir: {}",
String::from_utf8_lossy(&rustc_output.stderr)
);
let target_libdir = PathBuf::from(String::from_utf8(rustc_output.stdout)?.trim());
if target_libdir.exists() {
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"
);
View on GitHub (pinned to 9d272b0363)
Solutions
- Run `rustc --print target-libdir --target wasm32-wasip1` manually to see the underlying rustc stderr; fix the reported toolchain problem first.
- Update your toolchain to a recent stable Rust that knows wasm32-wasip1 (`rustup update stable` or install current stable via rustup instead of the distro package).
- Install the target explicitly: `rustup target add wasm32-wasip1`.
- For Nix rust-overlay/fenix toolchains, add the wasm target: `targets = ["wasm32-wasip1"]` in your toolchain definition.
- If your toolchain only supports the legacy name, ensure rustc >= 1.78 is used, or align the build with a toolchain that supports wasm32-wasip1.
Example fix
// before (shell): old distro rustc $ rustc --version rustc 1.63.0 // knows only wasm32-wasi, not wasm32-wasip1 // error: failed to retrieve the `wasm32-wasip1` target libdir: ... // after (shell): use rustup-managed current stable and add the target $ rustup install stable && rustup default stable $ rustup target add wasm32-wasip1
Defensive patterns
Strategy: validation
Validate before calling
# shell: confirm the toolchain recognizes the wasm target before building
rustc --print target-libdir --target wasm32-wasip1 \
|| { echo 'wasm32-wasip1 unknown to this toolchain; update rust / add the target'; exit 1; } Try / catch
try {
await buildExtension(path);
} catch (err) {
if (String(err).includes("target libdir")) {
console.error("Toolchain does not know wasm32-wasip1; run `rustc --print target-libdir --target wasm32-wasip1` to see rustc's own error.");
}
throw err;
} Prevention
- Use a current rustup-managed stable toolchain (>= 1.78) for extension development.
- Avoid relying on distro rustc packages for extension builds.
- Keep `rustup target add wasm32-wasip1` in your project setup docs/CI.
- Run the rustc --print target-libdir command once during environment setup to validate the toolchain.
When it happens
Trigger: Calling `compile_rust_extension` -> `install_rust_wasm_target_if_needed` where the `rustc --print target-libdir --target <RUST_TARGET>` subprocess exits non-zero. Specific conditions: the installed toolchain does not know the `wasm32-wasip1` target (older Rust versions only know `wasm32-wasi`; the target was renamed to wasm32-wasip1 in Rust 1.78+), rustc on PATH is from a partial/toolkit-only install without target metadata, or rustc emits an error due to a broken toolchain (missing sysroot, rustup shim pointing at a nonexistent toolchain).
Common situations: System-package-manager rustc (e.g. Debian/Ubuntu `rustc` package) that is too old to recognize wasm32-wasip1; Nix or custom toolchains without wasm targets; a stale rustup default toolchain after an upgrade; RUST_TARGET env drift between Zed's expected triple and what your toolchain supports.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- the `{RUST_TARGET}` target is not installed, and `rustup` is
- failed to install the `{RUST_TARGET}` target: {}
- failed to install dlv via `go install`. stdout: {:?}, stderr
- zig not found on $PATH, install zig (see https://ziglang.org
- failed to build extension {}
AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-09-12).
Data as JSON: /api/errors/aa44809c3fbdbcc2.
Report an issue: GitHub.