Help to compile a crate on windows that depends on a C library but compile properly on linux

Hello,
I have done these small crates GitHub - cpcsdk/hxcfe_rs: Binding for the libhxcfe library. MVP for https://github.com/cpcsdk/rust.cpclib/. More work is expected for other use cases few time ago to access from rust to some functionalities of a c library.
I have no issues a all to compile these crates under Linux and to use them as dependencies of other projects.

However, I know nothing to windows compilation world and I hit an issue I am unable to solve myself. Some guidance is expected.

cargo +nightly-x86_64-pc-windows-msvc test
fails with this error

error: failed to run custom build command for hxcadaptor-sys v0.1.5 (C:\Users\giotr\Perso\CPC\hxc_rust\hxcadaptor-sys)

Caused by:
process didn't exit successfully: C:\Users\giotr\Perso\CPC\hxc_rust\target\debug\build\hxcadaptor-sys-e2dbf5a5627a8eb0\build-script-build (exit code: 101)
--- stdout
cargo:rerun-if-changed=build.rs
cargo:rerun-if-changed=wrapper.h
cargo:include=C:\Users\giotr\Perso\CPC\hxc_rust\target\debug\build\hxcadaptor-sys-8215fdc0317b9735\out\hxccode\libhxcadaptor\sources
cargo:rustc-link-search=native=C:\Users\giotr\Perso\CPC\hxc_rust\target\debug\build\hxcadaptor-sys-8215fdc0317b9735\out\hxccode\libhxcadaptor\build
cargo:rustc-link-lib=hxcadaptor
cargo:rerun-if-env-changed=TARGET
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64-pc-windows-msvc
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS

--- stderr
Really build the library
gcc -o libhxcadaptor.o -c ../sources/libhxcadaptor.c -O3 -I../sources/ -I ../../libhxcfe/sources -I ../../libusbhxcfe/sources -I ../../build -Wall
gcc -o fs.o -c ../sources/fs.c -O3 -I../sources/ -I ../../libhxcfe/sources -I ../../libusbhxcfe/sources -I ../../build -Wall
gcc -o network.o -c ../sources/network.c -O3 -I../sources/ -I ../../libhxcfe/sources -I ../../libusbhxcfe/sources -I ../../build -Wall
ar r libhxcadaptor.a libhxcadaptor.o fs.o network.o
copy libhxcadaptor.a ....\build
1 fichier(s) copi�(s).

process_begin: CreateProcess(NULL, uname, ...) failed.
Makefile:5: pipe: No error
ar: creating libhxcadaptor.a

Build the windows library
Generate bindings
clang version 17.0.6
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir:
ignoring nonexistent directory "lib\clang\17\include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 10.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include"
#include "..." search starts here:
#include <...> search starts here:
C:\Users\giotr\Perso\CPC\hxc_rust\target\debug\build\hxcadaptor-sys-8215fdc0317b9735\out\hxccode\libhxcadaptor\sources
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include (framework directory)
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include
C:\Program Files\LLVM\lib\clang\17\include
End of search list.
C:\Users\giotr\Perso\CPC\hxc_rust\target\debug\build\hxcadaptor-sys-8215fdc0317b9735\out\hxccode\libhxcadaptor\sources\libhxcadaptor.h:65:10: fatal error: 'sys/stat.h' file not found
thread 'main' panicked at hxcadaptor-sys\build.rs:59:10:
Unable to generate bindings: ClangDiagnostic("C:\Users\giotr\Perso\CPC\hxc_rust\target\debug\build\hxcadaptor-sys-8215fdc0317b9735\out\hxccode\libhxcadaptor\sources\libhxcadaptor.h:65:10: fatal error: 'sys/stat.h' file not found\n")
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

while cargo +nightly-x86_64-pc-windows-gnu test

fails with

error: failed to run custom build command for hxcadaptor-sys v0.1.5 (C:\Users\giotr\Perso\CPC\hxc_rust\hxcadaptor-sys)

Caused by:
process didn't exit successfully: C:\Users\giotr\Perso\CPC\hxc_rust\target\debug\build\hxcadaptor-sys-38e0a4ba988ace0e\build-script-build (exit code: 101)
--- stdout
cargo:rerun-if-changed=build.rs
cargo:rerun-if-changed=wrapper.h
cargo:include=C:\Users\giotr\Perso\CPC\hxc_rust\target\debug\build\hxcadaptor-sys-f5334dff9f4ff3f4\out\hxccode\libhxcadaptor\sources
cargo:rustc-link-search=native=C:\Users\giotr\Perso\CPC\hxc_rust\target\debug\build\hxcadaptor-sys-f5334dff9f4ff3f4\out\hxccode\libhxcadaptor\build
cargo:rustc-link-lib=hxcadaptor
cargo:rerun-if-env-changed=TARGET
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64-pc-windows-gnu
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64_pc_windows_gnu
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS

