Skip to content

Use fbjni from maven #6163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion examples/third-party/fbjni
Submodule fbjni deleted from 52a14f
38 changes: 35 additions & 3 deletions extension/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,40 @@ 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
# 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems risky? How do you make sure things under third-party/fbjni is compatible with fbjni.aar downloaded from Maven?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I need to remove examples/third-party/fbjni in a follow up PR. We can't use it. We need to make sure the runtime so deps is the same as compile time so library. We can't build the so from source, because runtime uses another one. The fbjni.aar downloaded from Maven basically contains a "SDK" of headers and so library for us to link our ET library against.


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"
)

set(executorch_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../lib/cmake/ExecuTorch)
Expand Down Expand Up @@ -128,6 +159,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})
Expand Down
Loading