Skip to content

Commit 6be870f

Browse files
committed
Refactor JNI targets to allow selective build
Summary: Introduce a utility target to allow for selective build with ET JNI. Differential Revision: D75062231
1 parent 6b48e89 commit 6be870f

File tree

4 files changed

+81
-32
lines changed

4 files changed

+81
-32
lines changed

extension/android/jni/BUCK

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ load("@fbsource//tools/build_defs/android:fb_android_cxx_library.bzl", "fb_andro
33
load("@fbsource//xplat/executorch/backends/xnnpack/third-party:third_party_libs.bzl", "third_party_dep")
44
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
55
load("@fbsource//xplat/executorch/codegen:codegen.bzl", "executorch_generated_lib")
6+
load(":build_defs.bzl", "ET_JNI_COMPILER_FLAGS")
67

78
oncall("executorch")
89

@@ -28,16 +29,12 @@ non_fbcode_target(_kind = executorch_generated_lib,
2829
non_fbcode_target(_kind = fb_android_cxx_library,
2930
name = "executorch_jni",
3031
srcs = ["jni_layer.cpp", "log.cpp"],
31-
headers = ["jni_layer_constants.h"],
3232
allow_jni_merging = False,
33-
compiler_flags = [
34-
"-frtti",
35-
"-fexceptions",
36-
"-Wno-unused-variable",
37-
],
33+
compiler_flags = ET_JNI_COMPILER_FLAGS,
3834
soname = "libexecutorch.$(ext)",
3935
visibility = ["PUBLIC"],
4036
deps = [
37+
":jni_headers",
4138
":log_provider_static",
4239
"//fbandroid/libraries/fbjni:fbjni",
4340
"//fbandroid/native/fb:fb",
@@ -53,16 +50,12 @@ non_fbcode_target(_kind = fb_android_cxx_library,
5350
non_fbcode_target(_kind = fb_android_cxx_library,
5451
name = "executorch_jni_full",
5552
srcs = ["jni_layer.cpp", "log.cpp"],
56-
headers = ["jni_layer_constants.h"],
5753
allow_jni_merging = False,
58-
compiler_flags = [
59-
"-frtti",
60-
"-fexceptions",
61-
"-Wno-unused-variable",
62-
],
54+
compiler_flags = ET_JNI_COMPILER_FLAGS,
6355
soname = "libexecutorch.$(ext)",
6456
visibility = ["PUBLIC"],
6557
deps = [
58+
":jni_headers",
6659
":log_provider_static",
6760
":generated_op_lib_optimized_static",
6861
"//fbandroid/libraries/fbjni:fbjni",
@@ -82,17 +75,14 @@ non_fbcode_target(_kind = fb_android_cxx_library,
8275
"jni_layer.cpp",
8376
"jni_layer_llama.cpp",
8477
],
85-
headers = ["jni_layer_constants.h"],
8678
allow_jni_merging = False,
87-
compiler_flags = [
88-
"-frtti",
89-
"-fexceptions",
79+
compiler_flags = ET_JNI_COMPILER_FLAGS + [
9080
"-DEXECUTORCH_BUILD_LLAMA_JNI",
91-
"-Wno-format",
9281
],
9382
soname = "libexecutorch.$(ext)",
9483
visibility = ["PUBLIC"],
9584
deps = [
85+
":jni_headers",
9686
":log_provider_static",
9787
"//fbandroid/libraries/fbjni:fbjni",
9888
"//fbandroid/native/fb:fb",
@@ -108,17 +98,44 @@ non_fbcode_target(_kind = fb_android_cxx_library,
10898
],
10999
)
110100

101+
non_fbcode_target(_kind = fb_android_cxx_library,
102+
name = "executorch_jni_core",
103+
srcs = ["jni_layer.cpp", "log.cpp"],
104+
compiler_flags = ET_JNI_COMPILER_FLAGS,
105+
preferred_linkage = "static",
106+
visibility = ["PUBLIC"],
107+
exported_deps = [
108+
":jni_headers",
109+
":log_provider_static",
110+
"//fbandroid/libraries/fbjni:fbjni",
111+
"//fbandroid/native/fb:fb",
112+
"//third-party/glog:glog",
113+
"//xplat/executorch/extension/module:module_static",
114+
"//xplat/executorch/extension/runner_util:inputs_static",
115+
"//xplat/executorch/extension/tensor:tensor_static",
116+
"//xplat/executorch/extension/threadpool:threadpool_static",
117+
third_party_dep("cpuinfo"),
118+
],
119+
)
120+
111121
non_fbcode_target(_kind = runtime.cxx_library,
112122
name = "log_provider",
113123
srcs = ["log.cpp"],
114124
exported_headers = ["log.h"],
115-
compiler_flags = [
116-
"-frtti",
117-
"-fexceptions",
118-
"-Wno-unused-variable",
119-
],
125+
compiler_flags = ET_JNI_COMPILER_FLAGS,
120126
deps = [
121127
"//executorch/runtime/core:core",
122128
],
123129
visibility = ["@EXECUTORCH_CLIENTS"],
124130
)
131+
132+
runtime.export_file(
133+
name = "jni_layer.cpp",
134+
)
135+
136+
runtime.cxx_library(
137+
name = "jni_headers",
138+
exported_headers = [
139+
"jni_layer_constants.h",
140+
]
141+
)

extension/android/jni/build_defs.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ET_JNI_COMPILER_FLAGS = [
2+
"-frtti",
3+
"-fexceptions",
4+
"-Wno-unused-variable",
5+
]

extension/android/jni/jni_layer.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9+
#include <executorch/extension/android/jni/jni_layer_constants.h>
10+
#include <executorch/extension/android/jni/log.h>
11+
#include <executorch/extension/module/module.h>
12+
#include <executorch/extension/runner_util/inputs.h>
13+
#include <executorch/extension/tensor/tensor.h>
14+
#include <executorch/runtime/core/portable_type/tensor_impl.h>
15+
#include <executorch/runtime/platform/log.h>
16+
#include <executorch/runtime/platform/platform.h>
17+
#include <executorch/runtime/platform/runtime.h>
918
#include <cassert>
1019
#include <chrono>
1120
#include <iostream>
@@ -15,16 +24,6 @@
1524
#include <unordered_map>
1625
#include <unordered_set>
1726
#include <vector>
18-
#include "jni_layer_constants.h"
19-
20-
#include <executorch/extension/android/jni/log.h>
21-
#include <executorch/extension/module/module.h>
22-
#include <executorch/extension/runner_util/inputs.h>
23-
#include <executorch/extension/tensor/tensor.h>
24-
#include <executorch/runtime/core/portable_type/tensor_impl.h>
25-
#include <executorch/runtime/platform/log.h>
26-
#include <executorch/runtime/platform/platform.h>
27-
#include <executorch/runtime/platform/runtime.h>
2827

2928
#ifdef ET_USE_THREADPOOL
3029
#include <cpuinfo.h>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
load("@fbcode_macros//build_defs:build_file_migration.bzl", "non_fbcode_target")
2+
load("@fbsource//tools/build_defs/android:fb_android_cxx_library.bzl", "fb_android_cxx_library")
3+
load("@fbsource//xplat/executorch/backends/xnnpack/third-party:third_party_libs.bzl", "third_party_dep")
4+
load("@fbsource//xplat/executorch/extension/android/jni:build_defs.bzl", "ET_JNI_COMPILER_FLAGS")
5+
6+
def selective_jni_target(name, deps, srcs = [], soname = "libexecutorch.$(ext)"):
7+
non_fbcode_target(_kind = fb_android_cxx_library,
8+
name = name,
9+
srcs = [
10+
"//xplat/executorch/extension/android/jni:jni_layer.cpp",
11+
] + srcs,
12+
allow_jni_merging = False,
13+
compiler_flags = ET_JNI_COMPILER_FLAGS,
14+
soname = soname,
15+
visibility = ["PUBLIC"],
16+
deps = [
17+
"//fbandroid/libraries/fbjni:fbjni",
18+
"//fbandroid/native/fb:fb",
19+
"//third-party/glog:glog",
20+
"//xplat/executorch/extension/android/jni:jni_headers",
21+
"//xplat/executorch/extension/android/jni:log_provider_static",
22+
"//xplat/executorch/extension/module:module_static",
23+
"//xplat/executorch/extension/runner_util:inputs_static",
24+
"//xplat/executorch/extension/tensor:tensor_static",
25+
"//xplat/executorch/extension/threadpool:threadpool_static",
26+
third_party_dep("cpuinfo"),
27+
] + deps,
28+
)

0 commit comments

Comments
 (0)