Fix OCI build failure on Windows ARM64 with clang #49
+32
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The build fails on Windows ARM64 when using clang with OCI support enabled:
The issue occurs because the Go CGO-generated header file
liboci.huses MSVC-specific complex number types (_Fcomplexand_Dcomplex) when_MSC_VERis defined. While clang on Windows defines_MSC_VERfor compatibility, it doesn't support these MSVC-specific types.Solution
This PR adds a post-processing step to patch the generated
liboci.hheader file after Go builds it. The patch modifies the conditional compilation logic to detect__clang__and use C++ standardstd::complextypes instead of MSVC-specific types when compiling with clang.Changes:
common/CMakeLists.txt: Added commands to run the patch script after Go generates the headercommon/patch_liboci_header.cmake: New CMake script that performs the header patchingThe patch changes the header logic from:
To:
This ensures clang uses C++ standard complex types that it supports, while maintaining compatibility with native MSVC compilation.
Testing
Fixes the build error reported in the Windows ARM64 clang CI environment.
Original prompt
Fix this build:
[146/295] Linking CXX shared library bin\Release\llama.dll
clang++: warning: argument unused during compilation: '-fno-finite-math-only' [-Wunused-command-line-argument]
[147/295] Building CXX object examples/simple-chat/CMakeFiles/llama-simple-chat.dir/Release/simple-chat.cpp.obj
D:/a/llama.cpp/llama.cpp/examples/simple-chat/simple-chat.cpp:170:37: warning: 'strdup' is deprecated: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup. See online help for details. [-Wdeprecated-declarations]
170 | messages.push_back({"user", strdup(user.c_str())});
| ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\string.h:531:20: note: 'strdup' has been explicitly marked deprecated here
531 | Check_return _CRT_NONSTDC_DEPRECATE(_strdup)
| ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt.h:428:50: note: expanded from macro '_CRT_NONSTDC_DEPRECATE'
428 | #define _CRT_NONSTDC_DEPRECATE(_NewName) _CRT_DEPRECATE_TEXT(
| ^
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\vcruntime.h:358:47: note: expanded from macro '_CRT_DEPRECATE_TEXT'
358 | #define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
| ^
D:/a/llama.cpp/llama.cpp/examples/simple-chat/simple-chat.cpp:190:42: warning: 'strdup' is deprecated: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup. See online help for details. [-Wdeprecated-declarations]
190 | messages.push_back({"assistant", strdup(response.c_str())});
| ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\string.h:531:20: note: 'strdup' has been explicitly marked deprecated here
531 | Check_return _CRT_NONSTDC_DEPRECATE(_strdup)
| ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt.h:428:50: note: expanded from macro '_CRT_NONSTDC_DEPRECATE'
428 | #define _CRT_NONSTDC_DEPRECATE(_NewName) _CRT_DEPRECATE_TEXT(
| ^
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\vcruntime.h:358:47: note: expanded from macro '_CRT_DEPRECATE_TEXT'
358 | #define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
| ^
2 warnings generated.
[148/295] Linking CXX executable bin\Release\llama-gguf-hash.exe
clang++: warning: argument unused during compilation: '-fno-finite-math-only' [-Wunused-command-line-argument]
[149/295] Linking CXX shared library bin\Release\mtmd.dll
clang++: warning: argument unused during compilation: '-fno-finite-math-only' [-Wunused-command-line-argument]
[150/295] Linking C executable bin\Release\test-c.exe
clang: warning: argument unused during compilation: '-fno-finite-math-only' [-Wunused-command-line-argument]
[151/295] Linking CXX executable bin\Release\llama-simple.exe
clang++: warning: argument unused during compilation: '-fno-finite-math-only' [-Wunused-command-line-argument]
[152/295] Linking CXX executable bin\Release\llama-simple-chat.exe
clang++: warning: argument unused during compilation: '-fno-finite-math-only' [-Wunused-command-line-argument]
[153/295] Linking CXX executable bin\Release\llama-gguf.exe
clang++: warning: argument unused during compilation: '-fno-finite-math-only' [-Wunused-command-line-argument]
[154/295] Building OCI Go library
go: downloading github.com/google/go-containerregistry v0.20.6
go: downloading golang.org/x/term v0.36.0
go: downloading github.com/docker/cli v28.2.2+incompatible
go: downloading github.com/opencontainers/go-digest v1.0.0
go: downloading github.com/mitchellh/go-homedir v1.1.0
go: downloading golang.org/x/sync v0.15.0
go: downloading golang.org/x/sys v0.37.0
go: downloading github.com/docker/distribution v2.8.3+incompatible
go: downloading github.com/pkg/errors v0.9.1
go: downloading github.com/sirupsen/logrus v1.9.3
go: downloading github.com/opencontainers/image-spec v1.1.1
go: downloading github.com/containerd/stargz-snapshotter/estargz v0.16.3
go: downloading github.com/klauspost/compress v1.18.0
go: downloading github.com/docker/docker-credential-helpers v0.9.3
go: downloading github.com/vbatts/tar-split v0.12.1
[155/295] Building CXX object common/CMakeFiles/common.dir/Release/chat-parser.cpp.obj
[156/295] Building CXX object common/CMakeFiles/common.dir/Release/common.cpp.obj
[157/295] Building CXX object common/CMakeFiles/common.dir/Release/console.cpp.obj
[158/295] Building CXX object common/CMakeFiles/common.dir/Release/json-partial.cpp.obj
[159/295] Building CXX object common/CMakeFiles/common.dir/Release/llguidance...
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.