Rust fails to compile some native libraries with MSVC, Windows
⚓ Rust 📅 2026-02-18 👤 surdeus 👁️ 6Hi, I installed Rustup via winget and then installed the latest rustc/toolchain (1.93.1). At some point I was working on a Rust on ESP32 project, which requires installing a modified toolchain for supporting the Xtensa platform. I followed the instructions found here: Toolchain Installation - The Rust on ESP Book
My understanding is that the Rust on ESP32 forked toolchain will only be invoked if I manually specify it, as mentioned here: Overrides - The rustup book
The trouble is, I'm now having build failures for some non-ESP32 projects when building for the target x86_64-pc-windows-msvc, when I haven't specified the ESP32 toolchain override at all. When this happens, an error like the following is displayed:
C:\Users\ericswpark\Projects\door-opener\target\debug\build\usb-compat-01-sys-5b5602f9c1a00e03\out\include\usb.h:61:10: fatal error: 'sys/types.h' file not found
thread 'main' (20016) panicked at C:\Users\ericswpark\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\bindgen-0.72.1\lib.rs:917:13:
assertion `left == right` failed: "x86_64-pc-windows-msvc" "x86_64-pc-windows-msvc"
left: 4
right: 8
This is quite strange because sys/types.h seems like the standard C header file that should be included with the MSVC installation.
I also get a similar output compiling a different project:
C:\Users\ericswpark\Projects\advent-of-code-solutions\2025\day-10\target\debug\build\scip-sys-584425f9038e6801\out\scip_install\include\scip\scip.h:42:10: fatal error: 'stdio.h' file not found
thread 'main' (18812) panicked at C:\Users\ericswpark\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\bindgen-0.72.1\lib.rs:917:13:
assertion `left == right` failed: "x86_64-pc-windows-msvc" "x86_64-pc-windows-msvc"
left: 4
right: 8
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Again, stdio.h is missing which doesn't seem possible.
I tried going through the Visual Studio installer to see if there's any missing build tools or Windows SDKs. I have both installed on the latest version, so I doubt that's the issue, but perhaps it's the version of Visual Studio that's causing the problem? I have VS 2026 installed; I seem to remember the compilation working fine with VS 2022 on another Windows machine (that didn't have the ESP32 toolchain fork installed at the time), but am unsure whether this is the cause.
If I go to the bindgen source where the error line is, I see the following:
if is_host_build {
debug_assert_eq!(
context.target_pointer_size(),
size_of::<*mut ()>(),
"{effective_target:?} {HOST_TARGET:?}"
);
}
So for some reason the host and target pointer sizes are different and it's causing the build failure? As well as the "missing" header files?
I tried adding the --target x86_64-pc-windows-msvc argument to cargo build but it still results in the same issue. Any guidance on where I could try troubleshooting next would be appreciated!
2 posts - 1 participant
🏷️ Rust_feed