Add Windows/MinGW support#430
Open
nbeerbower wants to merge 43 commits into
Open
Conversation
- Update Makefile with platform detection for Windows/MinGW/MSYS2 - Add HML_WINDOWS preprocessor macro - Configure Windows-specific libraries (-lws2_32, no -ldl) - Set up platform-specific LDFLAGS - Add Windows compatibility to runtime builtins - Windows socket abstraction (Winsock2 initialization, closesocket) - Directory iteration via FindFirstFile/FindNextFile - Dynamic library loading via LoadLibrary/GetProcAddress - Clock/time functions using Windows API - Compatibility macros for POSIX functions (access, getcwd, etc.) - Add Windows compatibility to interpreter builtins - Signal handling using signal() instead of sigaction() - Platform-specific includes and function mappings - realpath() implementation via GetFullPathNameA - Add Windows compatibility to compiler codegen - basename/dirname implementations for Windows - open_memstream fallback using tmpfile - Update test runner to skip Windows-incompatible tests - Signal tests, fork tests, Unix socket tests, termios tests - Platform detection for MSYS/MinGW/Cygwin - Add docs/WINDOWS_SUPPORT.md with build instructions and API docs https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
- Add windows-test job: runs interpreter tests with MSYS2/MinGW - Add windows-compiler job: builds and tests the compiler - Add windows-parity job: runs parity tests on Windows - Add build-windows job to release workflow: creates Windows release package - Include MinGW runtime DLLs (libgcc, libwinpthread, libffi) in Windows release - Update release notes with Windows quick start and platform notes https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
- Use LoadLibrary/GetProcAddress/FreeLibrary on Windows instead of dlopen/dlsym/dlclose - Add Windows library path translation (libc.so.6 -> msvcrt.dll, .so -> .dll) - Use platform-agnostic hml_lib_handle_t type for library handles - Proper error handling with Windows error codes https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
- Add get_executable_path() helper function that works on Windows, macOS, and Linux
- Use GetModuleFileNameA on Windows instead of readlink("/proc/self/exe")
- Use _NSGetExecutablePath on macOS
- Replace all direct readlink calls with the portable helper
https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
- compiler/main.c: Add Windows compatibility for access, unlink, close, popen - context.c: Add Windows compatibility for getcwd - parser/module.c: Add Windows compatibility for getcwd - modules/modules.c: Add Windows compatibility for GetModuleFileNameA, access, getcwd, dirname https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
Avoid naming conflict with Windows' TokenType defined in winnt.h. https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
MinGW provides ssize_t via sys/types.h, no need to redefine it. https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
sigset_t, sigfillset, and pthread_sigmask are not available on Windows. https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
Windows doesn't have realpath - use GetFullPathNameA instead. https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
Windows doesn't have getline - provide a compatible implementation. https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
Windows uses Sleep() in milliseconds instead of nanosleep/usleep. https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
The runtime library has its own Makefile which was missing Windows/MinGW platform detection and the -DHML_WINDOWS flag. https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
MinGW already provides nanosleep and struct timespec via time.h. Only keep usleep compatibility wrapper. https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
MinGW provides usleep via unistd.h, no need to define it. https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
Replace POSIX DIR/dirent/opendir/readdir/closedir with hml_dir_t/hml_dirent_t/hml_opendir/hml_readdir/hml_closedir which work on both Windows and POSIX systems. https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
nbeerbower
force-pushed
the
claude/add-windows-support-FXUyc
branch
from
January 28, 2026 18:21
5be5dbe to
601423e
Compare
- Add setenv/unsetenv wrappers using _putenv_s - Add Windows stubs for getppid, getuid, geteuid, getgid, getegid - Add WIFEXITED/WEXITSTATUS macros for Windows - Add Windows CreateProcess implementation for exec() and exec_argv() - Add Windows TerminateProcess implementation for kill() - Add error returns for fork(), wait(), waitpid() on Windows https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
- Remove duplicate getppid/getuid/etc macros from env.c (already in internal.h) - Add fcntl.h include for Windows (provides O_RDONLY, O_WRONLY, etc.) - Add open/_open and lseek/_lseek mappings for Windows https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
- Remove nanosleep/clock_gettime definitions (MinGW pthreads provides them) - Remove POLLIN/POLLOUT redefinitions (MinGW winsock2.h provides them) - Remove ssize_t typedef (MinGW corecrt.h provides it) - Use hml_dirent_t instead of struct dirent in runtime and interpreter https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
- Wrap POSIX socket headers in #ifndef HML_WINDOWS - Replace close() with hml_closesocket() for socket file descriptors - Add Windows ioctlsocket() for non-blocking mode (replaces fcntl) https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
- Cast setsockopt value pointer to (const char*) for Windows - Use DWORD milliseconds for socket timeouts on Windows (instead of struct timeval) https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
Add Windows implementations for system information functions: - builtin_arch(): Use GetNativeSystemInfo() - builtin_username(): Use GetUserNameA() and USERNAME env var - builtin_homedir(): Use USERPROFILE and HOMEDRIVE/HOMEPATH - builtin_cpu_count(): Use GetSystemInfo() - builtin_total_memory(): Use GlobalMemoryStatusEx() - builtin_free_memory(): Use GlobalMemoryStatusEx() - builtin_os_version(): Use GetVersionExA() - builtin_os_name(): Return "Windows" - builtin_uptime(): Use GetTickCount64() - builtin_tmpdir(): Use GetTempPathA() as fallback Wrap POSIX headers (sys/utsname.h, pwd.h) in #ifndef HML_WINDOWS. https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
POSIX regex (regex.h) is not available on Windows/MinGW, so add stub implementations that return errors indicating regex is not supported. The regex functions now: - Return errors on Windows indicating unsupported feature - Continue to use POSIX regex on Unix/macOS https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
poll.h is not available on Windows - poll functionality comes from winsock2.h which is already included via internal.h. https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
Interpreter (registration.c): - Wrap POSIX-only signal constants (SIGHUP, SIGQUIT, etc.) in #ifndef HML_WINDOWS - Keep common signals (SIGINT, SIGTERM, SIGABRT) available on all platforms Runtime (builtins_internal.h): - Add stat compatibility (sys/stat.h, S_ISREG, S_ISDIR) for Windows Runtime (builtins_io.c): - Add Windows implementations for system info functions: - hml_arch(): Use GetNativeSystemInfo() - hml_username(): Use GetUserNameA() and USERNAME env var - hml_homedir(): Use USERPROFILE and HOMEDRIVE/HOMEPATH - hml_cpu_count(): Use GetSystemInfo() - hml_total_memory(): Use GlobalMemoryStatusEx() - hml_free_memory(): Use GlobalMemoryStatusEx() - hml_os_version(): Use GetVersionExA() - hml_os_name(): Return "Windows" - hml_uptime(): Use GetTickCount64() - hml_tmpdir(): Use GetTempPathA() as fallback - Update hml_list_dir() to use platform-agnostic hml_opendir/readdir/closedir https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
gettimeofday() is not available on Windows. Use GetSystemTimeAsFileTime() instead, which returns time in 100-nanosecond intervals since 1601. Convert to milliseconds since Unix epoch for consistent behavior. https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
The interpreter's io/file_methods.c uses getline() which is not available on Windows. Add a Windows-compatible hml_getline() implementation to the interpreter's internal.h header. https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
- Reorder includes: winsock2.h must come before windows.h to avoid warnings - Remove duplicate hml_getline definition (now provided by ../internal.h) https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
…tions builtins_internal.h: - Add #ifndef guards for S_ISREG and S_ISDIR (MinGW already provides them) builtins_process.c: - Add Windows compatibility macros: WIFEXITED, WEXITSTATUS - Add Windows pipe compatibility using _pipe() - Add stub macros for waitpid, wait, kill, fork (return -1) - Add hml_setenv and hml_unsetenv using _putenv_s - Use basic signal() function on Windows instead of sigaction() https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
strndup() is not available on Windows. Add a Windows-compatible hml_strndup() implementation for the LSP handlers. https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
- Add Windows socket includes (winsock2.h, ws2tcpip.h) - Define STDIN_FILENO and STDOUT_FILENO for Windows - Map close() to closesocket() for socket handles - Wrap POSIX socket headers in #ifndef HML_WINDOWS https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
- Cast setsockopt arg to (const char *) for Windows API compatibility - Move winsock2.h/ws2tcpip.h includes to parent internal.h - Remove duplicate winsock includes from builtins internal.h - This fixes the 'include winsock2.h before windows.h' warnings https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
- Add hml_strndup implementation for Windows - Wrap unistd.h include in #ifndef HML_WINDOWS https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
- Add hml_realpath implementation using _fullpath for Windows - Wrap _XOPEN_SOURCE in #ifndef HML_WINDOWS https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
- Add hml_realpath implementation using _fullpath for Windows https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
- Cast setsockopt arg to (const char *) for Windows API compatibility https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
On Windows/MSYS2, backslashes in paths were being interpreted as escape sequences when displayed via echo. Using printf '%s' avoids this issue and displays paths correctly. https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
- Add socket_error_msg() helper that uses WSAGetLastError() on Windows - Replace all strerror(errno) with socket_error_msg() for socket ops - Add WinSock initialization (WSAStartup) before socket/DNS operations - This fixes 'No error' messages and DNS resolution failures on Windows https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn
Resolved conflicts: - runtime/Makefile: Keep Windows platform guard for zlib/OpenSSL checks - runtime/src/builtins_internal.h: Add inttypes.h include (dlfcn.h handled via Windows compat layer) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add OpenSSL to Windows LDFLAGS in runtime/Makefile - Add ECDSA version check - requires OpenSSL 3.0+ (stub for older versions) - Fix hml_dirname to find correct last separator with mixed / and \ paths - Fix Windows absolute path detection (C:\ style) in module resolver - These fixes resolve module imports and stdlib loading on Windows Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Update Makefile with platform detection for Windows/MinGW/MSYS2
Add Windows compatibility to runtime builtins
Add Windows compatibility to interpreter builtins
Add Windows compatibility to compiler codegen
Update test runner to skip Windows-incompatible tests
Add docs/WINDOWS_SUPPORT.md with build instructions and API docs
https://claude.ai/code/session_01YL2nKyNmSwkQ7DicdGCrvn