From e0a5f0e9d072f0e57c955193ccc458fc1af3bf18 Mon Sep 17 00:00:00 2001 From: storytellerF <34095089+storytellerF@users.noreply.github.com> Date: Tue, 15 Apr 2025 07:58:20 +0800 Subject: [PATCH 1/2] compat android --- .github/include/windows/jni_md.h | 4 ++++ CMakeLists.txt | 6 ++++++ src/main/cpp/jllama.cpp | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/include/windows/jni_md.h b/.github/include/windows/jni_md.h index 6c8d6b9e..38724b88 100644 --- a/.github/include/windows/jni_md.h +++ b/.github/include/windows/jni_md.h @@ -32,7 +32,11 @@ // 'long' is always 32 bit on windows so this matches what jdk expects typedef long jint; +#ifdef PLATFORM_WINDOWS typedef __int64 jlong; +#else +typedef int64_t jlong; +#endif typedef signed char jbyte; #endif /* !_JAVASOFT_JNI_MD_H_ */ diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f402fa2..4f139fa5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,3 +119,9 @@ if (LLAMA_METAL AND NOT LLAMA_METAL_EMBED_LIBRARY) # copy ggml-common.h and ggml-metal.metal to bin directory configure_file(${llama.cpp_SOURCE_DIR}/ggml-metal.metal ${JLLAMA_DIR}/ggml-metal.metal COPYONLY) endif() + +if (MSVC) + add_definitions(-DPLATFORM_WINDOWS) +else() + add_definitions(-DPLATFORM_UNIX) +endif() \ No newline at end of file diff --git a/src/main/cpp/jllama.cpp b/src/main/cpp/jllama.cpp index ac056b94..0f495328 100644 --- a/src/main/cpp/jllama.cpp +++ b/src/main/cpp/jllama.cpp @@ -823,7 +823,7 @@ JNIEXPORT void JNICALL Java_de_kherud_llama_LlamaModel_delete(JNIEnv *env, jobje JNIEXPORT void JNICALL Java_de_kherud_llama_LlamaModel_cancelCompletion(JNIEnv *env, jobject obj, jint id_task) { jlong server_handle = env->GetLongField(obj, f_model_pointer); auto *ctx_server = reinterpret_cast(server_handle); // NOLINT(*-no-int-to-ptr) - std::unordered_set id_tasks = {id_task}; + std::unordered_set id_tasks = {static_cast(id_task)}; ctx_server->cancel_tasks(id_tasks); ctx_server->queue_results.remove_waiting_task_id(id_task); } From 0c50bed5d5be282a368265b73a2459dcf03b6d52 Mon Sep 17 00:00:00 2001 From: storytellerF <34095089+storytellerF@users.noreply.github.com> Date: Sun, 20 Apr 2025 00:48:48 +0800 Subject: [PATCH 2/2] --amend --- .github/include/windows/jni_md.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/include/windows/jni_md.h b/.github/include/windows/jni_md.h index 38724b88..934ffb18 100644 --- a/.github/include/windows/jni_md.h +++ b/.github/include/windows/jni_md.h @@ -26,16 +26,25 @@ #ifndef _JAVASOFT_JNI_MD_H_ #define _JAVASOFT_JNI_MD_H_ -#define JNIEXPORT __declspec(dllexport) -#define JNIIMPORT __declspec(dllimport) -#define JNICALL __stdcall +#ifdef _MSC_VER + // Windows + MSVC 编译器 + #define JNIEXPORT __declspec(dllexport) + #define JNIIMPORT __declspec(dllimport) + #define JNICALL __stdcall +#else + // 其他平台或非 MSVC 编译器 + #define JNIEXPORT + #define JNIIMPORT + #define JNICALL +#endif // 'long' is always 32 bit on windows so this matches what jdk expects typedef long jint; #ifdef PLATFORM_WINDOWS -typedef __int64 jlong; + typedef __int64 jlong; #else -typedef int64_t jlong; + #include + typedef int64_t jlong; #endif typedef signed char jbyte;