{"id":"f1897a1d02b38238","repo":"rust-lang/rust","slug":"host-was-not-set","errorCode":null,"errorMessage":"HOST was not set","messagePattern":"HOST was not set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_llvm/build.rs","lineNumber":225,"sourceCode":"    // In that case, there's no guarantee that we can actually run the target,\n    // so the build system works around this by giving us the LLVM_CONFIG for\n    // the host platform. This only really works if the host LLVM and target\n    // LLVM are compiled the same way, but for us that's typically the case.\n    //\n    // We *want* detect this cross compiling situation by asking llvm-config\n    // what its host-target is. If that's not the TARGET, then we're cross\n    // compiling. Unfortunately `llvm-config` seems either be buggy, or we're\n    // misconfiguring it, because the `i686-pc-windows-gnu` build of LLVM will\n    // report itself with a `--host-target` of `x86_64-pc-windows-gnu`. This\n    // tricks us into thinking we're doing a cross build when we aren't, so\n    // havoc ensues.\n    //\n    // In any case, if we're cross compiling, this generally just means that we\n    // can't trust all the output of llvm-config because it might be targeted\n    // for the host rather than the target. As a result a bunch of blocks below\n    // are gated on `if !is_crossed`\n    let target = env::var(\"TARGET\").expect(\"TARGET was not set\");\n    let host = env::var(\"HOST\").expect(\"HOST was not set\");\n    let is_crossed = target != host;\n\n    let components = output(Command::new(&llvm_config).arg(\"--components\"));\n    let mut components = components.split_whitespace().collect::<Vec<_>>();\n    components.retain(|c| OPTIONAL_COMPONENTS.contains(c) || REQUIRED_COMPONENTS.contains(c));\n\n    for component in REQUIRED_COMPONENTS {\n        if !components.contains(component) {\n            panic!(\"require llvm component {component} but wasn't found\");\n        }\n    }\n\n    for component in components.iter() {\n        println!(\"cargo:rustc-cfg=llvm_component=\\\"{component}\\\"\");\n    }\n\n    // Link in our own LLVM shims, compiled with the same flags as LLVM\n    let mut cmd = Command::new(&llvm_config);","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_llvm/build.rs#L207-L243","documentation":"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.","triggerScenarios":"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.","commonSituations":"Hand-running the compiled build script for debugging; containers/sandboxes that drop inherited env; misconfigured CI wrappers around cargo.","solutions":["Build via cargo or `./x.py build` so Cargo exports HOST (and TARGET, OUT_DIR, etc.) to the build script.","When invoking the build script manually, set both HOST and TARGET to the appropriate triples before running it.","Audit any wrapper/container around the build for environment filtering."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"[ -n \"${HOST:-}\" ] || { echo \"HOST not set: invoke via './x.py build' or 'cargo build', not rustc directly\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build through ./x.py or cargo, which set HOST alongside TARGET","Treat a missing HOST as a wrong-build-driver signal, not a script bug","Document the required build driver in your CI pipeline"],"tags":["rustc-internals","build-script","cargo","environment"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}