{"id":"64ec70aab1be446e","repo":"rust-lang/rust","slug":"wrong-command-used-for-building","errorCode":null,"errorMessage":"wrong command used for building","messagePattern":"wrong command used for building","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_macros/build.rs","lineNumber":14,"sourceCode":"fn main() {\n    println!(\"cargo:rerun-if-changed=build.rs\");\n    println!(\"cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP\");\n    if std::env::var(\"RUSTC_BOOTSTRAP\").is_err() {\n        eprintln!(\n            \"error: you are attempting to build the compiler without going through bootstrap\"\n        );\n        eprintln!(\n            \"help: see https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html for how to build the compiler\"\n        );\n        eprintln!(\n            \"help: if you know what you're doing, set the RUSTC_BOOTSTRAP environment variable to any value\"\n        );\n        panic!(\"wrong command used for building\");\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":17,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_macros/build.rs#L1-L17","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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`."],"exampleFix":"# before (panics)\ncargo build -p rustc_macros\n\n# after (option A — recommended)\n./x.py build compiler/rustc_macros\n\n# after (option B — explicit, if you know why)\nRUSTC_BOOTSTRAP=1 cargo build -p rustc_macros","handlingStrategy":"validation","validationCode":"# rustc_macros/build.rs only expects to be driven by the project build driver\n[ -n \"${CARGO:-}\" ] || { echo \"invoke via './x.py build' or 'cargo build', not rustc directly\"; exit 1; }\n# Confirm against the exact command asserted at compiler/rustc_macros/build.rs:14","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["rustc-internals","build-script","bootstrap","environment"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}