Skip to content

fix: Windows (MSVC) native and CUDA builds - #1

Closed
smanaton wants to merge 2 commits into
Apothic-AI:masterfrom
smanaton:windows-fixes
Closed

fix: Windows (MSVC) native and CUDA builds#1
smanaton wants to merge 2 commits into
Apothic-AI:masterfrom
smanaton:windows-fixes

Conversation

@smanaton

@smanaton smanaton commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Three build.rs fixes — each a hard build/link failure on Windows:

  1. Verbatim paths: canonicalize() returns \\?\... paths that MSVC cl.exe cannot use in -I dirs. Strip carefully:
    • \\?\C:\fooC:\foo
    • \\?\UNC\server\share\\server\share
  2. advapi32: link on Windows for ggml-cpu registry-based CPU detection.
  3. CUDA link flags: previously Linux-only; emit Windows import libs (cudart, cublas, cublasLt, cuda) plus lib\x64 search path when CUDA is enabled.

Test plan

  • Validated on Windows 11 (MSVC, CUDA 12.2, RTX 4090) against mainline llama.cpp: CPU and CUDA builds link and run.
  • CPU vs GPU eval consistency on Bonsai GGUF lab runs.
  • Optional: verify UNC checkout path strip on a network share.

Notes

Fork staging: smanaton#1
Recommend merging before the prefer-mainline-llama PR.

Three build-script fixes, each a hard build failure on Windows:

- canonicalize_llama_cpp_dir returned \?\-prefixed verbatim paths, which
  cl.exe cannot resolve in -I include dirs (fatal error C1083 on
  ggml-backend.h). Strip the verbatim prefix after canonicalizing.
- The target_os link-lib match had no windows arm; ggml-cpu's CPU detection
  calls RegOpenKeyExA/RegQueryValueExA/RegCloseKey, leaving three unresolved
  __imp_Reg* externals at link time. Link advapi32.
- emit_cuda_link_flags was Linux-only and its lib set (cudart_static/culibos/
  dl/rt/pthread) is Unix-specific, so --features cuda compiled every kernel
  then failed to link. Add a Windows variant emitting the cudart/cublas/
  cublasLt/cuda import libs plus the lib\x64 search path, which
  cuda_library_dir misses when the bare lib parent exists.

Validated on Windows 11 (MSVC 14.51, CUDA 12.2, RTX 4090) against mainline
llama.cpp b10054: CPU and CUDA builds link and run; CPU vs GPU eval results
on Bonsai-27B-Q1_0 are identical.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 17, 2026 18:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The job was not started because the account is locked due to a billing issue.

canonicalize() can return \\?\UNC\server\share\...; stripping only \\?\ left
a relative UNC\... path. Map that form to \\server\share\... and plain
\\?\C:\... to C:\... so MSVC/CMake include paths stay absolute.
@smanaton smanaton changed the title Fix Windows (MSVC) native and CUDA builds fix: Windows (MSVC) native and CUDA builds Jul 19, 2026

@bitnom bitnom 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.

Please address these before merge:

  1. build.rs:255-258 unconditionally links cublasLt on Windows. Current llama.cpp only links CUDA::cudart and CUDA::cublas for the Windows static backend, and CUDA 10.0 does not provide cuBLASLt. This can cause LNK1104 on an otherwise supported toolkit. Omit the Windows cublasLt link or gate it on a verified toolkit capability/version.

  2. build.rs:246-248 assumes an x64 subdirectory whenever the discovered CUDA directory has one. The build script already receives the target architecture, but this path is not architecture-aware and can select the wrong import-library directory for Windows ARM64. Either select the directory from the target architecture or explicitly reject unsupported Windows CUDA targets.

  3. Please add focused automated coverage for the Windows path/link decisions, including CPU-only MSVC and CUDA-enabled MSVC, and at least the path normalization cases. The current validation is a single local x64 environment and there are no CI checks on this PR.

The advapi32 addition and drive/UNC normalization are directionally correct, but these issues affect whether the foundational build script works across supported Windows/CUDA environments.

@bitnom

bitnom commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Superseded by draft replacement PR #3: #3

The corrected implementation is on the upstream windows-fixes feature branch, including focused tests and a Linux/Windows CI matrix. This fork branch cannot be updated from the maintainer account, so the original PR will be closed to keep the merge candidates unambiguous.

@bitnom

bitnom commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded by draft PR #3. The corrected work remains on the windows-fixes feature branch pending multi-platform validation.

@bitnom bitnom closed this Aug 28, 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.

3 participants