--- stderr
Really build the library
gcc -o libhxcadaptor.o -c ../sources/libhxcadaptor.c -O3 -I../sources/ -I ../../libhxcfe/sources -I ../../libusbhxcfe/sources -I ../../build -Wall
gcc -o fs.o -c ../sources/fs.c -O3 -I../sources/ -I ../../libhxcfe/sources -I ../../libusbhxcfe/sources -I ../../build -Wall
gcc -o network.o -c ../sources/network.c -O3 -I../sources/ -I ../../libhxcfe/sources -I ../../libusbhxcfe/sources -I ../../build -Wall
ar r libhxcadaptor.a libhxcadaptor.o fs.o network.o
copy libhxcadaptor.a ....\build
1 fichier(s) copi�(s).

process_begin: CreateProcess(NULL, uname, ...) failed.
Makefile:5: pipe: No error
ar: creating libhxcadaptor.a

Build the windows library
Generate bindings
clang version 17.0.6
Target: x86_64-pc-windows-gnu
Thread model: posix
InstalledDir:
ignoring nonexistent directory "lib\clang\17\include"
ignoring nonexistent directory "C:\Strawberry\c\x86_64-w64-mingw32\usr/include"
ignoring duplicate directory "C:\Strawberry\c\x86_64-w64-mingw32\include"
ignoring duplicate directory "C:\Strawberry\c\include"
#include "..." search starts here:
#include <...> search starts here:
C:\Users\giotr\Perso\CPC\hxc_rust\target\debug\build\hxcadaptor-sys-f5334dff9f4ff3f4\out\hxccode\libhxcadaptor\sources
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include (framework directory)
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include
C:\Program Files\LLVM\lib\clang\17\include
C:\Strawberry\c\x86_64-w64-mingw32\include
C:\Strawberry\c\include
End of search list.
wrapper.h:83:26: error: expected ';' after top level declarator
wrapper.h:84:21: error: typedef redefinition with different types ('unsigned int' vs 'int')
wrapper.h:83:19: note: previous definition is here
wrapper.h:84:28: error: expected ';' after top level declarator
C:\Users\giotr\Perso\CPC\hxc_rust\target\debug\build\hxcadaptor-sys-f5334dff9f4ff3f4\out\hxccode\libhxcadaptor\sources\libhxcadaptor.h:37:1: error: unknown type name 'uintptr_t'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vadefs.h:61:26: error: typedef redefinition with different types ('unsigned int' vs 'int')
wrapper.h:83:19: note: previous definition is here
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vadefs.h:61:33: error: expected ';' after top level declarator
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:96:1: error: expected identifier
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:96:20: error: expected ';' after top level declarator
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:193:22: error: typedef redefinition with different types ('unsigned int' vs 'int')
wrapper.h:83:19: note: previous definition is here
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:193:29: error: expected ';' after top level declarator
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:194:30: error: typedef redefinition with different types ('__int64' (aka 'int') vs 'long long')
C:\Program Files\LLVM\lib\clang\17\include\stddef.h:35:26: note: previous definition is here
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:386:51: error: unknown type name 'uintptr_t'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:387:67: error: unknown type name 'uintptr_t'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:391:8: error: unknown type name 'uintptr_t'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:399:1: error: a parameter list without types is only allowed in a function definition
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\crtdefs.h:10:10: fatal error: 'corecrt.h' file not found
thread 'main' panicked at hxcadaptor-sys\build.rs:59:10:
Unable to generate bindings: ClangDiagnostic("wrapper.h:83:26: error: expected ';' after top level declarator\nwrapper.h:84:21: error: typedef redefinition with different types ('unsigned int' vs 'int')\nwrapper.h:84:28: error: expected ';' after top level declarator\nC:\Users\giotr\Perso\CPC\hxc_rust\target\debug\build\hxcadaptor-sys-f5334dff9f4ff3f4\out\hxccode\libhxcadaptor\sources\libhxcadaptor.h:37:1: error: unknown type name 'uintptr_t'\nC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vadefs.h:61:26: error: typedef redefinition with different types ('unsigned int' vs 'int')\nC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vadefs.h:61:33: error: expected ';' after top level declarator\nC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:96:1: error: expected identifier\nC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:96:20: error: expected ';' after top level declarator\nC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:193:22: error: typedef redefinition with different types ('unsigned int' vs 'int')\nC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:193:29: error: expected ';' after top level declarator\nC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:194:30: error: typedef redefinition with different types ('__int64' (aka 'int') vs 'long long')\nC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:386:51: error: unknown type name 'uintptr_t'\nC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:387:67: error: unknown type name 'uintptr_t'\nC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:391:8: error: unknown type name 'uintptr_t'\nC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vcruntime.h:399:1: error: a parameter list without types is only allowed in a function definition\nC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\crtdefs.h:10:10: fatal error: 'corecrt.h' file not found\n")

I am pretty sure at the early stages of development of these crates, I have been able to build them at least with one of these versions of rustc.
I do not expect anyone to solve the issue at my place, but I will be very greatful to have some guidance to know where to look at.

Thanks a lot

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.