From 1280abf544d5f867d8a5580d4a991e36b7c89c17 Mon Sep 17 00:00:00 2001 From: Zach Toogood Date: Mon, 19 Oct 2026 11:08:57 +0100 Subject: [PATCH 1/2] Build: Support MSVC, keep fixtures byte exact - std::filesystem in place of dirent.h - GCC flags and attributes only where the compiler takes them - fixtures/ is -text, so a CRLF checkout doesn't shift the expected byte offsets --- .gitattributes | 2 ++ CMakeLists.txt | 19 +++++++++++++------ src/compiler/symbols.cpp | 24 +++++++++++------------- src/runtime.cpp | 2 ++ tests/adlibc_test.cpp | 12 +++++------- tools/adlibc.cpp | 12 ++++++------ 6 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fa8ff52 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# The compiler fixtures are byte exact: expected diagnostics give byte offsets into them. +fixtures/** -text diff --git a/CMakeLists.txt b/CMakeLists.txt index 382527e..4cb50d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,13 +42,16 @@ target_include_directories(adlib PUBLIC $ $) target_compile_features(adlib PUBLIC cxx_std_17) -target_compile_options(adlib PRIVATE -Wall -Wextra -Wno-unused-parameter) # Lockstep determinism (the runtime does a little float math, e.g. id_SET_InteractorLatency): # no FMA contraction, no fast-math, SSE on x86. Hosts that need bit-identical simulation across -# builds should use the same flags. -target_compile_options(adlib PRIVATE -ffp-contract=off -fno-fast-math) -if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64" AND NOT EMSCRIPTEN) - target_compile_options(adlib PRIVATE -mfpmath=sse -msse2) +# builds should use the same flags. MSVC's /fp:precise contracts nothing and x64 is always SSE2. +if(MSVC) + target_compile_options(adlib PRIVATE /W4 /wd4100 /fp:precise) +else() + target_compile_options(adlib PRIVATE -Wall -Wextra -Wno-unused-parameter -ffp-contract=off -fno-fast-math) + if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64" AND NOT EMSCRIPTEN) + target_compile_options(adlib PRIVATE -mfpmath=sse -msse2) + endif() endif() set_target_properties(adlib PROPERTIES VERSION ${PROJECT_VERSION} EXPORT_NAME adlib) @@ -59,7 +62,11 @@ if(ADLIB_BUILD_TOOLS) src/tools/trace.cpp) add_library(adlib::tools ALIAS adlib_tools) target_link_libraries(adlib_tools PUBLIC adlib) - target_compile_options(adlib_tools PRIVATE -Wall -Wextra -Wno-unused-parameter) + if(MSVC) + target_compile_options(adlib_tools PRIVATE /W4 /wd4100) + else() + target_compile_options(adlib_tools PRIVATE -Wall -Wextra -Wno-unused-parameter) + endif() set_target_properties(adlib_tools PROPERTIES EXPORT_NAME tools) add_executable(adlibc tools/adlibc.cpp) diff --git a/src/compiler/symbols.cpp b/src/compiler/symbols.cpp index 4d5ca3a..e4750b1 100644 --- a/src/compiler/symbols.cpp +++ b/src/compiler/symbols.cpp @@ -1,6 +1,6 @@ // CPlanCompiler_ctor (0x487790) tables and CPlanCompiler_LoadSymbols (0x48a240), emulated. #include -#include +#include #include #include #include @@ -31,23 +31,21 @@ const CompilerKeyword kKeywordTable[] = { bool readFileCI(const std::string &dir, const std::string &name, std::string &out) { // Case-insensitive lookup of `name` (may contain one '/' level) under dir. std::string d = dir, n = name; + auto findCI = [](const std::string &in, const std::string &want) { + std::error_code ec; + for (const auto &e : std::filesystem::directory_iterator(in, ec)) { + const std::string fileName = e.path().filename().string(); + if (msvcStricmp(fileName.c_str(), want.c_str()) == 0) return fileName; + } + return std::string(); + }; size_t slash = n.find('/'); if (slash != std::string::npos) { - std::string sub; - DIR *h = opendir(d.c_str()); - if (!h) return false; - while (dirent *e = readdir(h)) - if (msvcStricmp(e->d_name, n.substr(0, slash).c_str()) == 0) { sub = e->d_name; break; } - closedir(h); + std::string sub = findCI(d, n.substr(0, slash)); if (sub.empty()) return false; return readFileCI(d + "/" + sub, n.substr(slash + 1), out); } - DIR *h = opendir(d.c_str()); - if (!h) return false; - std::string found; - while (dirent *e = readdir(h)) - if (msvcStricmp(e->d_name, n.c_str()) == 0) { found = e->d_name; break; } - closedir(h); + std::string found = findCI(d, n); if (found.empty()) return false; std::ifstream f(d + "/" + found, std::ios::binary); if (!f) return false; diff --git a/src/runtime.cpp b/src/runtime.cpp index f3de583..549e5fd 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -16,7 +16,9 @@ struct PlanError : std::runtime_error { using std::runtime_error::runtime_error; }; +#if defined(__GNUC__) std::string fmt(const char *f, ...) __attribute__((format(printf, 1, 2))); +#endif std::string fmt(const char *f, ...) { char buf[512]; va_list ap; diff --git a/tests/adlibc_test.cpp b/tests/adlibc_test.cpp index a7c2a9a..3cf4bdd 100644 --- a/tests/adlibc_test.cpp +++ b/tests/adlibc_test.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include @@ -41,12 +41,10 @@ bool readFile(const std::string &p, std::string &out) { } std::vector listDir(const std::string &d, const std::string &ext) { std::vector v; - if (DIR *h = opendir(d.c_str())) { - while (dirent *e = readdir(h)) { - std::string n = e->d_name; - if (n.size() > ext.size() && n.compare(n.size() - ext.size(), ext.size(), ext) == 0) v.push_back(n); - } - closedir(h); + std::error_code ec; + for (const auto &e : std::filesystem::directory_iterator(d, ec)) { + std::string n = e.path().filename().string(); + if (n.size() > ext.size() && n.compare(n.size() - ext.size(), ext.size(), ext) == 0) v.push_back(n); } std::sort(v.begin(), v.end()); return v; diff --git a/tools/adlibc.cpp b/tools/adlibc.cpp index 474e88a..419ec02 100644 --- a/tools/adlibc.cpp +++ b/tools/adlibc.cpp @@ -5,7 +5,7 @@ // [--compat=adlib|adlib1996] [--plans-dir DIR] [--strict] [--Werror] [-o out.pbn] [-q] file.txt #include #include -#include +#include #include #include #include @@ -58,12 +58,12 @@ std::string lower(std::string s) { } std::optional findPlan(const std::string &dir, const std::string &name) { - DIR *h = opendir(dir.empty() ? "." : dir.c_str()); - if (!h) return std::nullopt; std::string want = lower(name + ".txt"), found; - while (dirent *e = readdir(h)) - if (lower(e->d_name) == want) { found = e->d_name; break; } - closedir(h); + std::error_code ec; + for (const auto &e : std::filesystem::directory_iterator(dir.empty() ? "." : dir, ec)) { + const std::string fileName = e.path().filename().string(); + if (lower(fileName) == want) { found = fileName; break; } + } if (found.empty()) return std::nullopt; std::string text; if (!readFile((dir.empty() ? "." : dir) + "/" + found, text)) return std::nullopt; From 29aa4161f98dfcd49d1e5c072a67b898f70a1092 Mon Sep 17 00:00:00 2001 From: Zach Toogood Date: Mon, 19 Oct 2026 11:08:57 +0100 Subject: [PATCH 2/2] CI: Add MSVC job --- .github/workflows/ci.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c65f162..61005c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,18 @@ jobs: cmake --build consumer/build ./consumer/build/consumer + windows: + name: build and test (MSVC) + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - name: Configure + run: cmake -S . -B build + - name: Build + run: cmake --build build --config Release + - name: Tests + run: ctest --test-dir build -C Release --output-on-failure + emscripten: name: library (Emscripten) runs-on: ubuntu-latest