{"record":{"id":"93e538087a23cd16","repo":"sxyazi/yazi","slug":"rustc-print-target-libdir-failed","errorCode":null,"errorMessage":"`rustc --print target-libdir` failed","messagePattern":"`rustc --print target-libdir` failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-build/src/build.rs","lineNumber":54,"sourceCode":"\t\t\tcmd.arg(\"--target\").arg(&self.target);\n\t\t}\n\t\tif self.completions {\n\t\t\tcmd.env(\"YAZI_GEN_COMPLETIONS\", \"1\");\n\t\t}\n\n\t\trun(&mut cmd).context(\"failed to build Yazi\")\n\t}\n\n\tpub(super) fn profile(&self) -> &'static str {\n\t\tif is_windows_target(&self.target) { \"release-windows\" } else { \"release\" }\n\t}\n\n\tfn has_rust_lld() -> Result<bool> {\n\t\tlet output = Command::new(env::var_os(\"RUSTC\").unwrap_or_else(|| \"rustc\".into()))\n\t\t\t.args([\"--print\", \"target-libdir\"])\n\t\t\t.output()\n\t\t\t.context(\"failed to locate the Rust target libdir\")?;\n\t\tensure!(output.status.success(), \"`rustc --print target-libdir` failed\");\n\n\t\tlet libdir: PathBuf = String::from_utf8(output.stdout)\n\t\t\t.context(\"rustc returned an invalid target libdir\")?\n\t\t\t.trim()\n\t\t\t.into();\n\t\tlet rust_lld = libdir\n\t\t\t.parent()\n\t\t\t.context(\"Rust target libdir has no parent\")?\n\t\t\t.join(\"bin\")\n\t\t\t.join(format!(\"rust-lld{EXE_SUFFIX}\"));\n\n\t\tOk(rust_lld.is_file())\n\t}\n}\n","sourceCodeStart":36,"sourceCodeEnd":69,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-build/src/build.rs#L36-L69","documentation":"When building for a Linux (non-sparc64) target, `Build::has_rust_lld` probes the toolchain by running `rustc --print target-libdir` to locate the bundled `rust-lld` linker. If rustc exits with a non-zero status, the `ensure!` fails with this message and the build aborts. It signals a broken or unusable rustc toolchain rather than a problem with Yazi itself.","triggerScenarios":"Running `ya build` or `ya dist` with a Linux target while the resolved rustc (`RUSTC` env var or `rustc` on PATH) exits non-zero on `--print target-libdir` — e.g. a missing/broken rustup toolchain, a removed default toolchain after `rustup update`, or `RUSTC` pointing to a non-rustc binary.","commonSituations":"After a rustup toolchain removal or failed update leaving dangling default toolchain; `RUSTC` set to a wrapper script that fails; minimal container images with a partial Rust install; corrupted sysroot.","solutions":["Run `rustc --print target-libdir` manually to see the underlying failure and fix it","Run `rustup show` / `rustup update` and reinstall the active toolchain (`rustup toolchain install stable`)","Check the `RUSTC` environment variable points to a working rustc, or unset it to fall back to PATH","Verify the toolchain's sysroot exists (`rustc --print sysroot`); reinstall if missing"],"exampleFix":"// before (broken toolchain)\n$ RUSTC=~/old-toolchain/rustc ya dist --target aarch64-unknown-linux-gnu\nerror: `rustc --print target-libdir` failed\n\n// after\n$ rustup toolchain install stable\n$ unset RUSTC\n$ ya dist --target aarch64-unknown-linux-gnu","handlingStrategy":"try-catch","validationCode":"# before building, verify the toolchain works\nrustc --print target-libdir >/dev/null || { echo 'rustc broken; run rustup toolchain install'; exit 1; }\nrustup target add <triple>  # ensure the cross target exists","typeGuard":null,"tryCatchPattern":"try {\n  execSync('ya dist --target ' + triple, { stdio: 'inherit' });\n} catch (err) {\n  if (String(err.message).includes('target-libdir')) {\n    console.error('Rust toolchain broken — run `rustup toolchain install stable` and retry');\n  }\n  throw err;\n}","preventionTips":["Run `rustup show` after rustup updates to catch dangling default toolchains","Avoid setting RUSTC to wrapper scripts that can fail silently","Keep toolchains installed for every target triple you cross-compile","Run `rustc --print target-libdir` in CI as a preflight sanity check"],"tags":["rustc","toolchain","build-tooling","subprocess"],"backgroundTag":"rust-toolchain-broken","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}