Add Windows build support via MSYS2 and fix platform-specific code

Guard X11 display crash handler with __linux__, add Windows GlobalMemoryStatusEx
path in memory_monitor, guard warden cache paths with APPDATA on Windows, and
make pkg-config optional in CMakeLists with a find_library fallback. Add Windows
x86-64 CI job using MSYS2 MINGW64 to the build workflow.
This commit is contained in:
Kelsi 2026-02-18 17:38:08 -08:00
parent 02fd0166e9
commit cb01821d89
6 changed files with 125 additions and 16 deletions

View file

@ -3,11 +3,16 @@
#include <fstream>
#include <string>
#include <sstream>
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/sysinfo.h>
#endif
namespace wowee {
namespace core {
#ifndef _WIN32
namespace {
size_t readMemAvailableBytesFromProc() {
std::ifstream meminfo("/proc/meminfo");
@ -26,6 +31,7 @@ size_t readMemAvailableBytesFromProc() {
return 0;
}
} // namespace
#endif
MemoryMonitor& MemoryMonitor::getInstance() {
static MemoryMonitor instance;
@ -33,6 +39,16 @@ MemoryMonitor& MemoryMonitor::getInstance() {
}
void MemoryMonitor::initialize() {
#ifdef _WIN32
ULONGLONG totalKB = 0;
if (GetPhysicallyInstalledSystemMemory(&totalKB)) {
totalRAM_ = static_cast<size_t>(totalKB) * 1024ull;
LOG_INFO("System RAM detected: ", totalRAM_ / (1024 * 1024 * 1024), " GB");
} else {
totalRAM_ = 16ull * 1024 * 1024 * 1024;
LOG_WARNING("Could not detect system RAM, assuming 16GB");
}
#else
struct sysinfo info;
if (sysinfo(&info) == 0) {
totalRAM_ = static_cast<size_t>(info.totalram) * info.mem_unit;
@ -42,9 +58,18 @@ void MemoryMonitor::initialize() {
totalRAM_ = 16ull * 1024 * 1024 * 1024;
LOG_WARNING("Could not detect system RAM, assuming 16GB");
}
#endif
}
size_t MemoryMonitor::getAvailableRAM() const {
#ifdef _WIN32
MEMORYSTATUSEX status;
status.dwLength = sizeof(status);
if (GlobalMemoryStatusEx(&status)) {
return static_cast<size_t>(status.ullAvailPhys);
}
return totalRAM_ / 2;
#else
// Best source on Linux for reclaimable memory headroom.
if (size_t memAvailable = readMemAvailableBytesFromProc(); memAvailable > 0) {
return memAvailable;
@ -59,6 +84,7 @@ size_t MemoryMonitor::getAvailableRAM() const {
return (totalRAM_ > 0 && available > totalRAM_) ? totalRAM_ : available;
}
return totalRAM_ / 2; // Fallback: assume 50% available
#endif
}
size_t MemoryMonitor::getRecommendedCacheBudget() const {