rust-lang/rust · critical
wrong command used for building
Error message
wrong command used for building
What it means
Thrown by the build.rs of rustc_macros (build.rs:1-16) when the RUSTC_BOOTSTRAP environment variable is not set. The rustc compiler must be built through bootstrap (./x.py), which sets RUSTC_BOOTSTRAP; a direct `cargo build` of the compiler crates does not, and the build script panics to prevent an unsupported build path. Helpful messages point to the rustc dev guide build instructions.
Source
Thrown at compiler/rustc_macros/build.rs:14
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP");
if std::env::var("RUSTC_BOOTSTRAP").is_err() {
eprintln!(
"error: you are attempting to build the compiler without going through bootstrap"
);
eprintln!(
"help: see https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html for how to build the compiler"
);
eprintln!(
"help: if you know what you're doing, set the RUSTC_BOOTSTRAP environment variable to any value"
);
panic!("wrong command used for building");
}
}
View on GitHub (pinned to 22057b88b0)
Solutions
- Build the compiler through bootstrap: `./x.py build` (or `./x.py build compiler/rustc_macros`). See https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html.
- If you intentionally need a direct cargo invocation (you know what you are doing), set RUSTC_BOOTSTRAP to any value, e.g. `RUSTC_BOOTSTRAP=1 cargo build -p rustc_macros`.
Example fix
# before (panics) cargo build -p rustc_macros # after (option A — recommended) ./x.py build compiler/rustc_macros # after (option B — explicit, if you know why) RUSTC_BOOTSTRAP=1 cargo build -p rustc_macros
Defensive patterns
Strategy: validation
Validate before calling
# rustc_macros/build.rs only expects to be driven by the project build driver
[ -n "${CARGO:-}" ] || { echo "invoke via './x.py build' or 'cargo build', not rustc directly"; exit 1; }
# Confirm against the exact command asserted at compiler/rustc_macros/build.rs:14 Prevention
- Build rustc_macros exclusively through ./x.py build
- Do not invoke the build.rs outside its cargo context
- Keep the build driver in sync with the command checked at build.rs:14
When it happens
Trigger: Running `cargo build`/`cargo build -p rustc_macros` (or any compiler crate) directly instead of through `./x.py`, without manually exporting RUSTC_BOOTSTRAP. The build.rs checks `env::var("RUSTC_BOOTSTRAP").is_err()` (build.rs:4) and panics at build.rs:14.
Common situations: New contributors attempting `cargo build` on a rustc checkout before learning bootstrap; IDE tooling or scripts that invoke cargo directly on compiler crates; CI that bypasses ./x.py for a sub-build.
Related errors
- REAL_LIBRARY_PATH_VAR
- LLVM_CONFIG was not set
- command did not execute successfully: {:?} expected success,
- TARGET was not set
- HOST was not set
AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03).
Data as JSON: /data/errors/64ec70aab1be446e.json.
Report an issue: GitHub.