From f5313fe581bdbe3cbb8298632de39ca7f4d69d57 Mon Sep 17 00:00:00 2001 From: ANSI TV Admin Date: Wed, 11 Nov 2026 12:04:37 -0800 Subject: [PATCH 15/24] DeuceSSH: build with mingw-w64 against msvcrt (timespec_get shim) Build support only, no behaviour change. mingw-w64 against msvcrt declares timespec_get only under UCRT, where it resolves to _timespec64_get, which msvcrt.dll does not export, so the CMake probe stopped the build. On MINGW supply C11 timespec_get from clock_gettime (compat_timespec.[ch], force- included) instead of refusing. Every other platform takes the old path. --- src/ssh/CMakeLists.txt | 20 +++++++++++++++----- src/ssh/compat_timespec.c | 22 ++++++++++++++++++++++ src/ssh/compat_timespec.h | 13 +++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 src/ssh/compat_timespec.c create mode 100644 src/ssh/compat_timespec.h diff --git a/src/ssh/CMakeLists.txt b/src/ssh/CMakeLists.txt index 1983cc77..6195aa19 100644 --- a/src/ssh/CMakeLists.txt +++ b/src/ssh/CMakeLists.txt @@ -110,9 +110,19 @@ check_c_source_compiles(" } " HAVE_TIMESPEC_GET) if(NOT HAVE_TIMESPEC_GET) - message(FATAL_ERROR - "DeuceSSH requires C11's timespec_get / TIME_UTC in . " - "This SDK/libc predates them — upgrade the platform toolchain.") + if(MINGW) + # mingw against msvcrt declares timespec_get only under UCRT, where + # it resolves to _timespec64_get -- a symbol msvcrt.dll does not + # export. clock_gettime is present, so supply C11's function + # instead of refusing to build. + message(STATUS "timespec_get missing (mingw/msvcrt): using compat shim") + set(DEUCE_TIMESPEC_SHIM "${CMAKE_CURRENT_SOURCE_DIR}/compat_timespec.c") + add_compile_options(-include "${CMAKE_CURRENT_SOURCE_DIR}/compat_timespec.h") + else() + message(FATAL_ERROR + "DeuceSSH requires C11's timespec_get / TIME_UTC in . " + "This SDK/libc predates them — upgrade the platform toolchain.") + endif() endif() # C11 threads: glibc (2.28+), recent macOS SDKs, and FreeBSD 12+ have @@ -423,7 +433,7 @@ set(DEUCESSH_INSTALL_TARGETS "") # --- Static library --- if(DEUCESSH_BUILD_STATIC) - add_library(deucessh_static STATIC ${DEUCESSH_SOURCES}) + add_library(deucessh_static STATIC ${DEUCESSH_SOURCES} ${DEUCE_TIMESPEC_SHIM}) add_library(deucessh::static ALIAS deucessh_static) set_property(TARGET deucessh_static PROPERTY C_STANDARD ${DEUCESSH_C_STANDARD}) set_property(TARGET deucessh_static PROPERTY C_STANDARD_REQUIRED ON) @@ -459,7 +469,7 @@ endif() # --- Shared library --- if(DEUCESSH_BUILD_SHARED) - add_library(deucessh_shared SHARED ${DEUCESSH_SOURCES}) + add_library(deucessh_shared SHARED ${DEUCESSH_SOURCES} ${DEUCE_TIMESPEC_SHIM}) add_library(deucessh::shared ALIAS deucessh_shared) set_property(TARGET deucessh_shared PROPERTY C_STANDARD ${DEUCESSH_C_STANDARD}) set_property(TARGET deucessh_shared PROPERTY C_STANDARD_REQUIRED ON) diff --git a/src/ssh/compat_timespec.c b/src/ssh/compat_timespec.c new file mode 100644 index 00000000..084b7823 --- /dev/null +++ b/src/ssh/compat_timespec.c @@ -0,0 +1,22 @@ +#include "compat_timespec.h" +#undef timespec_get +#include + +/* GetSystemTimeAsFileTime rather than clock_gettime: clock_gettime lives in + * winpthread, and the shared library links without it. */ +int deuce_timespec_get(struct timespec *ts, int base) +{ + FILETIME ft; + ULARGE_INTEGER u; + + if (base != TIME_UTC) + return 0; + GetSystemTimeAsFileTime(&ft); + u.LowPart = ft.dwLowDateTime; + u.HighPart = ft.dwHighDateTime; + /* 100ns ticks since 1601-01-01 -> seconds and nanoseconds since epoch */ + u.QuadPart -= 116444736000000000ULL; + ts->tv_sec = (time_t)(u.QuadPart / 10000000ULL); + ts->tv_nsec = (long)((u.QuadPart % 10000000ULL) * 100ULL); + return TIME_UTC; +} diff --git a/src/ssh/compat_timespec.h b/src/ssh/compat_timespec.h new file mode 100644 index 00000000..cea3ba10 --- /dev/null +++ b/src/ssh/compat_timespec.h @@ -0,0 +1,13 @@ +/* mingw/msvcrt has no timespec_get: the header only declares it under UCRT, + * where it resolves to _timespec64_get, which msvcrt.dll does not export. + * clock_gettime is there (winpthread), so C11's function is a two-line shim. + * Force-included into every DeuceSSH translation unit by the cross build. */ +#ifndef DEUCE_COMPAT_TIMESPEC_H +#define DEUCE_COMPAT_TIMESPEC_H +#include +#ifndef TIME_UTC +#define TIME_UTC 1 +#endif +int deuce_timespec_get(struct timespec *ts, int base); +#define timespec_get deuce_timespec_get +#endif -- 2.47.3