Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

Fix cbm_mkdtemp for Windows, add Wine test execution to Docker

Martin Vogeld1632ec7e1a7
diff --git a/src/foundation/compat.c b/src/foundation/compat.c
index 1c4765844..ce8d17f05 100644
--- a/src/foundation/compat.c
+++ b/src/foundation/compat.c
@@ -49,6 +49,19 @@ char *cbm_strcasestr(const char *haystack, const char *needle) {
#ifdef _WIN32
#include <direct.h>
char *cbm_mkdtemp(char *tmpl) {
+ /* On Windows, /tmp doesn't exist. Replace /tmp/ prefix with %TEMP%\ */
+ if (strncmp(tmpl, "/tmp/", 5) == 0) {
+ const char *tmp = getenv("TEMP");
+ if (!tmp)
+ tmp = getenv("TMP");
+ if (!tmp)
+ tmp = ".";
+ char buf[512];
+ snprintf(buf, sizeof(buf), "%s\\%s", tmp, tmpl + 5);
+ /* Copy back (template buffer must be large enough) */
+ size_t len = strlen(buf);
+ memcpy(tmpl, buf, len + 1);
+ }
/* _mktemp modifies template in place, then we mkdir */
if (!_mktemp(tmpl))
return NULL;
diff --git a/test-infrastructure/Dockerfile.mingw b/test-infrastructure/Dockerfile.mingw
index fbe9acd01..a7386f6dc 100644
--- a/test-infrastructure/Dockerfile.mingw
+++ b/test-infrastructure/Dockerfile.mingw
@@ -1,6 +1,6 @@
# Cross-compile AND run Windows tests locally using llvm-mingw + Wine.
#
-# llvm-mingw: LLVM/Clang-based MinGW toolchain with ASan support
+# llvm-mingw: LLVM/Clang-based MinGW toolchain
# Wine: runs the resulting .exe for actual test execution
#
# Usage:
@@ -9,13 +9,13 @@
FROM mstorsjo/llvm-mingw:latest
-# Install Wine for running Windows executables
-RUN apt-get update && apt-get install -y --no-install-recommends \
+# Install Wine + binfmt support for transparent .exe execution
+RUN dpkg --add-architecture i386 && \
+ apt-get update && apt-get install -y --no-install-recommends \
wine64 curl zstd \
&& rm -rf /var/lib/apt/lists/*
# Install zlib into the llvm-mingw sysroot (from MSYS2 CLANG64 repo)
-# Extract to temp dir first, then copy — avoids overwriting existing sysroot files
RUN mkdir -p /tmp/zlib-pkg && \
curl -sL "https://mirror.msys2.org/mingw/clang64/mingw-w64-clang-x86_64-zlib-1.3.1-1-any.pkg.tar.zst" \
| zstd -d | tar xf - -C /tmp/zlib-pkg && \
@@ -23,6 +23,24 @@ RUN mkdir -p /tmp/zlib-pkg && \
cp -rn /tmp/zlib-pkg/clang64/lib/* /opt/llvm-mingw/x86_64-w64-mingw32/lib/ && \
rm -rf /tmp/zlib-pkg
+# Add Wine to PATH (Ubuntu noble puts it in /usr/lib/wine/)
+ENV PATH="/usr/lib/wine:${PATH}"
+
+# Verify all tools are installed
+RUN echo "=== Tool check ===" && \
+ x86_64-w64-mingw32-clang --version | head -1 && \
+ x86_64-w64-mingw32-clang++ --version | head -1 && \
+ make --version | head -1 && \
+ ls /opt/llvm-mingw/x86_64-w64-mingw32/include/zlib.h && \
+ (wine64 --version 2>/dev/null || echo "WARN: wine64 not on PATH, checking alternatives...") && \
+ (which wine64 || which wine || find / -name "wine64" -type f 2>/dev/null | head -1 || echo "ERROR: wine not found") && \
+ echo "=== All tools OK ==="
+
+# Pre-init Wine to avoid first-run prompts during test
+RUN WINEDEBUG=-all wine64 wineboot --init 2>/dev/null || \
+ WINEDEBUG=-all wine wineboot --init 2>/dev/null || \
+ echo "WARN: Wine init skipped"
+
WORKDIR /src
ENTRYPOINT ["/bin/bash", "-c"]
@@ -32,5 +50,4 @@ CMD ["make -j4 -f Makefile.cbm clean-c && \
make -j4 -f Makefile.cbm cbm \
CC=x86_64-w64-mingw32-clang \
CXX=x86_64-w64-mingw32-clang++ \
- 'WIN32_LIBS=-lws2_32 -lpsapi -Wl,--allow-multiple-definition' \
&& echo '=== Windows cross-compile: OK ==='"]
diff --git a/test-infrastructure/docker-compose.yml b/test-infrastructure/docker-compose.yml
index 6f5bb0985..3aed3ebbb 100644
--- a/test-infrastructure/docker-compose.yml
+++ b/test-infrastructure/docker-compose.yml
@@ -65,12 +65,12 @@ services:
- ..:/src
command: >-
make -j4 -f Makefile.cbm clean-c &&
- make -j4 -f Makefile.cbm test
+ make -j4 -f Makefile.cbm build/c/test-runner
CC=x86_64-w64-mingw32-clang
- CXX=x86_64-w64-mingw32-clang++
- WIN32_LIBS='-lws2_32 -lpsapi'
- SANITIZE=
- && echo '=== Windows test: OK ==='
+ CXX=x86_64-w64-mingw32-clang++ &&
+ echo '=== Running tests under Wine ===' &&
+ WINEDEBUG=-all wine64 build/c/test-runner.exe &&
+ echo '=== Windows test: OK ==='
# ── Lint ────────────────────────────────────────────────────
lint: