Add native Windows MSYS2 UCRT64 support#571
Add native Windows MSYS2 UCRT64 support#571jklarenbeek wants to merge 1 commit intobuserror:masterfrom
Conversation
Fix compilation on Windows with MSYS2 UCRT64 / MinGW toolchain without breaking Linux or macOS builds. All changes are guarded with #ifdef __MINGW32__. sim_gdb.c: - Add CLOSE_SOCKET() dispatch macro: closesocket() on Windows, close() on POSIX. Winsock socket FDs cannot be closed with the POSIX close(); replace all five socket fd close() calls in avr_gdb_init(), avr_deinit_gdb(), and gdb_network_handler() with CLOSE_SOCKET(). - sim_network.h already initialises Winsock (WSAStartup) and provides the Winsock headers, so no additional includes are needed here. sim_avr.c: - Suppress CLOCK_MONOTONIC_RAW under __MINGW32__ so avr_get_time_stamp() always takes the gettimeofday() code path. CLOCK_MONOTONIC_RAW is Linux-specific; MinGW may expose the macro without a working clock_gettime(). sim_avr.h: - Ensure ssize_t is defined on MinGW. MSYS2 UCRT64 provides sys/types.h but the _SSIZE_T_DEFINED guard may not activate in all compilation modes. Makefile.common: - Add -lpthread to LDFLAGS in the existing Msys block so that winpthreads is linked on Windows (needed for GDB thread stubs and other consumers). .github/workflows/windows-build.yml: - New CI workflow: builds libsimavr.a on every push/PR using MSYS2 UCRT64, ensuring the Windows port stays green. Tested: libsimavr.a (2.3 MB, 154 exported symbols) built with zero warnings under MSYS2 UCRT64 gcc (x86_64-w64-mingw32) with -Werror active.
|
It looks good, but I think it makes sense to replace the existing 64-bit build with this one, as UCRT64 has long been the recommended library. Also, please shorten the change description: it is excellent to describe the PR, but too big for the git log. Have you downloaded and tested the package? I usually do 'make test' and run all the examples. Finally, could you explain more about '-lpthreads'? There are no pthread calls in simavr and this looks specific to UCRT64. Thanks, G. |
|
Hi G, I will respond alongside your questions:
Yes I understand and will do that this weekend.
I haven't, but I did build it and tested it. Will look at the action later this weekend. I have created a small project called protosim that registers the simavr as a real pseudo-terminal (PTY) for another project I have called protoduino. At a point I decided that protosim should work with windows as well and when that worked a submitted a patch to simavr.
There is a example in simavr (https://github.com/buserror/simavr/blob/master/examples/board_simduino/simduino.c) using pthreads as well. I might have just mindlessly copied it from there, but I think it was for gdb to work correctly. I will have another look at it. Regards, J. |
Fix compilation on Windows with MSYS2 UCRT64 / MinGW toolchain without breaking Linux or macOS builds.
Changes:
sim_gdb.c: Add CLOSE_SOCKET() dispatch macro: closesocket() on Windows, close() on POSIX.
sim_avr.c: Suppress CLOCK_MONOTONIC_RAW under MINGW32 so avr_get_time_stamp() always takes the gettimeofday() code path.
sim_avr.h: Ensure ssize_t is defined on MinGW.
Makefile.common: Add -lpthread to LDFLAGS in the existing Msys block so that winpthreads is linked on Windows.
.github/workflows/windows-build.yml: New CI workflow: builds libsimavr.a on every push/PR using MSYS2 UCRT64.