File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,15 @@ impl Debug for LlamaSampler {
20
20
}
21
21
}
22
22
23
+ // this is needed for the dry sampler to typecheck on android
24
+ // ...because what is normally an i8, is an u8
25
+ #[ cfg( target_os = "android" ) ]
26
+ type CChar = u8 ;
27
+
28
+ #[ cfg( not( target_os = "android" ) ) ]
29
+ type CChar = i8 ;
30
+
31
+
23
32
impl LlamaSampler {
24
33
/// Sample and accept a token from the idx-th output of the last evaluation
25
34
#[ must_use]
@@ -257,7 +266,7 @@ impl LlamaSampler {
257
266
. into_iter ( )
258
267
. map ( |s| CString :: new ( s. as_ref ( ) ) . unwrap ( ) )
259
268
. collect ( ) ;
260
- let mut seq_breaker_pointers: Vec < * const i8 > =
269
+ let mut seq_breaker_pointers: Vec < * const CChar > =
261
270
seq_breakers. iter ( ) . map ( |s| s. as_ptr ( ) ) . collect ( ) ;
262
271
263
272
let sampler = unsafe {
Original file line number Diff line number Diff line change @@ -230,6 +230,24 @@ fn main() {
230
230
config. static_crt ( static_crt) ;
231
231
}
232
232
233
+ if target. contains ( "android" ) && target. contains ( "aarch64" ) {
234
+ // build flags for android taken from this doc
235
+ // https://github.com/ggerganov/llama.cpp/blob/master/docs/android.md
236
+ let android_ndk = env:: var ( "ANDROID_NDK" )
237
+ . expect ( "Please install Android NDK and ensure that ANDROID_NDK env variable is set" ) ;
238
+ config. define (
239
+ "CMAKE_TOOLCHAIN_FILE" ,
240
+ format ! ( "{android_ndk}/build/cmake/android.toolchain.cmake" ) ,
241
+ ) ;
242
+ config. define ( "ANDROID_ABI" , "arm64-v8a" ) ;
243
+ config. define ( "ANDROID_PLATFORM" , "android-28" ) ;
244
+ config. define ( "CMAKE_SYSTEM_PROCESSOR" , "arm64" ) ;
245
+ config. define ( "CMAKE_C_FLAGS" , "-march=armv8.7a" ) ;
246
+ config. define ( "CMAKE_CXX_FLAGS" , "-march=armv8.7a" ) ;
247
+ config. define ( "GGML_OPENMP" , "OFF" ) ;
248
+ config. define ( "GGML_LLAMAFILE" , "OFF" ) ;
249
+ }
250
+
233
251
if cfg ! ( feature = "vulkan" ) {
234
252
config. define ( "GGML_VULKAN" , "ON" ) ;
235
253
if cfg ! ( windows) {
You can’t perform that action at this time.
0 commit comments