Repository navigation
Build the library on Windows with clang-cl - #210
Merged
Merged
Conversation
- Detect the MAC address on Windows with GetAdaptersAddresses(), applying the same up, non-loopback, routable-IP filter as the getifaddrs() path - Use /W4 instead of -Wall on MSVC-style compilers, where clang-cl reads -Wall as -Weverything; quiet -Wpedantic's report of opus_types.h's __int32/__int64 keywords - Define NOMINMAX, WIN32_LEAN_AND_MEAN and NOGDI privately, since <windows.h> (reached through IXWebSocket) defines min/max and wingdi's ERROR as macros - Default micro-opus to USE_ALLOCA on Windows, whose default thread-safe pseudostack needs pthread TLS Tests and examples remain POSIX-only.
This was referenced Oct 21, 2026
kahrendt
pushed a commit
that referenced
this pull request
Oct 28, 2026
On Windows every socket call fails until `WSAStartup()` runs, and
IXWebSocket leaves that to the application through
`ix::initNetSystem()`. The client could neither dial a server ("Either
the application has not called WSAStartup") nor listen.
## Summary
- `SendspinWsServer::start()` and `SendspinClientConnection::start()`
call `ix::initNetSystem()` once, through a function-local static, before
their first socket. It is never undone; Windows releases it at process
exit.
- The two handle a failure differently on purpose. The server's
`start()` returns a bool, so it logs and returns false. The client's
`start()` has no failure return, so it logs and lets the attempt go
ahead; its first socket call then fails and IXWebSocket reports it as
the connection's `Error`, which already reports the close.
## Notes
- A no-op on POSIX (`initNetSystem()` returns true without doing
anything there).
- Follows #210, which made the library compile on Windows with clang-cl.
Split out of #211.
## Testing
- Windows 11, clang-cl 22.1.3 (from #211): `basic_client` dials Music
Assistant with `-u` and listens on its own port; before this change both
failed with the WSAStartup error.
- Linux, GCC 16: host build clean; `sendspin_tests` all pass. The
ASan/UBSan and TSan runs are this PR's CI (no sanitizer runtime on the
local machine).
kahrendt
pushed a commit
that referenced
this pull request
Nov 4, 2026
A Windows consumer that includes `<windows.h>` before the sendspin headers, as most Win32 code does, fails to compile them. The library's `NOMINMAX` / `WIN32_LEAN_AND_MEAN` / `NOGDI` from #210 are private, so they never covered the public headers. ## Summary - **`LogLevel::ERROR`.** wingdi.h defines `ERROR` as `0`, which turned the enumerator into `0 = 1`. `client.h` now sets the macro aside around `LogLevel` with `#pragma push_macro("ERROR")` / `#undef ERROR` / `#pragma pop_macro("ERROR")`, so the consumer's own `ERROR` is back after it. The pragmas are supported by GCC, Clang and MSVC, so the header needs no `#ifdef _WIN32`, and they are no-ops where `ERROR` is not defined. - **`std::numeric_limits<uint16_t>::max()`** in `PlayerRoleConfig::pipeline_lead_time_ms()` was expanded by windows.h's function-like `max()` macro. It is now `(std::numeric_limits<uint16_t>::max)()`, with a comment so the parentheses are not tidied away. - **`tests/test_windows_header_macros.cpp`**, a compile-only translation unit in `sendspin_tests` that guards both on every host. It includes the standard headers the public headers use, then defines `ERROR`, `min()` and `max()` as `<windows.h>` does, then includes every public header: `client.h`, `persistence_codec.h` and each enabled role's header (`client.h` only forward-declares the roles). A `static_assert` checks that `ERROR` is restored. The standard headers come first because libstdc++ and libc++ don't guard themselves against a function-like `max()` the way the MSVC STL does. A new standard include in a public header has to be added there too, as its comment says. ## Notes - Consumer code that itself names `LogLevel::ERROR` after `<windows.h>` still needs `NOGDI` or its own `#undef ERROR`; the comment above `LogLevel` says so. Renaming the enumerator would remove that, but it would break the API for every consumer, so it is left alone. - The new test simulates the macros rather than including the real `<windows.h>`. A Windows CI job is planned as a follow-up. It would compile the library and `basic_client` on Windows, and with them the public headers after the real `<windows.h>`. - The saturated lead time isn't re-checked in the new test: the macro can only break the build, not change the value, and `test_player_role.cpp` already pins `pipeline_lead_time_ms()`. ## Testing - Windows 11, clang-cl 22.1.3 (Visual Studio 2026), `/W4`, every role enabled, one translation unit including every public header: - `<windows.h>` first: failed with 3 errors before this change, compiles cleanly after it. - `<windows.h>` after the sendspin headers, with `NOMINMAX` + `WIN32_LEAN_AND_MEAN`, and without `<windows.h>`: all compile cleanly. - `static_assert(ERROR == 0)` after the headers holds, so `pop_macro` restores wingdi's macro. - With `NOGDI`, consumer code can name `LogLevel::ERROR` after `<windows.h>`; without it, it fails in the consumer's own line, as the header comment says. - Windows 11, clang-cl: the `sendspin` target builds with no warnings from the library's own sources. - Linux (WSL), GCC 13, `-Wall -Wextra -Wpedantic`: both headers compile, a consumer's own `ERROR` macro survives the include, and `pipeline_lead_time_ms(0xFFFF)` still saturates at `0xFFFF`. - Mutations against `test_windows_header_macros.cpp` (GCC 13, every role enabled). Each one alone fails the build: - no parentheses around `max` in `config.h`: fails at `config.h:418`; - no `push_macro` / `#undef` in `client.h`: "expected identifier before numeric constant"; - no `pop_macro`: the `static_assert` fails ("ERROR was not declared"); - a bare `std::numeric_limits<int>::max()` added to `artwork_role.h`, or separately to `visualizer_role.h`: fails at that line. The first version of the test (`1e8e506`), which included only `client.h` and `persistence_codec.h`, still compiled with either. - CI on `1c24d4a`: all checks green; the unit-test job builds the new translation unit and passes 707/707. - clang-format: no changes.
kahrendt
added a commit
that referenced
this pull request
Nov 4, 2026
Depends on #213 (Winsock init): this branch is stacked on it, and `basic_client` cannot dial or listen on Windows without it. Review only the top commit; the base switches to `main` once #213 merges. ## Summary - **PortAudio on Windows.** Windows has no pkg-config or system PortAudio, so `examples/basic_client/CMakeLists.txt` fetches PortAudio v19.7.0 on `WIN32` and builds it as a static library. POSIX keeps the pkg-config lookup. - **`getopt()` for Windows.** `examples/common/win_getopt.h` is a minimal stand-in for the missing one. It covers grouped flags, `-x val` / `-xval`, and stops at the first non-option or `--`. Errors return `?` without a message, since the example prints its usage on that. - **The pairing-window gesture.** Console keys `p` / `c` stand in for `SIGUSR1` / `SIGUSR2`. A single `#ifdef _WIN32` block defines the key poll (a no-op on POSIX) and the hint strings, so the usage text and the pairing-window prompt name the right gesture on each platform. - **Persistence.** The provider writes through `_open` / `_write` / `_commit` and replaces the file with `std::filesystem::rename()`, because `std::rename()` won't replace an existing file on Windows. It falls back to `%USERPROFILE%` when `HOME` is unset. Each `write_file()` variant has its own doc comment. - **README.** `examples/basic_client/README.md` gets a Windows section covering the build, no mDNS (so dial with `-u`), the `p`/`c` keys, and the persistence file's permissions. - **The default build.** `tui_client` includes POSIX `<getopt.h>`, so the top-level `CMakeLists.txt` skips it on `WIN32` with a status message, the way `source_client` already skips itself without PortAudio. A standalone Windows build with the examples on (the default) now succeeds. - **CRT warnings.** `basic_client` defines `_CRT_SECURE_NO_WARNINGS` on `WIN32`, since the persistence provider's `getenv()` and `_open()` otherwise draw deprecation warnings pointing at `_dupenv_s` / `_sopen_s`. ## Notes - The persistence file can't be created 0600 on Windows. It inherits its directory's ACL, which under `%USERPROFILE%` grants only the user, SYSTEM and Administrators. - `tui_client`, `source_client` and the tests remain POSIX-only. The top-level README's "macOS/Linux" wording is left alone, since #210 deferred the library's Windows support scope. - Split out of #211. ## Testing - Windows 11, clang-cl 22.1.3 (Visual Studio 2026, Ninja, Release), from #211: `sendspin` and `basic_client` built with no warnings from the library's own sources. `basic_client.exe -p 8929 -u ws://<music-assistant>:8927/sendspin` completed the Noise handshake, was admitted (unpaired) and listened locally. Pairing and playback were not exercised. - Windows 11, clang-cl (Visual Studio 2026, Ninja), on this branch: a clean configure and build with the default `BUILD_EXAMPLES` succeeds, skipping `tui_client` and `source_client`, with no warnings from the repo's own sources. `basic_client.exe -h` names the `p`/`c` keys, an unknown option prints the usage, and `basic_client.exe -p 8931` starts and listens on 8931. - The trimmed `win_getopt.h` was checked on Linux against `basic_client`'s optstring: grouped flags, `-pVAL`, `-p VAL`, `--`, a lone `-`, an unknown option, a missing argument and `-:`. - Linux, GCC 16: host build including the examples is clean, and `sendspin_tests` passes 705/705. The sanitizer runs are this PR's CI. --------- Co-authored-by: Kevin Ahrendt <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The host build only compiles on macOS and Linux. With clang-cl on Windows it fails in four places, and clang-cl reads the target's
-Wallas/Wall, which is-Weverything(about 40,000 warnings).src/host/network_info.cppusesgetifaddrs(). A_WIN32branch now walksGetAdaptersAddresses()with the same filter: adapter up, not loopback, a 6-byte hardware address, and a routable unicast address. It reusesis_routable_ip()andformat_mac().<windows.h>, reached through IXWebSocket's winsock include, definesmin/maxand wingdi'sERRORas macros, which breakstd::min/std::maxandLogLevel::ERROR. The library target definesNOMINMAX,WIN32_LEAN_AND_MEANandNOGDIprivately; no public header includes<windows.h>, so consumers' GDI and min/max settings are untouched.THREADSAFE_PSEUDOSTACKkeeps its per-thread state in pthread TLS. On WindowsOPUS_ALLOCATION_MODEdefaults toUSE_ALLOCA, which stays thread-safe between the player's decoder and the source's encoder; a consumer that sets the mode keeps its own./W4 -Wpedantic -Wno-language-extension-token.opus_types.huses the__int32/__int64keywords on Windows, which-Wpedanticreports as an extension.Notes
pthread.handunistd.h, and the sanitizer options pass GCC-style flags.-DENABLE_WERROR=ONstill fails on Windows inside micro-flac: itshost.cmakeadds-Walland honours the sameENABLE_WERRORcache variable. Every sendspin object compiles cleanly with-Werror; the fix belongs in micro-flac.Testing
-DBUILD_EXAMPLES=OFF):sendspin.libbuilds with zero warnings from the library's own sources; with-DENABLE_WERROR=ONonly micro-flac's objects fail.sendspin.libcalledplatform_get_interface_mac()and returned the physical NIC's MAC, skipping the Hyper-V and WSL virtual adapters listed ahead of it.