fix(build): force _WIN32_WINNT>=0x0600 on Windows

librist unconditionally calls WSAPoll and uses inet_pton/inet_ntop on
Windows. mingw-w64's <winsock2.h> and <ws2tcpip.h> only declare those
symbols (plus POLLIN/POLLOUT/POLLRDNORM/POLLRDBAND/POLLPRI/POLLHUP/
struct pollfd) under _WIN32_WINNT >= 0x0600 (Vista).

Downstream consumers that pin a lower baseline break the librist build
without any librist source change: VLC 3.0's contrib toolchain, for
example, passes -D_WIN32_WINNT=0x0502 -DWINVER=0x0502 after librist's
own meson-supplied -D_WIN32_WINNT=0x0600, and the later definition
wins, leaving every polling/inet_* symbol undeclared.

Bump _WIN32_WINNT to at least 0x0600 at the top of every translation
unit that pulls in <winsock2.h>, <windows.h> or <ws2tcpip.h>, so the
first system header to be processed sees the Vista baseline and the
include guards do not short-circuit later consumers:

  include/librist/udpsocket.h   (public header, defines EVSOCKET_EV_READ POLLIN)
  src/libevsocket.c             (uses WSAPoll via contrib/poll_win.c)
  contrib/pthread-shim.h        (pulled in via rist-private.h)
  contrib/socket-shim.h         (pulled in via rist-private.h)
  contrib/endian-shim.h         (ntohs/htonl helpers)
  contrib/time-shim.h           (gettimeofday/clock helpers)

The block is a no-op when the caller already targets Vista or newer.
This mirrors the pattern VLC uses in its own modules/audio_output/
wasapi.c, modules/audio_output/mmdevice.c and modules/video_output/
win32/direct3d11.c to selectively target a higher Windows minimum
than the project-wide baseline.

librist already requires Vista+ at runtime (no select-based fallback
for WSAPoll); this change only surfaces that requirement at build
time when an XP-era baseline is forced by the consumer.

Verified by cross-compiling with x86_64-w64-mingw32-gcc 15.2.0 and
CFLAGS=-D_WIN32_WINNT=0x0502 (VLC 3.0 contrib baseline): build
produces a clean librist.dll with zero compile errors. Without this
patch the same command fails with 'POLLIN undeclared' in udpsocket.h
and 'implicit declaration of inet_pton/inet_ntop' in udp.c and
rist-common.c, matching the VLC MR CI output.
This commit is contained in:
Sergio Ammirata
2026-04-18 04:44:36 -04:00
parent 007d43db9a
commit e428a6d524
6 changed files with 47 additions and 0 deletions
+8
View File
@@ -10,6 +10,14 @@
#if defined(_WIN32)
/* librist uses WSAPoll/inet_pton/inet_ntop which mingw-w64 gates on
* _WIN32_WINNT >= 0x0600. Force a Vista minimum before <winsock2.h>
* is pulled in, so downstream consumers that set a lower baseline
* (e.g. VLC 3.0 contribs pin it to XP SP2 via 0x0502) still compile. */
#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600
# undef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
#endif
#include <winsock2.h>
#define be16toh(x) ntohs(x)
+8
View File
@@ -12,6 +12,14 @@
#include "config.h"
#ifdef _WIN32
/* librist uses WSAPoll/inet_pton/inet_ntop which mingw-w64 gates on
* _WIN32_WINNT >= 0x0600. Force a Vista minimum before <winsock2.h>
* is pulled in, so downstream consumers that set a lower baseline
* (e.g. VLC 3.0 contribs pin it to XP SP2 via 0x0502) still compile. */
#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600
# undef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
#endif
# include <stdbool.h>
# include <stdint.h>
#include <winsock2.h> //<-- not used here, but included because otherwise our order is broken.
+8
View File
@@ -12,6 +12,14 @@
#endif
#ifdef _WIN32
/* librist uses WSAPoll/inet_pton/inet_ntop which mingw-w64 gates on
* _WIN32_WINNT >= 0x0600. Force a Vista minimum before <winsock2.h>
* is pulled in, so downstream consumers that set a lower baseline
* (e.g. VLC 3.0 contribs pin it to XP SP2 via 0x0502) still compile. */
#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600
# undef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
#endif
#include <winsock2.h>
#define _WINSOCKAPI_
#include <windows.h>
+8
View File
@@ -11,6 +11,14 @@
#include "config.h"
#if defined(_WIN32)
/* librist uses WSAPoll/inet_pton/inet_ntop which mingw-w64 gates on
* _WIN32_WINNT >= 0x0600. Force a Vista minimum before <winsock2.h>
* is pulled in, so downstream consumers that set a lower baseline
* (e.g. VLC 3.0 contribs pin it to XP SP2 via 0x0502) still compile. */
#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600
# undef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
#endif
#include <winsock2.h>
#include <time.h>
#define usleep(a) Sleep((a)/1000)
+8
View File
@@ -22,6 +22,14 @@
/* Windows */
#ifdef _WIN32
/* librist uses WSAPoll/inet_pton/inet_ntop which mingw-w64 gates on
* _WIN32_WINNT >= 0x0600. Force a Vista minimum before <winsock2.h>
* is pulled in, so downstream consumers that set a lower baseline
* (e.g. VLC 3.0 contribs pin it to XP SP2 via 0x0502) still compile. */
#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600
# undef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
#endif
#include <winsock2.h>
#define _WINSOCKAPI_
#include <windows.h>
+7
View File
@@ -16,6 +16,13 @@
#ifdef _WIN32
/* librist uses WSAPoll and needs struct pollfd / POLLIN / POLLOUT from
* <winsock2.h>, all gated on _WIN32_WINNT >= 0x0600 by mingw-w64. */
#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600
# undef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
#endif
#if !defined(UNDER_CE)
# define _NO_OLDNAMES 1
# include <io.h>