Skip to content

Add MSVC native build support for Windows#1502

Open
djdarcy wants to merge 2 commits intotsl0922:mainfrom
djdarcy:fix/windows-conpty
Open

Add MSVC native build support for Windows#1502
djdarcy wants to merge 2 commits intotsl0922:mainfrom
djdarcy:fix/windows-conpty

Conversation

@djdarcy
Copy link

@djdarcy djdarcy commented Mar 13, 2026

Fixes #1501. Related: #1412.

The MinGW-W64 cross-compiled Windows binary fails on Windows 11 25H2 (build 26200+). CreateProcessW returns 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:

  • Branch compiler flags for GCC vs MSVC (/W3, /wd4996, _CRT_SECURE_NO_WARNINGS)
  • Resolve vcpkg cmake targets for libwebsockets (websockets_shared / websockets)
  • Add getopt-win32 package for MSVC (POSIX getopt.h isn't available)

src/compat.h (new):

  • MSVC shims behind #ifdef _MSC_VER: strcasecmp, strncasecmp, S_ISDIR, S_ISREG

src/pty.c:

  • Guard #include <unistd.h> with #ifndef _WIN32
  • Initialize cwd to NULL (was uninitialized)
  • Report errors in connect_cb instead of silently freeing

src/server.c:

  • Cast void* pointer arithmetic for strict C compliance
  • Guard getopt.h for MSVC

src/protocol.c, src/utils.c:

  • Include compat.h

Build instructions (MSVC + vcpkg)

vcpkg install libwebsockets:x64-windows libuv:x64-windows json-c:x64-windows zlib:x64-windows openssl:x64-windows getopt-win32:x64-windows
cmake -B build -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/builtin/vcpkg.cmake
cmake --build build --config Release

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.

djdarcy added 2 commits March 12, 2026 23:57
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.
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.

ConPTY fails on Windows 11 25H2, MinGW cross-compiled binary can't spawn child process

1 participant