Skip to content

Commit

Permalink
Merge pull request #605 from nobodywho-ooo/android-build
Browse files Browse the repository at this point in the history
Build for aarch64-linux-android
  • Loading branch information
MarcusDunn authored Jan 2, 2025
2 parents b2b45fa + 55059ad commit 5df1501
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
11 changes: 10 additions & 1 deletion llama-cpp-2/src/sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ impl Debug for LlamaSampler {
}
}

// this is needed for the dry sampler to typecheck on android
// ...because what is normally an i8, is an u8
#[cfg(target_os = "android")]
type CChar = u8;

#[cfg(not(target_os = "android"))]
type CChar = i8;


impl LlamaSampler {
/// Sample and accept a token from the idx-th output of the last evaluation
#[must_use]
Expand Down Expand Up @@ -257,7 +266,7 @@ impl LlamaSampler {
.into_iter()
.map(|s| CString::new(s.as_ref()).unwrap())
.collect();
let mut seq_breaker_pointers: Vec<*const i8> =
let mut seq_breaker_pointers: Vec<*const CChar> =
seq_breakers.iter().map(|s| s.as_ptr()).collect();

let sampler = unsafe {
Expand Down
18 changes: 18 additions & 0 deletions llama-cpp-sys-2/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,24 @@ fn main() {
config.static_crt(static_crt);
}

if target.contains("android") && target.contains("aarch64") {
// build flags for android taken from this doc
// https://github.com/ggerganov/llama.cpp/blob/master/docs/android.md
let android_ndk = env::var("ANDROID_NDK")
.expect("Please install Android NDK and ensure that ANDROID_NDK env variable is set");
config.define(
"CMAKE_TOOLCHAIN_FILE",
format!("{android_ndk}/build/cmake/android.toolchain.cmake"),
);
config.define("ANDROID_ABI", "arm64-v8a");
config.define("ANDROID_PLATFORM", "android-28");
config.define("CMAKE_SYSTEM_PROCESSOR", "arm64");
config.define("CMAKE_C_FLAGS", "-march=armv8.7a");
config.define("CMAKE_CXX_FLAGS", "-march=armv8.7a");
config.define("GGML_OPENMP", "OFF");
config.define("GGML_LLAMAFILE", "OFF");
}

if cfg!(feature = "vulkan") {
config.define("GGML_VULKAN", "ON");
if cfg!(windows) {
Expand Down

0 comments on commit 5df1501

Please sign in to comment.