Skip to content

Commit 5df1501

Browse files
authored
Merge pull request #605 from nobodywho-ooo/android-build
Build for aarch64-linux-android
2 parents b2b45fa + 55059ad commit 5df1501

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

llama-cpp-2/src/sampling.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ impl Debug for LlamaSampler {
2020
}
2121
}
2222

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+
2332
impl LlamaSampler {
2433
/// Sample and accept a token from the idx-th output of the last evaluation
2534
#[must_use]
@@ -257,7 +266,7 @@ impl LlamaSampler {
257266
.into_iter()
258267
.map(|s| CString::new(s.as_ref()).unwrap())
259268
.collect();
260-
let mut seq_breaker_pointers: Vec<*const i8> =
269+
let mut seq_breaker_pointers: Vec<*const CChar> =
261270
seq_breakers.iter().map(|s| s.as_ptr()).collect();
262271

263272
let sampler = unsafe {

llama-cpp-sys-2/build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,24 @@ fn main() {
230230
config.static_crt(static_crt);
231231
}
232232

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+
233251
if cfg!(feature = "vulkan") {
234252
config.define("GGML_VULKAN", "ON");
235253
if cfg!(windows) {

0 commit comments

Comments
 (0)