Add MSVC native build support for Windows#1502
Open
djdarcy wants to merge 2 commits intotsl0922:mainfrom
Open
Conversation
The MinGW-W64 cross-compiled binary fails on Windows 11 25H2 (build 26200+): CreateProcessW returns error 123 (ERROR_INVALID_NAME) during ConPTY setup, so no child process spawns and the browser shows "Reconnecting" indefinitely. Building with MSVC resolves this. MSVC build support: - CMakeLists.txt: branch GCC/MSVC compiler flags, vcpkg cmake target resolution for libwebsockets, getopt-win32 package for MSVC - compat.h (new): POSIX shims for MSVC (strcasecmp, S_ISDIR, S_ISREG) - server.c: cast void* pointer arithmetic for strict C, getopt.h guard - protocol.c, utils.c: include compat.h - pty.c: guard unistd.h with #ifndef _WIN32 ConPTY diagnostic logging: - conpty_init: kernel32 load, function pointer resolution - conpty_setup: pipe creation, CreatePseudoConsole HRESULT, attribute list setup, with error codes on all failure paths - pty_spawn: CreateProcessW flags and result, PID on success - connect_cb: pipe connection status with uv error string Code fixes: - Initialize cwd to NULL (was uninitialized on non-cwd paths) - connect_cb reports errors instead of silently freeing Tested: Windows 11 25H2 build 26200.8037, VS 2022, vcpkg deps (libwebsockets 4.5.4, libuv, json-c, zlib, openssl, getopt-win32). Verified from both Git Bash and native cmd.exe. Related: tsl0922#1207, charmbracelet/vhs#631
Remove verbose debug output from conpty_init, conpty_setup, pty_spawn, and connect_cb. Keep error reporting on pipe connect failure. The debug-instrumented version is preserved in the previous commit for reference.
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.
Fixes #1501. Related: #1412.
The MinGW-W64 cross-compiled Windows binary fails on Windows 11 25H2 (build 26200+).
CreateProcessWreturns error 123 (ERROR_INVALID_NAME) during ConPTY setup -- no child process spawns and the browser shows "Reconnecting."Building natively with MSVC resolves it. All ConPTY steps succeed and the terminal works.
Changes
CMakeLists.txt:
/W3,/wd4996,_CRT_SECURE_NO_WARNINGS)websockets_shared/websockets)getopt-win32package for MSVC (POSIXgetopt.hisn't available)src/compat.h (new):
#ifdef _MSC_VER:strcasecmp,strncasecmp,S_ISDIR,S_ISREGsrc/pty.c:
#include <unistd.h>with#ifndef _WIN32cwdtoNULL(was uninitialized)connect_cbinstead of silently freeingsrc/server.c:
void*pointer arithmetic for strict C compliancegetopt.hfor MSVCsrc/protocol.c, src/utils.c:
compat.hBuild instructions (MSVC + vcpkg)
Notes
As mentioned in #1501 I understand this adds MSVC-specific paths that may not be desirable upstream. The existing GCC/MinGW build paths are unchanged and all MSVC additions are behind
if(MSVC)or#ifdef _MSC_VER. Happy to adjust the approach if you'd prefer a different structure, or I can maintain a fork with pre-built Windows binaries if that's simpler (already setup an example release here).Tested on Windows 11 Pro 25H2 (build 26200.8037), VS 2022, verified from both Git Bash and native
cmd.exe.