Skip to content

Commit 58f244e

Browse files
committed
chore: winfix
1 parent 57c8ba9 commit 58f244e

File tree

11 files changed

+775
-38
lines changed

11 files changed

+775
-38
lines changed

Makefile

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ help:
1010
@echo " make install - Install in development mode"
1111
@echo ""
1212
@echo "Development:"
13-
@echo " make test - Run tests"
14-
@echo " make benchmark - Run benchmarks"
15-
@echo " make lint - Run linters (ruff, mypy)"
16-
@echo " make format - Format code (ruff)"
13+
@echo " make test - Run tests"
14+
@echo " make benchmark - Run benchmarks"
15+
@echo " make lint - Run linters (ruff, mypy)"
16+
@echo " make format - Format code (ruff)"
17+
@echo " make check-windows - Quick Windows compatibility check (no Docker)"
1718
@echo ""
1819
@echo "Docker (CI Testing):"
19-
@echo " make docker-build - Build Docker test container (mimics CI)"
20-
@echo " make docker-test - Run tests in Docker"
21-
@echo " make docker-shell - Open shell in Docker for debugging"
20+
@echo " make docker-build - Build Docker test container (mimics CI)"
21+
@echo " make docker-test - Run tests in Docker"
22+
@echo " make docker-shell - Open shell in Docker for debugging"
23+
@echo " make docker-windows-quick - Quick Windows API check (works on ARM64/M1/M2)"
24+
@echo " make docker-windows - Full Windows test (requires x86_64 host)"
25+
@echo " make docker-win-shell - Open Windows test shell for debugging"
2226
@echo ""
2327
@echo "Cleanup:"
2428
@echo " make clean - Remove build artifacts"
@@ -87,10 +91,15 @@ rebuild: clean setup build
8791
check: lint test
8892
@echo "All checks passed!"
8993

94+
# Quick Windows compatibility check (no Docker needed)
95+
check-windows:
96+
@echo "Running Windows compatibility check..."
97+
@./scripts/check_windows_compat.sh
98+
9099
# Docker targets for CI testing
91100
docker-build:
92101
@echo "Building Docker test container (mimics GitHub Actions)..."
93-
docker build -f Dockerfile.test -t httpmorph-test .
102+
docker build -f docker/Dockerfile.test -t httpmorph-test .
94103

95104
docker-test: docker-build
96105
@echo "Running tests in Docker container..."
@@ -99,3 +108,24 @@ docker-test: docker-build
99108
docker-shell:
100109
@echo "Opening shell in Docker container for debugging..."
101110
docker run --rm -it -v $(PWD):/workspace httpmorph-test bash
111+
112+
# Windows compatibility testing with MinGW cross-compile
113+
docker-windows:
114+
@echo "Testing Windows compatibility with MinGW-w64..."
115+
@echo "Note: This tests API compatibility, not full MSVC behavior."
116+
@echo "Note: Requires x86_64 host (may fail on ARM64/Apple Silicon due to vcpkg limitations)"
117+
docker-compose -f docker/docker-compose.windows-test.yml up windows-mingw
118+
119+
# Quick Windows syntax check (works on ARM64/Apple Silicon)
120+
docker-windows-quick:
121+
@echo "Quick Windows API compatibility check..."
122+
docker build -f docker/Dockerfile.windows-quick -t httpmorph-windows-quick .
123+
docker run --rm httpmorph-windows-quick
124+
125+
docker-win-shell:
126+
@echo "Opening Windows test shell (MinGW cross-compile environment)..."
127+
docker-compose -f docker/docker-compose.windows-test.yml run windows-shell
128+
129+
docker-windows-build:
130+
@echo "Building Windows test image..."
131+
docker build -f docker/Dockerfile.windows-mingw -t httpmorph-windows-test .
File renamed without changes.

