1919 * when already applied, which is treated as success.
2020 */
2121
22- import { execFileSync , spawnSync } from "node:child_process" ;
23- import { existsSync , readFileSync , readdirSync } from "node:fs" ;
22+ import { spawnSync } from "node:child_process" ;
23+ import { existsSync , readFileSync , readdirSync , writeFileSync } from "node:fs" ;
2424import { dirname , join , resolve } from "node:path" ;
2525import { fileURLToPath } from "node:url" ;
2626
@@ -84,6 +84,7 @@ for (const { label, dir: pkgDir } of candidates) {
8484 try {
8585 const contents = readFileSync ( buildGradle , "utf8" ) ;
8686 if ( contents . includes ( "'arm64-v8a', 'riscv64'" ) ) {
87+ ensureAndroidSkipPatch ( pkgDir ) ;
8788 skipped ++ ;
8889 continue ;
8990 }
@@ -102,6 +103,7 @@ for (const { label, dir: pkgDir } of candidates) {
102103 ) ;
103104
104105 if ( result . status === 0 || result . status === 1 ) {
106+ ensureAndroidSkipPatch ( pkgDir ) ;
105107 patched ++ ;
106108 } else {
107109 failed ++ ;
@@ -116,3 +118,30 @@ if (patched > 0 || skipped > 0 || failed > 0) {
116118 `[patch-llama-cpp-capacitor] patched=${ patched } already-applied=${ skipped } failed=${ failed } ` ,
117119 ) ;
118120}
121+
122+ function ensureAndroidSkipPatch ( pkgDir ) {
123+ const cmakeLists = join ( pkgDir , "android" , "src" , "main" , "CMakeLists.txt" ) ;
124+ if ( ! existsSync ( cmakeLists ) ) return ;
125+ const current = readFileSync ( cmakeLists , "utf8" ) ;
126+ if ( current . includes ( "ELIZA_ANDROID_SKIP_FORK_LLAMA_LIB" ) ) return ;
127+ const marker =
128+ 'if(NOT DEFINED ELIZA_REPO_ROOT)\n message(FATAL_ERROR "ELIZA_REPO_ROOT is required for the Eliza DFlash Android JNI bridge")\nendif()\n' ;
129+ if ( ! current . includes ( marker ) ) return ;
130+ const skipBlock =
131+ 'if(DEFINED ENV{ELIZA_ANDROID_SKIP_FORK_LLAMA_LIB} AND "$ENV{ELIZA_ANDROID_SKIP_FORK_LLAMA_LIB}" STREQUAL "1")\n' +
132+ ' file(WRITE "${CMAKE_BINARY_DIR}/eliza-dflash-smoke-stub.cpp" "extern \\"C\\" int eliza_dflash_smoke_stub() { return 0; }\\n")\n' +
133+ ' set(ELIZA_SMOKE_OUTPUT_NAME "llama-cpp-arm64")\n' +
134+ ' if(ANDROID_ABI STREQUAL "riscv64")\n' +
135+ ' set(ELIZA_SMOKE_OUTPUT_NAME "llama-cpp-riscv64")\n' +
136+ ' endif()\n' +
137+ ' add_library(${ELIZA_SMOKE_OUTPUT_NAME} SHARED "${CMAKE_BINARY_DIR}/eliza-dflash-smoke-stub.cpp")\n' +
138+ ' set_target_properties(\n' +
139+ ' ${ELIZA_SMOKE_OUTPUT_NAME}\n' +
140+ ' PROPERTIES\n' +
141+ ' OUTPUT_NAME "${ELIZA_SMOKE_OUTPUT_NAME}"\n' +
142+ ' )\n' +
143+ ' message(STATUS "Skipping Eliza DFlash JNI bridge for Android smoke build")\n' +
144+ ' return()\n' +
145+ 'endif()\n\n' ;
146+ writeFileSync ( cmakeLists , current . replace ( marker , skipBlock + marker ) ) ;
147+ }
0 commit comments