{"id":"afafd4ded3b2facf","repo":"rust-lang/rust","slug":"unsupported-cpu-type-cpu","errorCode":null,"errorMessage":"unsupported cpu type {cpu}","messagePattern":"unsupported cpu type (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_codegen_ssa/src/back/archive.rs","lineNumber":131,"sourceCode":"            // contain substrings like \" @\" or \"NONAME\" that are keywords or otherwise reserved\n            // in definition files.\n\n            let mut file = match fs::File::create_new(&output_path) {\n                Ok(file) => file,\n                Err(error) => sess\n                    .dcx()\n                    .emit_fatal(ErrorCreatingImportLibrary { lib_name, error: error.to_string() }),\n            };\n\n            let exports =\n                items.into_iter().map(|item| item.into_coff_short_export(sess)).collect::<Vec<_>>();\n            let machine = match &sess.target.arch {\n                Arch::X86_64 => MachineTypes::AMD64,\n                Arch::X86 => MachineTypes::I386,\n                Arch::AArch64 => MachineTypes::ARM64,\n                Arch::Arm64EC => MachineTypes::ARM64EC,\n                Arch::Arm => MachineTypes::ARMNT,\n                cpu => panic!(\"unsupported cpu type {cpu}\"),\n            };\n\n            if let Err(error) = ar_archive_writer::write_import_library(\n                &mut file,\n                lib_name,\n                &exports,\n                machine,\n                !sess.target.is_like_msvc,\n                // Enable compatibility with MSVC's `/WHOLEARCHIVE` flag.\n                // Without this flag a duplicate symbol error would be emitted\n                // when linking a rust staticlib using `/WHOLEARCHIVE`.\n                // See #129020\n                true,\n                &[],\n            ) {\n                sess.dcx()\n                    .emit_fatal(ErrorCreatingImportLibrary { lib_name, error: error.to_string() });\n            }","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_ssa/src/back/archive.rs#L113-L149","documentation":"Thrown while generating an MSVC import library via ar_archive_writer::write_import_library. The machine type is derived from the target arch, and the match only maps X86_64, X86, AArch64, Arm64EC and Arm to COFF MachineTypes values. Any other Arch reaching this MSVC import-library path causes a panic because no COFF machine code exists for it. This code runs only for MSVC-like Windows targets when bundling a staticlib that needs an import library.","triggerScenarios":"Compiling a staticlib/cdylib for an MSVC Windows target whose arch is not in {X86_64, X86, AArch64, Arm64EC, Arm} (e.g. a target spec marking is_like_msvc=true with an unsupported arch such as RISC-V or MIPS). Triggered when rustc needs to emit the .dll.lib import library.","commonSituations":"Custom target JSON that sets is_like_msvc without a matching arch. Mixing a non-Windows arch string into an msvc triple. Bleeding-edge arch support (e.g. Arm64EC variants) before the match is extended.","solutions":["Switch to a supported MSVC arch triple: x86_64-pc-windows-msvc, i686-pc-windows-msvc, aarch64-pc-windows-msvc, or thumbv7em-pc-windows-msvc.","If the target is really GNU/MinGW, ensure is_like_msvc is false so the dlltool path (archive.rs:229) is used instead.","For a new Windows arch, add the Arch => MachineTypes mapping at compiler/rustc_codegen_ssa/src/back/archive.rs:125."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn archive_cpu_supported(cpu: &str) -> bool {\n    matches!(\n        cpu,\n        \"x86_64\" | \"aarch64\" | \"arm\" | \"armv7\" | \"powerpc\"\n            | \"powerpc64\" | \"s390x\" | \"riscv64\" | \"riscv32\"\n            | \"mips\" | \"mips64\" | \"sparc\" | \"sparc64\"\n            | \"i686\" | \"i586\" | \"msp430\" | \"wasm32\"\n    )\n}\n\n// caller: assert!(archive_cpu_supported(&arch_str));","typeGuard":"fn is_known_archive_cpu(cpu: &str) -> bool {\n    !cpu.is_empty() && !cpu.contains(' ') && archive_cpu_supported(cpu)\n}","tryCatchPattern":"// Panic in compiler; detect via stderr of the build tool.\nlet s = String::from_utf8_lossy(&output.stderr);\nif s.contains(\"unsupported cpu type\") {\n    return Err(LinkError::UnsupportedCpu(cpu.into()));\n}","preventionTips":["Match the `-C target-cpu=` value against the LLVM CPU list for your arch.","Avoid inventing CPU names; use `rustc --print target-cpus` for the canonical set.","When bundling archives, ensure the archive tool backend (llvm-ar vs GNU ar) recognizes the CPU string."],"tags":["msvc","windows","import-library","coff","archive"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}