Skip to content

cmake: ease Windows clang and custom ROCm builds from source - #16974

Open
tenderdeve wants to merge 1 commit into
ollama:mainfrom
tenderdeve:feat/16889-windows-hip-build-ergonomics
Open

tenderdeve wants to merge 1 commit into
ollama:mainfrom
tenderdeve:feat/16889-windows-hip-build-ergonomics

Conversation

@tenderdeve

Copy link
Copy Markdown

Fixes #16889

Two build-from-source friction points reported on Windows + clang / custom ROCm toolchains, both fixed with gated, opt-in CMake changes.

1. Auto-detect the Windows Resource Compiler. With clang as the C/C++ compiler (instead of MSVC), CMake can't find rc.exe on its own, so the build fails unless you pass a version-specific -DCMAKE_RC_COMPILER=".../Windows Kits/10/bin/10.0.xxxxx.0/x64/rc.exe". The top-level CMake now globs the installed Windows SDKs and picks the newest rc.exe automatically. Runs only on Windows, only when CMAKE_RC_COMPILER isn't already set — globbing avoids hardcoding SDK versions.

2. OLLAMA_HIP_DEVICE_LIB_PATH cache variable. Custom ROCm layouts (TheRock, self-built, nightly) keep the device bitcode at e.g. <rocm>/lib/llvm/amdgcn/bitcode instead of <rocm>/amdgcn/bitcode, requiring --rocm-device-lib-path. Today that means patching the vendored ggml-hip CMake. The new opt-in cache var injects the flag into the existing rocm_v* HIP block, routed through CXX flags on Windows (where ggml-hip builds with CXX_IS_HIPCC, so CMAKE_HIP_FLAGS is ignored) and HIP flags elsewhere.

Both default to no-ops and are gated on WIN32 / the cache var being set, so non-Windows and standard ROCm builds are unchanged.

Verification: I don't have a Windows/ROCm box, so I validated the CMake logic in isolation rather than a full Windows build — the SDK glob+sort picks the newest rc.exe from a fake SDK tree, the $ENV{ProgramFiles(x86)} escaping parses, and the device-lib-path flag routes to CXX flags on Windows. A configure on macOS executes the new top-level block cleanly. Would appreciate a maintainer with a Windows + clang / custom-ROCm setup confirming the end-to-end build.

Two friction points when building from source on Windows with clang and
with non-standard ROCm toolchains:

- With clang as the C/C++ compiler, CMake can't locate the Windows
  Resource Compiler (rc.exe) and the build fails unless the user passes a
  version-specific -DCMAKE_RC_COMPILER. Search the installed Windows SDKs
  and select the newest rc.exe automatically. Only runs on Windows when
  CMAKE_RC_COMPILER isn't already set.

- Custom ROCm layouts (TheRock, self-built, nightly) keep the device
  bitcode at a non-standard path and need --rocm-device-lib-path, which
  currently means patching the vendored ggml-hip CMake. Add an opt-in
  OLLAMA_HIP_DEVICE_LIB_PATH cache variable that injects the flag, routed
  through CXX flags on Windows where ggml-hip builds with CXX_IS_HIPCC.

Both changes are gated and default to no-ops, so non-Windows and default
ROCm builds are unaffected.

This branch has not been deployed

No deployments
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.

Suggestion: Improve Windows + HIP/clang build ergonomics

1 participant