Add jni_binary_with_tflite and android_library_with_tflite to the shim target macros
PiperOrigin-RevId: 369266726
Change-Id: I67e70a802027211f2b5f38dfc553e79e2cea11b4
diff --git a/tensorflow/lite/core/shims/cc_library_with_tflite.bzl b/tensorflow/lite/core/shims/cc_library_with_tflite.bzl
index 7f20190..dcc0501 100644
--- a/tensorflow/lite/core/shims/cc_library_with_tflite.bzl
+++ b/tensorflow/lite/core/shims/cc_library_with_tflite.bzl
@@ -1,7 +1,45 @@
-"""Definitions for cc_library/cc_test targets that use the TFLite shims."""
+"""Definitions for targets that use the TFLite shims."""
+
+load("//tensorflow/lite:build_def.bzl", "tflite_jni_binary")
+load("@build_bazel_rules_android//android:rules.bzl", "android_library")
+
+def android_library_with_tflite(
+ name,
+ deps = [],
+ tflite_deps = [],
+ exports = [],
+ tflite_exports = [],
+ **kwargs):
+ """Defines an android_library that uses the TFLite shims.
+
+ This is a hook to allow applying different build flags (etc.)
+ for targets that use the TFLite shims.
+
+ Note that this build rule doesn't itself add any dependencies on
+ TF Lite; this macro should normally be used in conjunction with a
+ direct or indirect 'tflite_deps' dependency on one of the "shim"
+ library targets from //third_party/tensorflow/lite/core/shims:*.
+
+ Args:
+ name: as for android_library.
+ deps: as for android_library.
+ tflite_deps: dependencies on rules that are themselves defined using
+ 'cc_library_with_tflite' / 'android_library_with_tflite'.
+ exports: same as for android_library.
+ tflite_exports: exported dependencies that are themselves defined using
+ 'cc_library_with_tflite' / 'android_library_with_tflite'.
+ **kwargs: Additional android_library parameters.
+ """
+ android_library(
+ name = name,
+ deps = deps + tflite_deps,
+ **kwargs
+ )
def cc_library_with_tflite(
name,
+ srcs = [],
+ tflite_jni_binaries = [],
deps = [],
tflite_deps = [],
**kwargs):
@@ -17,6 +55,9 @@
Args:
name: as for cc_library.
+ srcs: as for cc_library.
+ tflite_jni_binaries: dependencies on shared libraries that are defined
+ using 'jni_binary_with_tflite'.
deps: as for cc_library.
tflite_deps: dependencies on rules that are themselves defined using
'cc_library_with_tflite'.
@@ -24,6 +65,7 @@
"""
native.cc_library(
name = name,
+ srcs = srcs + tflite_jni_binaries,
deps = deps + tflite_deps,
**kwargs
)
@@ -39,7 +81,7 @@
for targets that use the TFLite shims.
Note that this build rule doesn't itself add any dependencies on
- TF Lite this macro should normally be used in conjunction with a
+ TF Lite; this macro should normally be used in conjunction with a
direct or indirect 'tflite_deps' dependency on one of the "shim"
library targets from //third_party/tensorflow/lite/core/shims:*.
@@ -55,3 +97,31 @@
deps = deps + tflite_deps,
**kwargs
)
+
+def jni_binary_with_tflite(
+ name,
+ deps = [],
+ tflite_deps = [],
+ **kwargs):
+ """Defines a tflite_jni_binary that uses the TFLite shims.
+
+ This is a hook to allow applying different build flags (etc.)
+ for targets that use the TFLite shims.
+
+ Note that this build rule doesn't itself add any dependencies on
+ TF Lite; this macro should normally be used in conjunction with a
+ direct or indirect 'tflite_deps' dependency on one of the "shim"
+ library targets from //third_party/tensorflow/lite/core/shims:*.
+
+ Args:
+ name: as for tflite_jni_binary.
+ deps: as for tflite_jni_binary.
+ tflite_deps: dependencies on rules that are themselves defined using
+ 'cc_library_with_tflite'.
+ **kwargs: Additional tflite_jni_binary parameters.
+ """
+ tflite_jni_binary(
+ name = name,
+ deps = deps + tflite_deps,
+ **kwargs
+ )