{"record":{"id":"aa36c463641636b4","repo":"rust-lang/rust","slug":"toolchain-name","errorCode":null,"errorMessage":"TOOLCHAIN_NAME","messagePattern":"TOOLCHAIN_NAME","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_codegen_cranelift/scripts/cargo-clif.rs","lineNumber":37,"sourceCode":"    }\n    if let Some(name) = option_env!(\"BUILTIN_BACKEND\") {\n        rustflags.push(format!(\"-Zcodegen-backend={name}\"));\n    } else {\n        let dylib = sysroot.join(\"lib\").join(\n            env::consts::DLL_PREFIX.to_string()\n                + \"rustc_codegen_cranelift\"\n                + env::consts::DLL_SUFFIX,\n        );\n        rustflags.push(format!(\"-Zcodegen-backend={}\", dylib.to_str().unwrap()));\n    }\n    rustflags.push(\"--sysroot\".to_owned());\n    rustflags.push(sysroot.to_str().unwrap().to_owned());\n\n    let cargo = if let Some(cargo) = option_env!(\"CARGO\") {\n        cargo\n    } else {\n        // Ensure that the right toolchain is used\n        env::set_var(\"RUSTUP_TOOLCHAIN\", option_env!(\"TOOLCHAIN_NAME\").expect(\"TOOLCHAIN_NAME\"));\n        \"cargo\"\n    };\n\n    let mut args = env::args().skip(1).collect::<Vec<_>>();\n    if args.get(0).map(|arg| &**arg) == Some(\"clif\") {\n        // Avoid infinite recursion when invoking `cargo-clif` as cargo subcommand using\n        // `cargo clif`.\n        args.remove(0);\n    }\n\n    let args: Vec<_> = match args.get(0).map(|arg| &**arg) {\n        Some(\"jit\") => {\n            rustflags.push(\"-Cprefer-dynamic\".to_owned());\n            args.remove(0);\n            IntoIterator::into_iter([\"rustc\".to_string()])\n                .chain(args)\n                .chain([\n                    \"--\".to_string(),","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_codegen_cranelift/scripts/cargo-clif.rs#L19-L55","documentation":"This panic fires in the `cargo-clif` wrapper script for the Cranelift codegen backend. The script uses `option_env!(\"TOOLCHAIN_NAME\")` to read the toolchain name at compile time, then `.expect(\"TOOLCHAIN_NAME\")` at runtime. `TOOLCHAIN_NAME` is a build-time environment variable that must be set when the wrapper script itself is compiled (by the cg_clif build system). If it's not set, the `option_env!` yields `None` and the script panics on launch.","triggerScenarios":"Running `cargo-clif` (the Cranelift backend's cargo wrapper) when the binary was compiled without the `TOOLCHAIN_NAME` environment variable set. This happens when the wrapper is built outside the official cg_clif build system (e.g., copied manually, built with a bare `cargo build`, or installed via a method that bypasses `build_system/`).","commonSituations":"Installing rustc_codegen_cranelift by manually running `cargo build` in the scripts directory instead of using the project's `build_system/` / `y.rs` build tool. Also happens if the build system's environment setup is incomplete or the toolchain name variable was removed in a refactor.","solutions":["Use the official build system (`./y.rs prepare && ./y.rs build`) which sets `TOOLCHAIN_NAME` during compilation.","Set `TOOLCHAIN_NAME` manually before building: `TOOLCHAIN_NAME=stage2 cargo build --manifest-path scripts/Cargo.toml`.","If `CARGO` env var is set, the script bypasses the toolchain check — set `CARGO` to your cargo binary as a workaround.","Follow the cg_clif README's installation instructions exactly; do not copy binaries built without the build system."],"exampleFix":"# before (manual build → TOOLCHAIN_NAME not set → panic)\ncargo build --manifest-path compiler/rustc_codegen_cranelift/scripts/Cargo.toml\n./target/debug/cargo-clif build\n\n# after (use the official build system)\ncd compiler/rustc_codegen_cranelift\n./y.rs prepare && ./y.rs build\n# then use the installed cargo-clif","handlingStrategy":"validation","validationCode":"// Check before building that TOOLCHAIN_NAME will be available.\n// In the build script or CI:\n// test -n \"$TOOLCHAIN_NAME\" || { echo \"TOOLCHAIN_NAME not set\"; exit 1; }\n// Or check at Rust compile time (in the script's build.rs):\n// fn main() {\n//     if option_env!(\"TOOLCHAIN_NAME\").is_none() && option_env!(\"CARGO\").is_none() {\n//         panic!(\"Set TOOLCHAIN_NAME or CARGO before building cargo-clif\");\n//     }\n// }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use y.rs build system for cg_clif — it sets TOOLCHAIN_NAME automatically.","Never manually cargo build the scripts without setting TOOLCHAIN_NAME.","Set CARGO env var as a fallback to bypass the toolchain lookup path.","Document the required env vars in your build pipeline."],"tags":["rustc","cranelift","codegen-backend","build-config","toolchain","env-var","cg-clif"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}