sxyazi/yazi · error
`rustc --print target-libdir` failed
Error message
`rustc --print target-libdir` failed
What it means
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.
Source
Thrown at yazi-build/src/build.rs:54
cmd.arg("--target").arg(&self.target);
}
if self.completions {
cmd.env("YAZI_GEN_COMPLETIONS", "1");
}
run(&mut cmd).context("failed to build Yazi")
}
pub(super) fn profile(&self) -> &'static str {
if is_windows_target(&self.target) { "release-windows" } else { "release" }
}
fn has_rust_lld() -> Result<bool> {
let output = Command::new(env::var_os("RUSTC").unwrap_or_else(|| "rustc".into()))
.args(["--print", "target-libdir"])
.output()
.context("failed to locate the Rust target libdir")?;
ensure!(output.status.success(), "`rustc --print target-libdir` failed");
let libdir: PathBuf = String::from_utf8(output.stdout)
.context("rustc returned an invalid target libdir")?
.trim()
.into();
let rust_lld = libdir
.parent()
.context("Rust target libdir has no parent")?
.join("bin")
.join(format!("rust-lld{EXE_SUFFIX}"));
Ok(rust_lld.is_file())
}
}
View on GitHub (pinned to 5f901b886b)
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
Example fix
// before (broken toolchain) $ RUSTC=~/old-toolchain/rustc ya dist --target aarch64-unknown-linux-gnu error: `rustc --print target-libdir` failed // after $ rustup toolchain install stable $ unset RUSTC $ ya dist --target aarch64-unknown-linux-gnu
Defensive patterns
Strategy: try-catch
Validate before calling
# before building, verify the toolchain works
rustc --print target-libdir >/dev/null || { echo 'rustc broken; run rustup toolchain install'; exit 1; }
rustup target add <triple> # ensure the cross target exists Try / catch
try {
execSync('ya dist --target ' + triple, { stdio: 'inherit' });
} catch (err) {
if (String(err.message).includes('target-libdir')) {
console.error('Rust toolchain broken — run `rustup toolchain install stable` and retry');
}
throw err;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- {cmd:?} exited with status {status}
- process exited with status {status}
- --target is not valid for the install task
AI-assisted analysis of sxyazi/yazi@5f901b886b (2026-09-02).
Data as JSON: /api/errors/93e538087a23cd16.
Report an issue: GitHub.