Skip to content

fix: port POSIX-only files to Windows for HIP builds#366

Closed
Sprize1 wants to merge 1 commit into
Luce-Org:mainfrom
Sprize1:fix/windows-hip-build
Closed

fix: port POSIX-only files to Windows for HIP builds#366
Sprize1 wants to merge 1 commit into
Luce-Org:mainfrom
Sprize1:fix/windows-hip-build

Conversation

@Sprize1

@Sprize1 Sprize1 commented Jun 10, 2026

Copy link
Copy Markdown

Problem

The HIP backend fails to compile on Windows native because several source files use POSIX-only APIs (mmap, dirent, mkstemps, readlink, POSIX sockets) without Windows fallbacks.

Solution

Add cross-platform support behind #if defined(_WIN32), using:

  • GgufMmap (existing project RAII class) instead of raw mmap
  • std::filesystem instead of dirent/stat
  • Winsock2 instead of POSIX sockets (http_server)
  • _putenv_s instead of setenv
  • _write/_read in io_utils
  • ws2_32 + BUILD_SHARED_LIBS=OFF in CMakeLists

Files changed (13)

File Change
gemma4_loader.cpp Gemma4Mmap → cross-platform (CreateFileMappingA/MapViewOfFile)
laguna_backend.cpp ::mmap → GgufMmap RAII
qwen35moe_backend.cpp 2x mmap blocks → GgufMmap
qwen35_backend.cpp open_dflash_floor_log → Windows fopen branch
io_utils.h write_exact_fd/read_exact_fd → _write/_read on Windows
daemon_loop.cpp mkstemps → std::filesystem temp dir
disk_prefix_cache.cpp dirent/stat → std::filesystem
model_card.cpp readlink(/proc/self/exe) → GetModuleFileNameA
server_main.cpp setenv → _putenv_s
http_server.cpp POSIX sockets → Winsock2 (helpers, casts)
http_server.h Guard unistd.h
CMakeLists.txt pthread conditional, ws2_32, BUILD_SHARED_LIBS=OFF

No functional change on Linux/macOS

All Windows-specific code is behind #if defined(_WIN32). POSIX paths are unchanged.

Tested

  • dflash_server.exe builds cleanly (91 MB)
  • test_dflash.exe builds cleanly (89 MB)
  • Platform: Windows 11 + ROCm 7.1 HIP + gfx1102 (RX 7600 XT 16GB)

🤖 Generated with Claude Code

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 13 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="server/src/server/server_main.cpp">

<violation number="1" location="server/src/server/server_main.cpp:37">
P1: Windows setenv shim ignores overwrite=0 parameter, silently overwriting existing environment variables on Windows instead of preserving them as POSIX requires.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

#include <vector>

#ifdef _WIN32
#define setenv(name, value, overwrite) _putenv_s(name, value)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Windows setenv shim ignores overwrite=0 parameter, silently overwriting existing environment variables on Windows instead of preserving them as POSIX requires.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At server/src/server/server_main.cpp, line 37:

<comment>Windows setenv shim ignores overwrite=0 parameter, silently overwriting existing environment variables on Windows instead of preserving them as POSIX requires.</comment>

<file context>
@@ -33,6 +33,11 @@
 #include <vector>
 
+#ifdef _WIN32
+#define setenv(name, value, overwrite) _putenv_s(name, value)
+#define unsetenv(name) _putenv_s(name, "")
+#endif
</file context>

- Replace raw mmap/munmap with GgufMmap (cross-platform RAII) in
  gemma4_loader, laguna_backend, qwen35moe_backend, test_dflash
- Replace dirent.h/stat with std::filesystem in disk_prefix_cache,
  model_card
- Add Windows implementations for write_exact_fd/read_exact_fd in
  io_utils.h
- Guard open_dflash_floor_log POSIX path with _WIN32 in qwen35_backend
- Replace mkstemps with std::filesystem temp dir in daemon_loop
- Port http_server socket/POSIX layer to Winsock2 (winsock2.h,
  WSAPoll, closesocket, ioctlsocket helpers)
- Guard unistd.h in http_server.h, add setenv fallback in server_main
- Make pthread link conditional (NOT WIN32), add ws2_32 on Windows,
  set BUILD_SHARED_LIBS=OFF for ggml symbol visibility
- All Windows-only code behind #if defined(_WIN32), no functional
  change on Linux/macOS

Tested: dflash_server.exe + test_dflash.exe build cleanly on
Windows 11 + ROCm 7.1 HIP + gfx1102 (RX 7600 XT).

Co-Authored-By: Claude Code <noreply@anthropic.com>
@Sprize1 Sprize1 force-pushed the fix/windows-hip-build branch from 634a173 to 0514c95 Compare June 10, 2026 20:42
@Sprize1 Sprize1 closed this Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant