-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Building for iPhone (iOS) error: xpc/xpc.h not found in IOSurfaceAPI when including <Metal/Metal.h> in ggml-metal.m #3106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I've never encountered this before on iOS. What is your Xcode version? Or are you use some other build tool? Also, the swift package provided some info you can refer to. |
I'm using XCode 14.3.1 on Ventura 13.5 I'm building llama.cpp from source (not using the swift package). I created the xcodeproject by running CMake in the build folder, then linking the xcodeproj into my project |
I took a quick look for IOSurfaceBase.h in the frameworks: // ...
#if TARGET_OS_OSX
#include <xpc/xpc.h>
#endif This means it doesn't work on iOS, but I don't think it should reference anything xpc on iOS, so I guess it has something wrong on the generated xcodeproj. For iOS, I mainly build llama.cpp via CocoaPods, not familiar with CMake + Xcode, it would be great if you could provide a simple demo so I can help try it out. |
I found the Path: You can replace
I think the cmake command you used is better. |
I used the CMake GUI. Pointed it at the llama.cpp folder, clicked "configure". Set "Xcode", "use default native compiler". I looked through the CMake options, it seems at this stage all the variables such as "METALKIT_FRAMEWORK" are already set to point to the MacOS path. |
Sorry I couldn't try the CMake GUI at this time, but I looking to the doc, it's simple on the command line: We need to modify CMakeLists.txt to made it work: diff --git a/CMakeLists.txt b/CMakeLists.txt
index e6242dc..17f18eb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -476,7 +476,7 @@ if (NOT MSVC)
endif()
endif()
-if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
+if ((${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64"))
message(STATUS "ARM detected")
if (MSVC)
# TODO: arm msvc?
@@ -581,6 +581,9 @@ endif()
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_compile_definitions(_DARWIN_C_SOURCE)
endif()
+if (CMAKE_SYSTEM_NAME MATCHES "iOS")
+ add_compile_definitions(_DARWIN_C_SOURCE)
+endif()
if (CMAKE_SYSTEM_NAME MATCHES "DragonFly")
add_compile_definitions(_DARWIN_C_SOURCE)
endif() It's need to check CMAKE_SYSTEM_NAME is iOS to define _DARWIN_C_SOURCE. I don't why the previously mkdir build && cd build
cmake -G Xcode .. \
-DLLAMA_BUILD_EXAMPLES=OFF \
-DLLAMA_BUILD_TESTS=OFF \
-DLLAMA_BUILD_SERVER=OFF \
-DCMAKE_SYSTEM_NAME=iOS \
-DCMAKE_OSX_DEPLOYMENT_TARGET=14.0
cmake --build . --config Release This is works to me, we might be able to contribute a CI step to llama.cpp to ensure it continues to work. |
Thanks for the tips. I got it working in the end using the Swift package instead of Cmake
…________________________________
From: Jhen-Jie Hong ***@***.***>
Sent: Monday, September 11, 2023 7:36:15 AM
To: ggerganov/llama.cpp ***@***.***>
Cc: l3utterfly ***@***.***>; Author ***@***.***>
Subject: Re: [ggerganov/llama.cpp] Building for iPhone (iOS) error: xpc/xpc.h not found in IOSurfaceAPI when including <Metal/Metal.h> in ggml-metal.m (Issue #3106)
Sorry I couldn't try the CMake GUI at this time, but I looking to the doc<https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-ios-tvos-or-watchos>, it's as simple on the command line:
We nee to modify CMakeLists.txt to made it work:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e6242dc..17f18eb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -476,7 +476,7 @@ if (NOT MSVC)
endif()
endif()
-if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
+if ((${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64"))
message(STATUS "ARM detected")
if (MSVC)
# TODO: arm msvc?
@@ -581,6 +581,9 @@ endif()
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_compile_definitions(_DARWIN_C_SOURCE)
endif()
+if (CMAKE_SYSTEM_NAME MATCHES "iOS")
+ add_compile_definitions(_DARWIN_C_SOURCE)
+endif()
if (CMAKE_SYSTEM_NAME MATCHES "DragonFly")
add_compile_definitions(_DARWIN_C_SOURCE)
endif()
It's need to check CMAKE_SYSTEM_NAME is iOS to define _DARWIN_C_SOURCE. I don't why the previously MATCHES OR is broken to me.
mkdir build && cd build
cmake -G Xcode .. \
-DLLAMA_BUILD_EXAMPLES=OFF \
-DLLAMA_BUILD_TESTS=OFF \
-DLLAMA_BUILD_SERVER=OFF \
-DCMAKE_SYSTEM_NAME=iOS \
-DCMAKE_OSX_DEPLOYMENT_TARGET=14.0
cmake --build . --config Release
This is works to me, we might be able to contribute a CI step to llama.cpp to ensure it continues to work.
—
Reply to this email directly, view it on GitHub<#3106 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABVFX26PVVQDLJCL5LPASD3XZZFG7ANCNFSM6AAAAAA4R5WHBI>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Getting the error
xpc/xpc.h not found
when building targeting iOS.I followed the fix in this stackoverflow answer: https://stackoverflow.com/questions/24013814/how-to-resolve-xpc-h-not-found-error
I downloaded the necessary headers from: https://github.com/realthunder/mac-headers, then copied the
xpc
directory in there into the root folder ofllama.cpp
.After this fix, iOS builds work.
Is this something wrong with my setup in particular? Or is adding the
xpc
headers is necessary? If so, should I do a pull request adding the headers?The text was updated successfully, but these errors were encountered: