llama-cpp-capacitor 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'LlamaCppCapacitor'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '15.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+
18
+ # Include the native llama-cpp framework
19
+ s.vendored_frameworks = 'ios/Frameworks/llama-cpp.framework'
20
+ s.pod_target_xcconfig = {
21
+ 'FRAMEWORK_SEARCH_PATHS' => '$(inherited) "$(PODS_TARGET_SRCROOT)/ios/Frameworks"'
22
+ }
23
+ end
package/build-native.sh CHANGED
@@ -93,36 +93,53 @@ build_ios() {
93
93
  cd ios/build
94
94
 
95
95
  # Configure with CMake
96
+ # IMPORTANT: CMAKE_OSX_SYSROOT=iphoneos ensures we build for iOS, not macOS.
97
+ # Without it, the framework would be built for macOS and fail to link in an iOS app.
96
98
  # IMPORTANT: build iOS framework as **ARM64-only**.
97
99
  # Including x86_64 here makes CMake/Xcode try to link an x86_64 slice,
98
100
  # but we only compile ARM-specific kernels (arch/arm), which leads to
99
101
  # undefined symbols like lm_ggml_gemm_* for x86_64.
100
102
  cmake .. \
101
103
  -DCMAKE_BUILD_TYPE=Release \
104
+ -DCMAKE_OSX_SYSROOT=iphoneos \
102
105
  -DCMAKE_OSX_ARCHITECTURES="arm64" \
103
106
  -DCMAKE_OSX_DEPLOYMENT_TARGET=13.0 \
104
107
  -DCMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE=NO
105
108
 
106
- # Build
107
- cmake --build . --config Release
109
+ # Build (parallel: -j uses available CPU cores)
110
+ JOBS=$(sysctl -n hw.ncpu 2>/dev/null || nproc 2>/dev/null || echo 4)
111
+ cmake --build . --config Release -- -j"$JOBS"
108
112
 
109
113
  # CMake builds the framework directly (FRAMEWORK TRUE in CMakeLists.txt)
110
114
  # Verify the framework was created
111
115
  if [ -d "llama-cpp.framework" ]; then
112
116
  print_success "iOS framework built successfully at: $(pwd)/llama-cpp.framework"
113
117
 
114
- # Strip debug symbols to reduce app store size (~0.5–1 MB)
115
- BINARY="llama-cpp.framework/Versions/A/llama-cpp"
116
- if [ -f "$BINARY" ]; then
118
+ # Binary location: CMake may produce flat (llama-cpp) or Versions/A/ layout
119
+ BINARY=""
120
+ if [ -f "llama-cpp.framework/llama-cpp" ]; then
121
+ BINARY="llama-cpp.framework/llama-cpp"
122
+ elif [ -f "llama-cpp.framework/Versions/A/llama-cpp" ]; then
123
+ BINARY="llama-cpp.framework/Versions/A/llama-cpp"
124
+ fi
125
+ if [ -n "$BINARY" ]; then
117
126
  if xcrun strip -x -S "$BINARY" 2>/dev/null; then
118
127
  print_status "Stripped debug symbols from iOS framework"
119
128
  fi
120
129
  fi
121
130
 
122
- # Copy framework to package location for npm publishing
123
- mkdir -p ../Frameworks
124
- cp -R llama-cpp.framework ../Frameworks/
125
- print_success "iOS framework copied to ios/Frameworks/ for npm package"
131
+ # Build flat framework (single binary, no duplication) for npm publishing
132
+ if [ -z "$BINARY" ] || [ ! -f "$BINARY" ]; then
133
+ print_error "iOS framework binary not found"
134
+ cd ../..
135
+ return 1
136
+ fi
137
+ rm -rf ../Frameworks/llama-cpp.framework
138
+ mkdir -p ../Frameworks/llama-cpp.framework/Resources
139
+ cp "$BINARY" ../Frameworks/llama-cpp.framework/llama-cpp
140
+ [ -f llama-cpp.framework/Info.plist ] && cp llama-cpp.framework/Info.plist ../Frameworks/llama-cpp.framework/
141
+ [ -f llama-cpp.framework/Versions/A/Resources/Info.plist ] && cp llama-cpp.framework/Versions/A/Resources/Info.plist ../Frameworks/llama-cpp.framework/Resources/
142
+ print_success "iOS framework copied to ios/Frameworks/ for npm package (flat, no duplication)"
126
143
  else
127
144
  print_error "iOS framework not found after build"
128
145
  cd ../..
@@ -173,7 +190,8 @@ build_android() {
173
190
  -DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_FILE" \
174
191
  -DANDROID_STL=c++_shared
175
192
 
176
- cmake --build . --config Release
193
+ JOBS=$(sysctl -n hw.ncpu 2>/dev/null || nproc 2>/dev/null || echo 4)
194
+ cmake --build . --config Release -- -j"$JOBS"
177
195
 
178
196
  mkdir -p ../src/main/jniLibs/$arch
179
197
  if [ -f "libllama-cpp-arm64.so" ]; then
@@ -201,6 +219,10 @@ build_android() {
201
219
  main() {
202
220
  print_status "Starting llama-cpp Capacitor plugin build..."
203
221
 
222
+ # Always start clean - remove previous build outputs
223
+ rm -rf ios/build ios/Frameworks android/build
224
+ print_status "Cleaned build directories"
225
+
204
226
  # Check dependencies
205
227
  if ! command -v cmake &> /dev/null; then
206
228
  print_error "CMake is required but not installed"
@@ -225,5 +247,5 @@ main() {
225
247
  print_success "Build completed successfully!"
226
248
  }
227
249
 
228
- # Run main function
229
- main "$@"
250
+ # Run main function (ignore any args npm may pass)
251
+ main