From 80fafa40d7cd4fa517febafb95d6ae8a8f85121c Mon Sep 17 00:00:00 2001 From: kirklandsign Date: Thu, 10 Oct 2024 22:50:38 -0700 Subject: [PATCH 1/7] Use fbjni from maven --- extension/android/CMakeLists.txt | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/extension/android/CMakeLists.txt b/extension/android/CMakeLists.txt index 075e4f21a40..8762c7a9684 100644 --- a/extension/android/CMakeLists.txt +++ b/extension/android/CMakeLists.txt @@ -21,9 +21,33 @@ include(${EXECUTORCH_ROOT}/build/Utils.cmake) set(_common_compile_options -Wno-deprecated-declarations -fPIC) set(_common_include_directories ${EXECUTORCH_ROOT}/..) -add_subdirectory( - ${EXECUTORCH_ROOT}/examples/third-party/fbjni - ${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni +if(NOT FBJNI_VERSION) + set(FBJNI_VERSION 0.5.2) +endif() +set(FBJNI_AAR_URL https://repo1.maven.org/maven2/com/facebook/fbjni/fbjni/${FBJNI_VERSION}/fbjni-${FBJNI_VERSION}.aar) +set(FBJNI_DOWNLOAD_PATH ${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/fbjni.aar) + +if (NOT EXISTS "${FBJNI_DOWNLOAD_PATH}") + file(DOWNLOAD "${FBJNI_AAR_URL}" "${FBJNI_DOWNLOAD_PATH}") +endif() + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/include/" "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/libs/android.${ANDROID_ABI}/libfbjni.so" + COMMAND unzip -o ${FBJNI_DOWNLOAD_PATH} -d ${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni + DEPENDS "${FBJNI_DOWNLOAD_PATH}") + +add_custom_target( + fbjni_prefab + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/include/" "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/libs/android.${ANDROID_ABI}/libfbjni.so" +) + +add_library(fbjni SHARED IMPORTED) +add_dependencies(fbjni fbjni_prefab) +set_target_properties(fbjni PROPERTIES + IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/libs/android.${ANDROID_ABI}/libfbjni.so" +) +list(APPEND + _common_include_directories "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/include/" ) set(executorch_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../lib/cmake/ExecuTorch) From 14817414d298d84d6b976e2a8e71f62f1d0d644a Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Thu, 10 Oct 2024 23:29:51 -0700 Subject: [PATCH 2/7] Fix include --- extension/android/CMakeLists.txt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/extension/android/CMakeLists.txt b/extension/android/CMakeLists.txt index 8762c7a9684..c32833655a1 100644 --- a/extension/android/CMakeLists.txt +++ b/extension/android/CMakeLists.txt @@ -28,13 +28,13 @@ set(FBJNI_AAR_URL https://repo1.maven.org/maven2/com/facebook/fbjni/fbjni/${FBJN set(FBJNI_DOWNLOAD_PATH ${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/fbjni.aar) if (NOT EXISTS "${FBJNI_DOWNLOAD_PATH}") - file(DOWNLOAD "${FBJNI_AAR_URL}" "${FBJNI_DOWNLOAD_PATH}") + file(DOWNLOAD "${FBJNI_AAR_URL}" "${FBJNI_DOWNLOAD_PATH}") endif() add_custom_command( - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/include/" "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/libs/android.${ANDROID_ABI}/libfbjni.so" - COMMAND unzip -o ${FBJNI_DOWNLOAD_PATH} -d ${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni - DEPENDS "${FBJNI_DOWNLOAD_PATH}") + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/include/" "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/libs/android.${ANDROID_ABI}/libfbjni.so" + COMMAND unzip -o ${FBJNI_DOWNLOAD_PATH} -d ${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni + DEPENDS "${FBJNI_DOWNLOAD_PATH}") add_custom_target( fbjni_prefab @@ -47,7 +47,7 @@ set_target_properties(fbjni PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/libs/android.${ANDROID_ABI}/libfbjni.so" ) list(APPEND - _common_include_directories "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/include/" + _common_include_directories ) set(executorch_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../lib/cmake/ExecuTorch) @@ -152,6 +152,7 @@ endif() target_include_directories( executorch_jni PRIVATE ${_common_include_directories} + "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/include/" ) target_compile_options(executorch_jni PUBLIC ${_common_compile_options}) From d9b92a749dca42e2dcda149d2a0377281fb394a4 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Thu, 10 Oct 2024 23:34:16 -0700 Subject: [PATCH 3/7] version is 0.5.1 --- extension/android/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/android/CMakeLists.txt b/extension/android/CMakeLists.txt index c32833655a1..a1bf4d3fd72 100644 --- a/extension/android/CMakeLists.txt +++ b/extension/android/CMakeLists.txt @@ -22,7 +22,7 @@ set(_common_compile_options -Wno-deprecated-declarations -fPIC) set(_common_include_directories ${EXECUTORCH_ROOT}/..) if(NOT FBJNI_VERSION) - set(FBJNI_VERSION 0.5.2) + set(FBJNI_VERSION 0.5.1) endif() set(FBJNI_AAR_URL https://repo1.maven.org/maven2/com/facebook/fbjni/fbjni/${FBJNI_VERSION}/fbjni-${FBJNI_VERSION}.aar) set(FBJNI_DOWNLOAD_PATH ${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/fbjni.aar) From 6697d38138b492a39577b5656bbf713bff9e4bfd Mon Sep 17 00:00:00 2001 From: Hansong <107070759+kirklandsign@users.noreply.github.com> Date: Thu, 10 Oct 2024 23:47:24 -0700 Subject: [PATCH 4/7] Fix linter --- extension/android/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/android/CMakeLists.txt b/extension/android/CMakeLists.txt index a1bf4d3fd72..368fef10757 100644 --- a/extension/android/CMakeLists.txt +++ b/extension/android/CMakeLists.txt @@ -27,7 +27,7 @@ endif() set(FBJNI_AAR_URL https://repo1.maven.org/maven2/com/facebook/fbjni/fbjni/${FBJNI_VERSION}/fbjni-${FBJNI_VERSION}.aar) set(FBJNI_DOWNLOAD_PATH ${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/fbjni.aar) -if (NOT EXISTS "${FBJNI_DOWNLOAD_PATH}") +if(NOT EXISTS "${FBJNI_DOWNLOAD_PATH}") file(DOWNLOAD "${FBJNI_AAR_URL}" "${FBJNI_DOWNLOAD_PATH}") endif() From 50dcb3b5831687dd31154b226a37e9f2acd1274e Mon Sep 17 00:00:00 2001 From: Hansong <107070759+kirklandsign@users.noreply.github.com> Date: Thu, 10 Oct 2024 23:53:58 -0700 Subject: [PATCH 5/7] Update docs --- extension/android/CMakeLists.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/extension/android/CMakeLists.txt b/extension/android/CMakeLists.txt index 368fef10757..1f3407eb24b 100644 --- a/extension/android/CMakeLists.txt +++ b/extension/android/CMakeLists.txt @@ -21,9 +21,18 @@ include(${EXECUTORCH_ROOT}/build/Utils.cmake) set(_common_compile_options -Wno-deprecated-declarations -fPIC) set(_common_include_directories ${EXECUTORCH_ROOT}/..) +# We need to download fbjni library from maven, and use its "prefab" library +# and headers, and link executorch library against that fbjni library. +# We don't know which NDK is used to compile fbjni, and we need to link our +# executorch library to the version which Android APK links against for runtime +# to ensure the libc++ dependencies are consistent. +# WARNING # +# Users need to use the SAME fbjni version here and in app gradle dependency +# for runtime compatibility! if(NOT FBJNI_VERSION) set(FBJNI_VERSION 0.5.1) endif() + set(FBJNI_AAR_URL https://repo1.maven.org/maven2/com/facebook/fbjni/fbjni/${FBJNI_VERSION}/fbjni-${FBJNI_VERSION}.aar) set(FBJNI_DOWNLOAD_PATH ${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/fbjni.aar) @@ -46,9 +55,6 @@ add_dependencies(fbjni fbjni_prefab) set_target_properties(fbjni PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/libs/android.${ANDROID_ABI}/libfbjni.so" ) -list(APPEND - _common_include_directories -) set(executorch_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../lib/cmake/ExecuTorch) find_package(executorch CONFIG REQUIRED) From 6c497525198883e383d37ce76e8333291806f651 Mon Sep 17 00:00:00 2001 From: Hansong <107070759+kirklandsign@users.noreply.github.com> Date: Thu, 10 Oct 2024 23:54:40 -0700 Subject: [PATCH 6/7] Format --- extension/android/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extension/android/CMakeLists.txt b/extension/android/CMakeLists.txt index 1f3407eb24b..cc080716111 100644 --- a/extension/android/CMakeLists.txt +++ b/extension/android/CMakeLists.txt @@ -43,7 +43,8 @@ endif() add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/include/" "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/libs/android.${ANDROID_ABI}/libfbjni.so" COMMAND unzip -o ${FBJNI_DOWNLOAD_PATH} -d ${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni - DEPENDS "${FBJNI_DOWNLOAD_PATH}") + DEPENDS "${FBJNI_DOWNLOAD_PATH}" +) add_custom_target( fbjni_prefab From 96e380fc45cc98f88e979f6a83127db94b53bc8e Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Fri, 11 Oct 2024 11:08:23 -0700 Subject: [PATCH 7/7] Remove examples/third-party/fbjni. We should use the library from maven repo --- .gitmodules | 3 --- examples/third-party/fbjni | 1 - 2 files changed, 4 deletions(-) delete mode 160000 examples/third-party/fbjni diff --git a/.gitmodules b/.gitmodules index 71ff854bb03..844cd917892 100644 --- a/.gitmodules +++ b/.gitmodules @@ -28,9 +28,6 @@ [submodule "backends/xnnpack/third-party/pthreadpool"] path = backends/xnnpack/third-party/pthreadpool url = https://github.com/Maratyszcza/pthreadpool.git -[submodule "examples/third-party/fbjni"] - path = examples/third-party/fbjni - url = https://github.com/facebookincubator/fbjni.git [submodule "extension/llm/third-party/abseil-cpp"] path = extension/llm/third-party/abseil-cpp url = https://github.com/abseil/abseil-cpp.git diff --git a/examples/third-party/fbjni b/examples/third-party/fbjni deleted file mode 160000 index 52a14f0daa8..00000000000 --- a/examples/third-party/fbjni +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 52a14f0daa889a20d8984798b8d96eb03cebd334