Skip to content

Commit 3176bc6

Browse files
committed
build: shim android portable tensorflow libs
1 parent 077003a commit 3176bc6

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

scripts/patch_tfjava.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,85 @@ def patch_workspace(path: Path) -> None:
903903
"""
904904

905905

906+
ANDROID_PORTABLE_LIB_SHIM_PATCH = """--- a/tensorflow/core/BUILD
907+
+++ b/tensorflow/core/BUILD
908+
@@ -1378,7 +1378,10 @@
909+
cc_library(
910+
name = "portable_tensorflow_lib_lite",
911+
- srcs = if_mobile([":mobile_srcs"]),
912+
+ srcs = select({
913+
+ "//tensorflow:android": [],
914+
+ "//conditions:default": if_mobile([":mobile_srcs"]),
915+
+ }),
916+
copts = tf_copts(android_optimization_level_override = None) + tf_opts_nortti_if_lite_protos() + if_ios(["-Os"]),
917+
defines = ["SUPPORT_SELECTIVE_REGISTRATION"] + tf_portable_full_lite_protos(
918+
full = [],
919+
@@ -1390,11 +1393,22 @@
920+
"notap",
921+
],
922+
visibility = ["//visibility:public"],
923+
- deps = [
924+
- ":protos_all_cc_impl",
925+
- "//tensorflow/core/util:stats_calculator_portable",
926+
- "//tensorflow/core:mobile_additional_lib_deps",
927+
- ] + tf_portable_deps_no_runtime(),
928+
+ deps = select({
929+
+ "//tensorflow:android": [
930+
+ ":core_cpu",
931+
+ ":core_cpu_internal",
932+
+ ":framework",
933+
+ ":framework_internal",
934+
+ ":lib",
935+
+ ":lib_internal",
936+
+ ":protos_all_cc",
937+
+ ],
938+
+ "//conditions:default": [
939+
+ ":protos_all_cc_impl",
940+
+ "//tensorflow/core/util:stats_calculator_portable",
941+
+ "//tensorflow/core:mobile_additional_lib_deps",
942+
+ ] + tf_portable_deps_no_runtime(),
943+
+ }),
944+
alwayslink = 1,
945+
)
946+
@@ -1485,7 +1499,10 @@
947+
cc_library(
948+
name = "portable_tensorflow_lib",
949+
- srcs = if_mobile([":portable_op_registrations_and_gradients"]),
950+
+ srcs = select({
951+
+ "//tensorflow:android": [],
952+
+ "//conditions:default": if_mobile([":portable_op_registrations_and_gradients"]),
953+
+ }),
954+
copts = tf_copts() + tf_opts_nortti_if_lite_protos(),
955+
features = tf_features_nomodules_if_mobile(),
956+
tags = [
957+
@@ -1494,12 +1511,16 @@
958+
"notap",
959+
],
960+
visibility = ["//visibility:public"],
961+
- deps = [
962+
- ":portable_tensorflow_lib_lite",
963+
- ":protos_all_cc_impl",
964+
- "//tensorflow/core/kernels:portable_tensorflow_kernels",
965+
- "//third_party/eigen3",
966+
- "@com_google_protobuf//:protobuf",
967+
- ],
968+
+ deps = select({
969+
+ "//tensorflow:android": [
970+
+ ":portable_tensorflow_lib_lite",
971+
+ ],
972+
+ "//conditions:default": [
973+
+ ":portable_tensorflow_lib_lite",
974+
+ ":protos_all_cc_impl",
975+
+ "//tensorflow/core/kernels:portable_tensorflow_kernels",
976+
+ "//third_party/eigen3",
977+
+ "@com_google_protobuf//:protobuf",
978+
+ ],
979+
+ }),
980+
alwayslink = 1,
981+
)
982+
"""
983+
984+
906985
def write_tensorflow_android_absl_patch(path: Path) -> None:
907986
path.parent.mkdir(parents=True, exist_ok=True)
908987
absl_patch_text = (
@@ -929,6 +1008,7 @@ def write_tensorflow_android_absl_patch(path: Path) -> None:
9291008
text += TF_C_API_EXPERIMENTAL_CC_PATCH
9301009
text += SAVED_MODEL_ANDROID_LOADER_PATCH
9311010
text += TENSORFLOW_FRAMEWORK_ANDROID_PATCH
1011+
text += ANDROID_PORTABLE_LIB_SHIM_PATCH
9321012
if not text.endswith("\n"):
9331013
text += "\n"
9341014
path.write_text(text, encoding="utf-8")

0 commit comments

Comments
 (0)