Skip to content

Add Windows support - #87

Merged
glbrntt merged 1 commit into
apple:mainfrom
jakepetroules:windows-support
Jul 6, 2026
Merged

glbrntt merged 1 commit into
apple:mainfrom
jakepetroules:windows-support

Conversation

@jakepetroules

Copy link
Copy Markdown
Member

c-ares shipped with POSIX-only config headers, so the build failed on Windows at the first #include <sys/socket.h>. Make the vendored config Windows-aware and wire up the platform bits:

  • ares_build.h: on _WIN32 use int for ares_socklen_t and the Win64/Win32 ares_ssize_t, and don't pull in <sys/socket.h>.
  • ares_config.h: on _WIN32 defer to c-ares's bundled config-win32.h via a path relative to the header, so it resolves both when compiling the c-ares sources and when the Swift compiler builds the Clang module from the umbrella header.
  • CAsyncDNSResolver.h: include winsock2.h/ws2tcpip.h instead of arpa/inet.h + netdb.h on Windows, and define CARES_STATICLIB so the statically-linked c-ares API isn't marked __declspec(dllimport).
  • Package.swift: define CARES_STATICLIB for the c-ares sources and link ws2_32/iphlpapi/advapi32 on Windows.
  • DNSResolver_c-ares.swift: recreate ARES_SOCKET_BAD (INVALID_SOCKET is a cast-expression macro Swift can't import and pass inet_ntop's size argument as size_t on Windows.

Enable the Windows unit-test matrix (6.1/6.2/6.3 + nightlies) in the PR workflow with the same warnings-as-errors flags as Linux.

c-ares shipped with POSIX-only config headers, so the build failed on
Windows at the first `#include <sys/socket.h>`. Make the vendored config
Windows-aware and wire up the platform bits:

- ares_build.h: on _WIN32 use `int` for ares_socklen_t and the Win64/Win32
  ares_ssize_t, and don't pull in <sys/socket.h>.
- ares_config.h: on _WIN32 defer to c-ares's bundled config-win32.h via a
  path relative to the header, so it resolves both when compiling the
  c-ares sources and when the Swift compiler builds the Clang module from
  the umbrella header.
- CAsyncDNSResolver.h: include winsock2.h/ws2tcpip.h instead of
  arpa/inet.h + netdb.h on Windows, and define CARES_STATICLIB so the
  statically-linked c-ares API isn't marked __declspec(dllimport).
- Package.swift: define CARES_STATICLIB for the c-ares sources and link
  ws2_32/iphlpapi/advapi32 on Windows.
- DNSResolver_c-ares.swift: recreate ARES_SOCKET_BAD (INVALID_SOCKET is a
  cast-expression macro Swift can't import and pass inet_ntop's size
  argument as size_t on Windows.

Enable the Windows unit-test matrix (6.1/6.2/6.3 + nightlies) in the PR
workflow with the same warnings-as-errors flags as Linux.
@glbrntt glbrntt added the 🆕 semver/minor Adds new public API. label Jul 6, 2026

@glbrntt glbrntt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great, thanks @jakepetroules!

@glbrntt
glbrntt merged commit 1447cb9 into apple:main Jul 6, 2026
42 of 43 checks passed
@jakepetroules
jakepetroules deleted the windows-support branch July 6, 2026 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants