rust-lang/rust · critical
require llvm component {component} but wasn't found
Error message
require llvm component {component} but wasn't found What it means
Thrown at build.rs:232-235 when `llvm-config --components` does not report one of the required LLVM components. REQUIRED_COMPONENTS (build.rs:33-34) is [ipo, bitreader, bitwriter, linker, asmparser, lto, coverage, instrumentation]; the loop at build.rs:232-236 verifies each is present in the components list (after filtering to known names at build.rs:230). A missing required component means the LLVM installation rustc is linking against was built without enabling that component, so rustc_llvm cannot function.
Source
Thrown at compiler/rustc_llvm/build.rs:234
// report itself with a `--host-target` of `x86_64-pc-windows-gnu`. This
// tricks us into thinking we're doing a cross build when we aren't, so
// havoc ensues.
//
// In any case, if we're cross compiling, this generally just means that we
// can't trust all the output of llvm-config because it might be targeted
// for the host rather than the target. As a result a bunch of blocks below
// are gated on `if !is_crossed`
let target = env::var("TARGET").expect("TARGET was not set");
let host = env::var("HOST").expect("HOST was not set");
let is_crossed = target != host;
let components = output(Command::new(&llvm_config).arg("--components"));
let mut components = components.split_whitespace().collect::<Vec<_>>();
components.retain(|c| OPTIONAL_COMPONENTS.contains(c) || REQUIRED_COMPONENTS.contains(c));
for component in REQUIRED_COMPONENTS {
if !components.contains(component) {
panic!("require llvm component {component} but wasn't found");
}
}
for component in components.iter() {
println!("cargo:rustc-cfg=llvm_component=\"{component}\"");
}
// Link in our own LLVM shims, compiled with the same flags as LLVM
let mut cmd = Command::new(&llvm_config);
cmd.arg("--cxxflags");
let cxxflags = quoted_split(cmd);
let mut cfg = cc::Build::new();
cfg.warnings(false);
// Prevent critical warnings when we're compiling from rust-lang/rust CI,
// except on MSVC, as the compiler throws warnings that are only reported
// for this platform. See https://github.com/rust-lang/rust/pull/145031#issuecomment-3162677202.
// Moreover, LLVM generally guarantees warning-freedom only when building with Clang, as otherView on GitHub (pinned to 22057b88b0)
Solutions
- Rebuild LLVM with the full set of targets/components, or use rustc's in-tree LLVM via bootstrap (`./x.py build`), which enables everything required.
- Install any missing distro LLVM subpackages corresponding to the named component (e.g. coverage/lto/dev packages).
- Verify with `llvm-config --components` that all of [ipo, bitreader, bitwriter, linker, asmparser, lto, coverage, instrumentation] are listed; if not, the LLVM_CONFIG path is wrong or the LLVM build is incomplete.
Defensive patterns
Strategy: validation
Validate before calling
# Ensure every LLVM component rustc_llvm needs is present before building
NEEDED="orcjit native webassembly target"
HAVE=$("$LLVM_CONFIG" --components)
for c in $NEEDED; do
grep -qw "$c" <<<"$HAVE" || { echo "missing required llvm component: $c"; exit 1; }
done Prevention
- Install an LLVM build that includes all components rustc_llvm/build.rs:234 requires
- Re-run `llvm-config --components` after any LLVM upgrade and diff against the required set
- Build LLVM with component groups enabled (e.g. -DLLVM_BUILD_LLVM_DYLIB=ON) if your distro splits them
When it happens
Trigger: Pointing LLVM_CONFIG at an LLVM build that was configured with `-DLLVM_TARGETS_TO_BUILD=...` only or with components disabled (e.g. a minimal/system LLVM lacking lto, coverage, or instrumentation); building rustc against a distro LLVM package split into subpackages where not all are installed.
Common situations: Using a stripped-down or vendor LLVM that omits components rustc needs; switching from in-tree LLVM (built by bootstrap with all components) to a system LLVM that is incomplete; outdated LLVM version where component names differ.
Related errors
- command did not execute successfully: {:?} expected success,
- REAL_LIBRARY_PATH_VAR
- LLVM_CONFIG was not set
- TARGET was not set
- HOST was not set
AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03).
Data as JSON: /data/errors/c21404f0e888aff9.json.
Report an issue: GitHub.