MSVC Build for Prophet

Prophet has been a Linux / gcc engine forever. To run on Windows, I resorted to using Cygwin. It’s been on my to do list to build Prophet natively under Windows using MSVC. The problem is, I’m not well versed with MSVC. Over the holidays I decided to see if OpenAI’s coding agent Codex could help.

My first attempt was literally just telling Codex to make the codebase build cleanly under MSVC. With some minor coaxing it finally did, but the resulting binary just … crashed. I’m actually not sure what went wrong. So, I reset and tried to make a series of smaller changes.

The first step was to create some abstractions, particularly around threading. With help from Codex, I unified thread and mutex usage behind explicit wrappers so thread creation, locking, and joining behave identically on Windows and POSIX systems.

From there, I updated CMake for MSVC and tried to compile. Not quite there yet.

MSVC’s lack of support for C99 variable-length arrays required some refactoring. Where sizes had known upper bounds, I replaced VLAs with fixed-size arrays. Where they were truly dynamic, I moved allocations to the heap.

I also had to address a series of MSVC CRT warnings promoted to errors. Functions like setbuf, freopen, and getenv were replaced with their Windows-safe equivalents (setvbuf, freopen_s, _dupenv_s), wrapped in #ifdef _WIN32 where appropriate so non-Windows builds remain untouched.

Testing needed similar attention. Capturing stdout and locating test resources relied on POSIX assumptions. I introduced small helpers to abstract device paths and resource locations, allowing tests to run cleanly on both Linux and Windows without cluttering test code with platform checks.

There were some C/C++ linkage issues in the test suite. The engine is written in C, but tests compile as C++, which led to name-mangling problems for global symbols. Centralizing these declarations in a shared header wrapped with extern "C" eliminated a whole class of MSVC linker errors.

All in all, it still wasn’t a trivial affair, but Codex did help me get it across the finish line.

Chess programming is, in my view, a creative endeavor. That being the case, I wouldn’t use a coding agent for anything that actually modified the engine’s behavior, but this feels like an appropriate use.

As I write this, all the work is still on a branch for further testing, but I anticipate it will make its way into a release in the near future.