rust-lang/rust · critical
unsupported cpu type {cpu}
Error message
unsupported cpu type {cpu} What it means
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.
Source
Thrown at compiler/rustc_codegen_ssa/src/back/archive.rs:131
// contain substrings like " @" or "NONAME" that are keywords or otherwise reserved
// in definition files.
let mut file = match fs::File::create_new(&output_path) {
Ok(file) => file,
Err(error) => sess
.dcx()
.emit_fatal(ErrorCreatingImportLibrary { lib_name, error: error.to_string() }),
};
let exports =
items.into_iter().map(|item| item.into_coff_short_export(sess)).collect::<Vec<_>>();
let machine = match &sess.target.arch {
Arch::X86_64 => MachineTypes::AMD64,
Arch::X86 => MachineTypes::I386,
Arch::AArch64 => MachineTypes::ARM64,
Arch::Arm64EC => MachineTypes::ARM64EC,
Arch::Arm => MachineTypes::ARMNT,
cpu => panic!("unsupported cpu type {cpu}"),
};
if let Err(error) = ar_archive_writer::write_import_library(
&mut file,
lib_name,
&exports,
machine,
!sess.target.is_like_msvc,
// Enable compatibility with MSVC's `/WHOLEARCHIVE` flag.
// Without this flag a duplicate symbol error would be emitted
// when linking a rust staticlib using `/WHOLEARCHIVE`.
// See #129020
true,
&[],
) {
sess.dcx()
.emit_fatal(ErrorCreatingImportLibrary { lib_name, error: error.to_string() });
}View on GitHub (pinned to 22057b88b0)
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.
Defensive patterns
Strategy: validation
Validate before calling
fn archive_cpu_supported(cpu: &str) -> bool {
matches!(
cpu,
"x86_64" | "aarch64" | "arm" | "armv7" | "powerpc"
| "powerpc64" | "s390x" | "riscv64" | "riscv32"
| "mips" | "mips64" | "sparc" | "sparc64"
| "i686" | "i586" | "msp430" | "wasm32"
)
}
// caller: assert!(archive_cpu_supported(&arch_str)); Type guard
fn is_known_archive_cpu(cpu: &str) -> bool {
!cpu.is_empty() && !cpu.contains(' ') && archive_cpu_supported(cpu)
} Try / catch
// Panic in compiler; detect via stderr of the build tool.
let s = String::from_utf8_lossy(&output.stderr);
if s.contains("unsupported cpu type") {
return Err(LinkError::UnsupportedCpu(cpu.into()));
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03).
Data as JSON: /data/errors/afafd4ded3b2facf.json.
Report an issue: GitHub.