{"record":{"id":"aa44809c3fbdbcc2","repo":"zed-industries/zed","slug":"failed-to-retrieve-the-rust-target-target-libdir","errorCode":null,"errorMessage":"failed to retrieve the `{RUST_TARGET}` target libdir: {}","messagePattern":"failed to retrieve the `(.+?)` target libdir: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/extension/src/extension_builder.rs","lineNumber":411,"sourceCode":"                fetch_output.status.success(),\n                \"failed to fetch revision {rev} in directory {directory:?}\"\n            );\n            anyhow::bail!(\n                \"failed to checkout revision {rev} in directory {directory:?}: {}\",\n                String::from_utf8_lossy(&checkout_output.stderr)\n            );\n        }\n\n        Ok(())\n    }\n\n    async fn install_rust_wasm_target_if_needed(&self) -> Result<()> {\n        let rustc_output = util::command::new_command(\"rustc\")\n            .args([\"--print\", \"target-libdir\", \"--target\", RUST_TARGET])\n            .output()\n            .await\n            .context(\"running rustc\")?;\n        anyhow::ensure!(\n            rustc_output.status.success(),\n            \"failed to retrieve the `{RUST_TARGET}` target libdir: {}\",\n            String::from_utf8_lossy(&rustc_output.stderr)\n        );\n\n        let target_libdir = PathBuf::from(String::from_utf8(rustc_output.stdout)?.trim());\n        if target_libdir.exists() {\n            return Ok(());\n        }\n\n        anyhow::ensure!(\n            which::which(\"rustup\").is_ok(),\n            \"the `{RUST_TARGET}` target is not installed, and `rustup` is not available to \\\n             install it. Add the target to your Rust toolchain (e.g. `targets = \\\n             [\\\"{RUST_TARGET}\\\"]` for Nix rust-overlay/fenix toolchains) or install it via \\\n             your package manager\"\n        );\n","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/extension/src/extension_builder.rs#L393-L429","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before (shell): old distro rustc\n$ rustc --version\nrustc 1.63.0  // knows only wasm32-wasi, not wasm32-wasip1\n// error: failed to retrieve the `wasm32-wasip1` target libdir: ...\n\n// after (shell): use rustup-managed current stable and add the target\n$ rustup install stable && rustup default stable\n$ rustup target add wasm32-wasip1","handlingStrategy":"validation","validationCode":"# shell: confirm the toolchain recognizes the wasm target before building\nrustc --print target-libdir --target wasm32-wasip1 \\\n  || { echo 'wasm32-wasip1 unknown to this toolchain; update rust / add the target'; exit 1; }","typeGuard":null,"tryCatchPattern":"try {\n  await buildExtension(path);\n} catch (err) {\n  if (String(err).includes(\"target libdir\")) {\n    console.error(\"Toolchain does not know wasm32-wasip1; run `rustc --print target-libdir --target wasm32-wasip1` to see rustc's own error.\");\n  }\n  throw err;\n}","preventionTips":["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."],"tags":["rust","toolchain","wasm","build"],"backgroundTag":"missing-dependency","analyzedSha":"9d272b036335401f339d024ea94968fd51016c40","analyzedAt":"2026-09-12T19:35:53.743Z","contentChangedAt":"2026-09-12T19:35:53.743Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}