rust-lang/rust · critical
LLVM_CONFIG was not set
Error message
LLVM_CONFIG was not set
What it means
Thrown at build.rs:185-186 via `tracked_env_var_os("LLVM_CONFIG").expect("LLVM_CONFIG was not set")`. rustc_llvm's build script drives an external `llvm-config` executable to discover LLVM include paths, link flags, and components (build.rs:228, 243, 336, 454). Bootstrap is responsible for exporting the LLVM_CONFIG env var pointing at the correct binary; if it is absent, the build script cannot proceed and panics.
Source
Thrown at compiler/rustc_llvm/build.rs:186
fn main() {
if cfg!(feature = "check_only") {
return;
}
for component in REQUIRED_COMPONENTS.iter().chain(OPTIONAL_COMPONENTS.iter()) {
println!("cargo:rustc-check-cfg=cfg(llvm_component,values(\"{component}\"))");
}
if tracked_env_var_os("RUST_CHECK").is_some() {
// If we're just running `check`, there's no need for LLVM to be built.
return;
}
restore_library_path();
let llvm_config =
PathBuf::from(tracked_env_var_os("LLVM_CONFIG").expect("LLVM_CONFIG was not set"));
println!("cargo:rerun-if-changed={}", llvm_config.display());
// FIXME: `--quote-paths` was added to llvm-config in LLVM 22, so this test (and all its ensuing
// fallback paths) can be removed once we bump the minimum llvm_version >= (22, 0, 0).
let llvm_config_supports_quote_paths =
stderr(Command::new(&llvm_config).arg("--help")).contains("quote-paths");
let quoted_split = |mut cmd: Command| {
if llvm_config_supports_quote_paths {
LlvmConfigOutput::QuotedPaths(output(cmd.arg("--quote-paths")))
} else {
LlvmConfigOutput::UnquotedPaths(output(&mut cmd))
}
};
// Test whether we're cross-compiling LLVM. This is a pretty rare case
// currently where we're producing an LLVM for a different platform thanView on GitHub (pinned to 22057b88b0)
Solutions
- Build via bootstrap: `./x.py build`, which sets LLVM_CONFIG to the appropriate llvm-config (in-tree or system).
- If you must build rustc_llvm manually, set LLVM_CONFIG to an absolute path of a working llvm-config, e.g. `LLVM_CONFIG=/usr/bin/llvm-config cargo build -p rustc_llvm`.
- Check config.toml's [llvm] section; when using a system LLVM ensure llvm-config is on PATH or llvm-config is explicitly specified, then re-run bootstrap.
Defensive patterns
Strategy: validation
Validate before calling
: "${LLVM_CONFIG:?LLVM_CONFIG must point to an llvm-config binary}"
[ -x "$LLVM_CONFIG" ] || { echo "$LLVM_CONFIG is not executable"; exit 1; }
"$LLVM_CONFIG" --version >/dev/null 2>&1 || { echo "llvm-config unusable"; exit 1; } Prevention
- Export LLVM_CONFIG in your shell rc and CI environment before any cargo/x.py build
- Point it at the exact LLVM the toolchain was built against, not a stray system one
- Verify with `llvm-config --version` as the first CI step
When it happens
Trigger: Running the rustc_llvm build script without bootstrap having set LLVM_CONFIG — e.g. `cargo build` invoked directly, or a custom build harness that does not export it. Also seen when bootstrap's LLVM discovery fails silently or the var is unset for a target that expects system LLVM.
Common situations: Building compiler/rustc_llvm by hand with cargo instead of `./x.py`; misconfigured bootstrap config.toml that does not locate an LLVM installation; switching between system LLVM and in-tree LLVM builds without updating configuration.
Related errors
- REAL_LIBRARY_PATH_VAR
- command did not execute successfully: {:?} expected success,
- wrong command used for building
- TARGET was not set
- HOST was not set
AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03).
Data as JSON: /data/errors/76b247a75a351f5e.json.
Report an issue: GitHub.