From d48ddea1dcdfc4c21264d1a9e949dafea5a1337b Mon Sep 17 00:00:00 2001 From: You Xie Date: Mon, 31 Aug 2026 23:52:27 -0700 Subject: [PATCH] Add a single-.so Vulkan+XNNPACK executorch JNI target Summary: Lets the executorch Android JNI sources be compiled from a Buck package other than their own. `log.cpp` and the JNI headers were not exported, and `jni_helper.cpp` and `log.cpp` included their headers by relative path (`#include "log.h"`). That form only resolves while the file is compiled inside `extension/android/jni`; the moment another target picks the `.cpp` up as an exported source, the include fails. This exports the missing files and switches both includes to the full `` path used everywhere else in the tree. Motivating case: building one `libexecutorch.so` that bundles the JNI bridge, the runtime, and both the Vulkan and XNNPACK backends. Android's linker only runs static initializers for libraries reached through an explicit `System.loadLibrary`, so splitting the backends across several `.so` files leaves their `REGISTER_BACKEND` globals unexecuted and the backends invisible at runtime. Composing everything into a single `.so` requires reusing these JNI sources from another package, which is what the include change enables. No behavior change to any existing target. Differential Revision: D118236328 --- extension/android/jni/BUCK | 16 ++++++++++++++++ extension/android/jni/jni_helper.cpp | 2 +- extension/android/jni/log.cpp | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/extension/android/jni/BUCK b/extension/android/jni/BUCK index 1b3e63002f8..1c7e714b145 100644 --- a/extension/android/jni/BUCK +++ b/extension/android/jni/BUCK @@ -146,6 +146,22 @@ runtime.export_file( name = "jni_helper.cpp", ) +runtime.export_file( + name = "log.cpp", +) + +runtime.export_file( + name = "jni_helper.h", +) + +runtime.export_file( + name = "log.h", +) + +runtime.export_file( + name = "jni_layer_constants.h", +) + runtime.cxx_library( name = "jni_headers", exported_headers = [ diff --git a/extension/android/jni/jni_helper.cpp b/extension/android/jni/jni_helper.cpp index f7c9c4abb74..55bca45a717 100644 --- a/extension/android/jni/jni_helper.cpp +++ b/extension/android/jni/jni_helper.cpp @@ -6,7 +6,7 @@ * LICENSE file in the root directory of this source tree. */ -#include "jni_helper.h" +#include namespace executorch::jni_helper { diff --git a/extension/android/jni/log.cpp b/extension/android/jni/log.cpp index 663198e1271..04deb3ecfd7 100644 --- a/extension/android/jni/log.cpp +++ b/extension/android/jni/log.cpp @@ -6,7 +6,7 @@ * LICENSE file in the root directory of this source tree. */ -#include "log.h" +#include #ifdef __ANDROID__