docker/Dockerfile.windows-mingw

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
# Windows Cross-Compilation Test using MinGW-w64
2+
# Tests Windows API compatibility and compilation on Linux/macOS
3+
#
4+
# This simulates Windows builds by:
5+
# 1. Using MinGW-w64 cross-compiler (x86_64-w64-mingw32-gcc)
6+
# 2. Testing all Windows-specific code paths
7+
# 3. Validating Windows API usage (Winsock2, Windows.h, etc.)
8+
9+
FROM ubuntu:22.04
10+
11+
ENV DEBIAN_FRONTEND=noninteractive
12+
13+
# Install MinGW-w64 and build tools
14+
RUN apt-get update && apt-get install -y \
15+
gcc-mingw-w64-x86-64 \
16+
g++-mingw-w64-x86-64 \
17+
mingw-w64-tools \
18+
cmake \
19+
ninja-build \
20+
git \
21+
curl \
22+
wget \
23+
zip \
24+
unzip \
25+
tar \
26+
python3.11 \
27+
python3.11-dev \
28+
python3-pip \
29+
pkg-config \
30+
autoconf \
31+
automake \
32+
libtool \
33+
make \
34+
&& rm -rf /var/lib/apt/lists/*
35+
36+
# Set Python 3.11 as default
37+
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 && \
38+
update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1
39+
40+
# Upgrade pip and install build tools
41+
RUN python3 -m pip install --upgrade pip setuptools wheel cython pytest
42+
43+
# Install vcpkg for Windows dependencies (with retry logic for network issues)
44+
ENV VCPKG_ROOT=/opt/vcpkg
45+
RUN git clone --depth 1 --single-branch https://github.com/microsoft/vcpkg.git ${VCPKG_ROOT} || \
46+
(sleep 5 && git clone --depth 1 --single-branch https://github.com/microsoft/vcpkg.git ${VCPKG_ROOT}) || \
47+
(sleep 10 && git clone --depth 1 --single-branch https://github.com/microsoft/vcpkg.git ${VCPKG_ROOT})
48+
RUN cd ${VCPKG_ROOT} && ./bootstrap-vcpkg.sh
49+
50+
# Install Windows dependencies using vcpkg with x64-mingw-static triplet
51+
RUN ${VCPKG_ROOT}/vcpkg install \
52+
openssl:x64-mingw-static \
53+
nghttp2:x64-mingw-static \
54+
zlib:x64-mingw-static \
55+
--clean-after-build
56+
57+
# Set environment for MinGW cross-compilation
58+
ENV VCPKG_DEFAULT_TRIPLET=x64-mingw-static
59+
ENV MINGW_PREFIX=/usr/x86_64-w64-mingw32
60+
ENV CC=x86_64-w64-mingw32-gcc
61+
ENV CXX=x86_64-w64-mingw32-g++
62+
ENV AR=x86_64-w64-mingw32-ar
63+
ENV RANLIB=x86_64-w64-mingw32-ranlib
64+
ENV PKG_CONFIG_PATH=${VCPKG_ROOT}/installed/x64-mingw-static/lib/pkgconfig
65+
66+
WORKDIR /workspace
67+
68+
# Copy project files
69+
COPY . .
70+
71+
# Create test script
72+
RUN cat > /usr/local/bin/test-windows-build << 'EOF'
73+
#!/bin/bash
74+
set -e
75+
76+
echo "╔════════════════════════════════════════════════════════════════╗"
77+
echo "║ Windows Build Test (MinGW-w64 Cross-Compiler) ║"
78+
echo "╚════════════════════════════════════════════════════════════════╝"
79+
echo ""
80+
81+
# Test 1: Check if Windows headers are properly guarded
82+
echo "📋 Test 1: Checking Windows-specific code guards..."
83+
if grep -r "#ifdef _WIN32" src/core/*.c | grep -q .; then
84+
echo " ✅ Found Windows-specific guards"
85+
else
86+
echo " ⚠️ No Windows guards found"
87+
fi
88+
89+
# Test 2: Compile check for Windows-specific files
90+
echo ""
91+
echo "📋 Test 2: Testing Windows API compatibility..."
92+
cat > /tmp/test_windows.c << 'CTEST'
93+
#define _WIN32 1
94+
#include <winsock2.h>
95+
#include <ws2tcpip.h>
96+
#include <windows.h>
97+
#include <stdio.h>
98+
99+
int main() {
100+
WSADATA wsaData;
101+
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
102+
return 1;
103+
}
104+
105+
SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
106+
if (sock == INVALID_SOCKET) {
107+
WSACleanup();
108+
return 1;
109+
}
110+
111+
closesocket(sock);
112+
WSACleanup();
113+
114+
printf("Windows API test passed!\n");
115+
return 0;
116+
}
117+
CTEST
118+
119+
if x86_64-w64-mingw32-gcc /tmp/test_windows.c -o /tmp/test_windows.exe -lws2_32 2>/dev/null; then
120+
echo " ✅ Windows API headers compile successfully"
121+
else
122+
echo " ❌ Windows API compilation failed"
123+
exit 1
124+
fi
125+
126+
# Test 3: Syntax check of source files with Windows defines
127+
echo ""
128+
echo "📋 Test 3: Syntax checking httpmorph.c with Windows defines..."
129+
x86_64-w64-mingw32-gcc -D_WIN32 -fsyntax-only \
130+
-I${VCPKG_ROOT}/installed/x64-mingw-static/include \
131+
-Iinclude -Isrc/core -Isrc/tls \
132+
src/core/httpmorph.c \
133+
-Wno-deprecated-declarations 2>&1 | head -20
134+
135+
if [ ${PIPESTATUS[0]} -eq 0 ]; then
136+
echo " ✅ httpmorph.c syntax check passed"
137+
else
138+
echo " ⚠️ Syntax warnings found (check above)"
139+
fi
140+
141+
# Test 4: Check for Windows-incompatible functions
142+
echo ""
143+
echo "📋 Test 4: Checking for Windows-incompatible code..."
144+
INCOMPATIBLE_FOUND=0
145+
146+
if grep -r "fork\|execve\|pipe2\|epoll\|kqueue" src/core/*.c | grep -v "ifdef" | grep -v "//"; then
147+
echo " ⚠️ Found potentially incompatible functions (check if properly guarded)"
148+
INCOMPATIBLE_FOUND=1
149+
else
150+
echo " ✅ No unguarded incompatible functions"
151+
fi
152+
153+
# Test 5: Verify all Windows-specific replacements
154+
echo ""
155+
echo "📋 Test 5: Verifying Windows API replacements..."
156+
MISSING=0
157+
158+
for file in src/core/*.c; do
159+
if grep -q "_WIN32" "$file"; then
160+
# Check for required Windows headers
161+
if ! grep -q "winsock2.h" "$file"; then
162+
echo " ⚠️ $file: Missing winsock2.h"
163+
MISSING=1
164+
fi
165+
166+
# Check for WSAStartup if using sockets
167+
if grep -q "socket(" "$file" && ! grep -q "WSAStartup\|Already initialized" "$file" 2>/dev/null; then
168+
echo " ℹ️ $file: Check if WSAStartup is called"
169+
fi
170+
fi
171+
done
172+
173+
if [ $MISSING -eq 0 ]; then
174+
echo " ✅ All Windows headers present"
175+
fi
176+
177+
# Test 6: Check for proper printf format specifiers
178+
echo ""
179+
echo "📋 Test 6: Checking printf format specifiers..."
180+
if grep -r "%lu.*uint64_t\|%ld.*uint64_t" src/core/*.c | grep -v "PRIu64\|PRId64"; then
181+
echo " ⚠️ Found potentially incorrect format specifiers for uint64_t"
182+
echo " Use PRIu64 from <inttypes.h> for portability"
183+
else
184+
echo " ✅ Printf format specifiers look correct"
185+
fi
186+
187+
# Summary
188+
echo ""
189+
echo "╔════════════════════════════════════════════════════════════════╗"
190+
echo "║ Test Summary ║"
191+
echo "╚════════════════════════════════════════════════════════════════╝"
192+
echo ""
193+
if [ $INCOMPATIBLE_FOUND -eq 0 ] && [ $MISSING -eq 0 ]; then
194+
echo "✅ All Windows compatibility checks passed!"
195+
echo ""
196+
echo "Note: This tests API compatibility using MinGW cross-compiler."
197+
echo "For full MSVC testing, use GitHub Actions Windows runner."
198+
exit 0
199+
else
200+
echo "⚠️ Some warnings found. Review the output above."
201+
exit 0
202+
fi
203+
EOF
204+
205+
RUN chmod +x /usr/local/bin/test-windows-build
206+
207+
# Default command
208+
CMD ["test-windows-build"]

0 commit comments

Comments
 (0)