Skip to content

Add Windows compatibility support#1

Open
AliRezaBeigy wants to merge 5 commits intoMygod:masterfrom
AliRezaBeigy:master
Open

Add Windows compatibility support#1
AliRezaBeigy wants to merge 5 commits intoMygod:masterfrom
AliRezaBeigy:master

Conversation

@AliRezaBeigy
Copy link

Adds comprehensive Windows build support to picoquic, enabling compilation on Windows using MSVC, MinGW, and other Windows toolchains.

Changes

Core Windows Compatibility

  • picoquic/wincompat.c: New file implementing wintimeofday() function, providing a Windows-compatible implementation of gettimeofday() for picotls and picoquic
  • picoquic/wincompat.h: Enhanced to:
    • Automatically define _WINDOWS macro when Windows is detected via standard macros (_WIN32, __WIN32__, __MINGW32__, etc.)
    • Include <ws2tcpip.h> for IPv6 socket structures (sockaddr_in6, etc.)
    • Provide gettimeofday macro mapping to wintimeofday

Build System Updates

  • CMakeLists.txt:
    • Added wincompat.c to picoquic-core library sources when building on Windows
    • When PICOQUIC_FETCH_PTLS=ON, automatically provides Windows compatibility files to picotls:
      • Copies wincompat.h to picotls include directory
      • Copies wincompat.c to picotls lib directory
      • Adds wincompat.c to picotls-core target
  • picoquic/picoquic.vcxproj: Added wincompat.c to Visual Studio project
  • picoquic/picoquic.vcxproj.filters: Added wincompat.c to Source Files filter

Header File Updates

  • picoquic/picoquic.h: Added early _WINDOWS detection to ensure correct header inclusion order
  • picoquic/picosocks.h: Added early _WINDOWS detection
  • picoquic/picoquic_packet_loop.h: Added ssize_t type definition for Windows compatibility

Why This Is Needed

  1. Missing gettimeofday(): Windows doesn't provide gettimeofday(), which is required by picotls. The wintimeofday() implementation converts Windows FILETIME to Unix timeval.

  2. IPv6 Support: Windows requires <ws2tcpip.h> for IPv6 socket structures, which was missing from the compatibility header.

  3. Build Integration: The existing wincompat.h and wincompat.c files weren't being compiled into the library, causing link errors on Windows.

Backward Compatibility

  • No changes to existing Unix/Linux builds
  • All changes are Windows-specific (#ifdef _WINDOWS or if(WIN32))
  • Existing code using #ifdef _WINDOWS continues to work without modification

@Mygod
Copy link
Owner

Mygod commented Jan 28, 2026

@codex review

@Mygod
Copy link
Owner

Mygod commented Jan 28, 2026

Some findings that I accidentally produced:

  • High: ssize_t is defined in two incompatible ways on Windows. picoquic/wincompat.h:30 defines it as a macro (#define ssize_t int), while picoquic/picoquic_packet_loop.h:33-39 adds typedef int ssize_t;. If any TU includes wincompat.h before picoquic_packet_loop.h, the macro expands to typedef int int; and fails to compile. Even when it compiles, int is the wrong width for 64‑bit Windows. Suggestion: centralize ssize_t in wincompat.h with #include <BaseTsd.h> and typedef SSIZE_T ssize_t;, set _SSIZE_T_DEFINED, and remove the new block from picoquic/picoquic_packet_loop.h.
  • Medium: struct timezone can be redefined if wincompat.h is force‑included as the comment claims. picoquic/wincompat.c:15-22 defines struct timezone behind _TIMEZONE_DEFINED, but picoquic/wincompat.h:47-52 defines it without setting that guard. If /FIwincompat.h is used, wincompat.c will re‑define the struct. Suggestion: include picoquic/wincompat.h in picoquic/wincompat.c and remove the local struct, or add _TIMEZONE_DEFINED in the header.
  • Medium: The picotls wiring may not actually fix Windows builds. In CMakeLists.txt:234-245 you copy wincompat.{h,c} into picotls and add the C file, but you never force-include wincompat.h for picotls, so gettimeofday calls in picotls (if any) may still be unresolved or using the wrong signature. Suggestion: explicitly force-include wincompat.h for picotls-core or patch picotls to include it on Windows.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive Windows build support to picoquic, enabling compilation using MSVC, MinGW, and other Windows toolchains. It implements the missing gettimeofday() function for Windows through wintimeofday() and ensures proper header inclusion for Windows networking APIs.

Changes:

  • Implements wintimeofday() function to provide Windows-compatible gettimeofday() functionality
  • Updates headers to auto-detect Windows platform and define _WINDOWS macro consistently
  • Integrates Windows compatibility files into build systems (CMake and Visual Studio projects)

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
picoquic/wincompat.c New implementation of wintimeofday() function that converts Windows FILETIME to Unix timeval
picoquic/wincompat.h Enhanced with automatic _WINDOWS detection, ws2tcpip.h inclusion, and gettimeofday macro mapping
picoquic/picoquic.h Added early _WINDOWS detection for correct header ordering
picoquic/picosocks.h Added early _WINDOWS detection for consistency
picoquic/picoquic_packet_loop.h Added Windows-specific ssize_t typedef and Windows-compatible function signature for picoquic_packet_loop_v3
CMakeLists.txt Added wincompat.c to build on Windows and provides compatibility files to fetched picotls dependency
picoquic/picoquic.vcxproj Added wincompat.c to Visual Studio project sources
picoquic/picoquic.vcxproj.filters Added wincompat.c to Source Files filter

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Mygod
Copy link
Owner

Mygod commented Jan 29, 2026

The changes still seem questionable to me. For example, "Missing gettimeofday()" is not true since the repo does contain an implementation so we should not reinvent the wheel.

@AliRezaBeigy
Copy link
Author

AliRezaBeigy commented Jan 29, 2026

@Mygod Thank you for the review. I've researched the issues raised:

  1. Regarding "gettimeofday already exists", I checked the upstream repositories and wincompat.c does NOT exist there. While wincompat.h declares wintimeofday(), there is no implementation anywhere in the upstream repo.

  2. Thanks for fixing the ssize_t incompatible definitions issue and addressing the struct timezone redefinition issue.

I made some additional changes:

  1. In CMakeLists.txt, we now force-include wincompat.h for ALL picotls targets, not just picotls-core, because other picotls components also need the Windows compatibility definitions. Without this change, the build failed.

  2. The _WINDOWS macro definition has been removed from CMakeLists.txt because it didn't work and still in the compilation I got error that compiler try to include non windows header. I've added the -D_WINDOWS option directly in the cc arguments in the slipstream-ffi build code instead. Mygod/slipstream-rust@c3dc75e

@Mygod
Copy link
Owner

Mygod commented Feb 2, 2026

It exists in picotls. Please refer to my comment in the other PR.

@AliRezaBeigy
Copy link
Author

@Mygod Thanks for the pointer. I’ve switched to picotls’ wintimeofday.c and dropped the duplicate in picoquic. All tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants