rust-lang/rust · critical

HOST was not set

Error message

HOST was not set

What it means

Thrown at build.rs:225 via `env::var("HOST").expect("HOST was not set")`. HOST is the triple of the platform running the build, set by Cargo for build scripts alongside TARGET. rustc_llvm compares HOST to TARGET (build.rs:226) to decide whether this is a cross-compile and to remap include/link paths (build.rs:255, 282-285, 457-462). Missing HOST therefore breaks cross-compile detection and panics.

Source

Thrown at compiler/rustc_llvm/build.rs:225

    // In that case, there's no guarantee that we can actually run the target,
    // so the build system works around this by giving us the LLVM_CONFIG for
    // the host platform. This only really works if the host LLVM and target
    // LLVM are compiled the same way, but for us that's typically the case.
    //
    // We *want* detect this cross compiling situation by asking llvm-config
    // what its host-target is. If that's not the TARGET, then we're cross
    // compiling. Unfortunately `llvm-config` seems either be buggy, or we're
    // misconfiguring it, because the `i686-pc-windows-gnu` build of LLVM will
    // 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);

View on GitHub (pinned to 22057b88b0)

Solutions

  1. Build via cargo or `./x.py build` so Cargo exports HOST (and TARGET, OUT_DIR, etc.) to the build script.
  2. When invoking the build script manually, set both HOST and TARGET to the appropriate triples before running it.
  3. Audit any wrapper/container around the build for environment filtering.
Defensive patterns

Strategy: validation

Validate before calling

[ -n "${HOST:-}" ] || { echo "HOST not set: invoke via './x.py build' or 'cargo build', not rustc directly"; exit 1; }

Prevention

When it happens

Trigger: Same shape as the TARGET error: the build script is invoked outside Cargo's standard build-script environment, so HOST was never exported. Any direct execution of the build-script binary or an environment-stripping wrapper triggers it.

Common situations: Hand-running the compiled build script for debugging; containers/sandboxes that drop inherited env; misconfigured CI wrappers around cargo.

Related errors


AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03). Data as JSON: /data/errors/f1897a1d02b38238.json. Report an issue: GitHub.