Skip to content

Commit c28da71

Browse files
committed
llama : add support for visionOS in xcframework
This commit add support for visionOS in xcframework build script. This includes building for visionOS and visionOS simulator. Currently there is some duplication in the build script which I'll address in a follow-up commit as I think it should probably be refactored now that more platforms are being added.
1 parent afe2087 commit c28da71

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

build-xcframework.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ rm -rf build-ios
1717
rm -rf build-ios-sim
1818
rm -rf build-ios-device
1919
rm -rf build-macos
20+
rm -rf build-visionos
2021

2122
# Function to setup framework structure for a given architecture
2223
setup_framework_structure() {
@@ -136,10 +137,53 @@ cmake -B build-macos -G Xcode \
136137
-S .
137138
cmake --build build-macos --config Release
138139

140+
141+
# Build for visionOS
142+
cmake -B build-visionos -G Xcode \
143+
-DBUILD_SHARED_LIBS=OFF \
144+
-DLLAMA_BUILD_EXAMPLES=OFF \
145+
-DLLAMA_BUILD_TESTS=OFF \
146+
-DLLAMA_BUILD_SERVER=OFF \
147+
-DGGML_METAL=ON \
148+
-DGGML_METAL_EMBED_LIBRARY=ON \
149+
-DGGML_BLAS_DEFAULT=ON \
150+
-DGGML_METAL_USE_BF16=ON \
151+
-DCMAKE_OSX_ARCHITECTURES="arm64" \
152+
-DCMAKE_SYSTEM_NAME=visionOS \
153+
-DCMAKE_OSX_SYSROOT=xros \
154+
-DCMAKE_OSX_DEPLOYMENT_TARGET=1.0 \
155+
-DCMAKE_XCODE_ATTRIBUTE_SUPPORTED_PLATFORMS=xros \
156+
-DCMAKE_C_FLAGS="-D_XOPEN_SOURCE=700 -Du_int=unsigned\ int -Du_char=unsigned\ char -Du_short=unsigned\ short -DGGML_VISIONOS=1" \
157+
-DCMAKE_CXX_FLAGS="-D_XOPEN_SOURCE=700 -Du_int=unsigned\ int -Du_char=unsigned\ char -Du_short=unsigned\ short -DGGML_VISIONOS=1" \
158+
-S .
159+
cmake --build build-visionos --config Release
160+
161+
# Build for visionOS simulator
162+
cmake -B build-visionos-sim -G Xcode \
163+
-DBUILD_SHARED_LIBS=OFF \
164+
-DLLAMA_BUILD_EXAMPLES=OFF \
165+
-DLLAMA_BUILD_TESTS=OFF \
166+
-DLLAMA_BUILD_SERVER=OFF \
167+
-DGGML_METAL=ON \
168+
-DGGML_METAL_EMBED_LIBRARY=ON \
169+
-DGGML_BLAS_DEFAULT=ON \
170+
-DGGML_METAL_USE_BF16=ON \
171+
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
172+
-DCMAKE_SYSTEM_NAME=visionOS \
173+
-DCMAKE_OSX_SYSROOT=xrsimulator \
174+
-DCMAKE_OSX_DEPLOYMENT_TARGET=1.0 \
175+
-DCMAKE_XCODE_ATTRIBUTE_SUPPORTED_PLATFORMS=xrsimulator \
176+
-DCMAKE_C_FLAGS="-D_XOPEN_SOURCE=700 -Du_int=unsigned\ int -Du_char=unsigned\ char -Du_short=unsigned\ short -DGGML_VISIONOS=1" \
177+
-DCMAKE_CXX_FLAGS="-D_XOPEN_SOURCE=700 -Du_int=unsigned\ int -Du_char=unsigned\ char -Du_short=unsigned\ short -DGGML_VISIONOS=1" \
178+
-S .
179+
cmake --build build-visionos-sim --config Release
180+
139181
# Setup frameworks and copy binaries and headers
140182
setup_framework_structure "build-ios-sim"
141183
setup_framework_structure "build-ios-device"
142184
setup_framework_structure "build-macos"
185+
setup_framework_structure "build-visionos"
186+
setup_framework_structure "build-visionos-sim"
143187

144188
# Function to combine static libraries
145189
combine_static_libraries() {
@@ -162,12 +206,16 @@ combine_static_libraries() {
162206
combine_static_libraries "build-ios-sim" "Release-iphonesimulator"
163207
combine_static_libraries "build-ios-device" "Release-iphoneos"
164208
combine_static_libraries "build-macos" "Release"
209+
combine_static_libraries "build-visionos" "Release-xros"
210+
combine_static_libraries "build-visionos-sim" "Release-xrsimulator"
165211

166212
# Create XCFramework
167213
xcodebuild -create-xcframework \
168214
-framework $(pwd)/build-ios-sim/framework/llama.framework \
169215
-framework $(pwd)/build-ios-device/framework/llama.framework \
170216
-framework $(pwd)/build-macos/framework/llama.framework \
217+
-framework $(pwd)/build-visionos/framework/llama.framework \
218+
-framework $(pwd)/build-visionos-sim/framework/llama.framework \
171219
-output $(pwd)/build-ios/llama.xcframework
172220

173221
# The generated framework can be found in build-ios/llama.xcframework and

src/llama-mmap.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ struct llama_mmap::impl {
314314
}
315315

316316
void unmap_fragment(size_t first, size_t last) {
317-
int page_size = sysconf(_SC_PAGESIZE);
317+
long page_size = sysconf(_SC_PAGESIZE);
318318
align_range(&first, &last, page_size);
319319
size_t len = last - first;
320320

@@ -471,14 +471,19 @@ struct llama_mlock::impl {
471471

472472
char* errmsg = std::strerror(errno);
473473
bool suggest = (errno == ENOMEM);
474-
474+
#if defined(GGML_VISIONOS)
475+
// visionOS doesn't support RLIMIT_MEMLOCK
476+
// Skip resource limit checks on visionOS
477+
suggest = false;
478+
#else
475479
struct rlimit lock_limit;
476480
if (suggest && getrlimit(RLIMIT_MEMLOCK, &lock_limit)) {
477481
suggest = false;
478482
}
479483
if (suggest && (lock_limit.rlim_max > lock_limit.rlim_cur + size)) {
480484
suggest = false;
481485
}
486+
#endif
482487

483488
LLAMA_LOG_WARN("warning: failed to mlock %zu-byte buffer (after previously locking %zu bytes): %s\n%s",
484489
size, this->size, errmsg, suggest ? MLOCK_SUGGESTION : "");

0 commit comments

Comments
 (0)