xref: /aosp_15_r20/external/tensorflow/Android.bp (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1// Copyright (C) 2017 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package {
16    default_applicable_licenses: ["external_tensorflow_license"],
17}
18
19// Added automatically by a large-scale-change that took the approach of
20// 'apply every license found to every target'. While this makes sure we respect
21// every license restriction, it may not be entirely correct.
22//
23// e.g. GPL in an MIT project might only apply to the contrib/ directory.
24//
25// Please consider splitting the single license below into multiple licenses,
26// taking care not to lose any license_kind information, and overriding the
27// default license using the 'licenses: [...]' property on targets as needed.
28//
29// For unused files, consider creating a 'fileGroup' with "//visibility:private"
30// to attach the license to, and including a comment whether the files may be
31// used in the current project.
32//
33// large-scale-change included anything that looked like it might be a license
34// text as a license_text. e.g. LICENSE, NOTICE, COPYING etc.
35//
36// Please consider removing redundant or irrelevant files from 'license_text:'.
37//
38// large-scale-change filtered out the below license kinds as false-positives:
39//   SPDX-license-identifier-CC-BY-SA
40//   SPDX-license-identifier-MPL-2.0
41// See: http://go/android-license-faq
42license {
43    name: "external_tensorflow_license",
44    visibility: [":__subpackages__"],
45    license_kinds: [
46        "SPDX-license-identifier-Apache-2.0",
47        "SPDX-license-identifier-BSD",
48        "SPDX-license-identifier-MIT",
49        "legacy_unencumbered",
50    ],
51    license_text: [
52        "LICENSE",
53        "NOTICE",
54    ],
55}
56
57cc_library_headers {
58    name: "tensorflow_headers",
59    export_include_dirs: ["."],
60    vendor_available: true,
61    host_supported: true,
62    sdk_version: "current",
63    min_sdk_version: "apex_inherit",
64    apex_available: [
65        "//apex_available:platform",
66        "com.android.extservices",
67        "com.android.neuralnetworks",
68        "test_com.android.neuralnetworks",
69        "com.android.adservices",
70        "com.android.ondevicepersonalization",
71    ],
72}
73
74genrule {
75    name: "libtflite_mutable_schema",
76    tools: ["flatc"],
77    cmd: "$(location flatc) --cpp --no-union-value-namespacing --gen-object-api --gen-mutable --keep-prefix -o $$(dirname $(out)) $(in)",
78    srcs: ["tensorflow/lite/schema/schema.fbs"],
79    out: ["tensorflow/lite/schema/mutable/schema_generated.h"],
80}
81
82subdirs = ["tensorflow/lite"]
83
84filegroup {
85    name: "tensorflow_tsl_logging_srcs",
86    srcs: [
87        "tensorflow/tsl/platform/default/logging.cc",
88        "tensorflow/tsl/platform/default/env_time.cc",
89    ],
90}
91
92cc_library_static {
93    name: "TfliteNnapiDelegateTests_static",
94    srcs: [
95        "tensorflow/lite/delegates/nnapi/nnapi_delegate_test.cc",
96        "tensorflow/lite/kernels/test_delegate_providers.cc",
97        "tensorflow/lite/kernels/test_util.cc",
98        "tensorflow/lite/kernels/acceleration_test_util.cc",
99        "tensorflow/lite/kernels/acceleration_test_util_internal.cc",
100        "tensorflow/lite/delegates/nnapi/acceleration_test_list.cc",
101        "tensorflow/lite/delegates/nnapi/acceleration_test_util.cc",
102    ],
103    include_dirs: [
104        "external/flatbuffers/include",
105        "external/tensorflow",
106        "external/ruy",
107    ],
108    cflags: [
109        "-DPLATFORM_POSIX_ANDROID",
110        "-Wextra",
111        "-Wno-extern-c-compat",
112        "-Wno-sign-compare",
113        "-Wno-unused-parameter",
114        "-Wno-unused-private-field",
115    ],
116    shared_libs: [
117        "libandroid",
118        "liblog",
119        "libneuralnetworks",
120    ],
121    static_libs: [
122        "libabsl",
123        "libgtest_ndk_c++",
124        "libgmock_ndk",
125        "libtflite_static",
126    ],
127    header_libs: [
128        "libeigen",
129        "gemmlowp_headers",
130        "libtflite_schema_headers",
131    ],
132    sdk_version: "current",
133    stl: "c++_static",
134}
135
136cc_library_static {
137    name: "libtflite_flex_delegate",
138    srcs: [
139        ":tflite_src",
140        ":tflite_flex_delegate",
141        ":tensorflow_c_srcs",
142        ":tensorflow_c_eager_srcs",
143        ":tensorflow_core_data_mobile_srcs_no_runtime",
144        ":tensorflow_core_kernels_mobile_srcs",
145        ":tensorflow_core_common_runtime_mobile_srcs_only_runtime",
146        ":tensorflow_core_framework_mobile_srcs_only_runtime",
147        ":tensorflow_core_framework_mobile_srcs_no_runtime",
148        ":tensorflow_core_graph_mobile_srcs_only_runtime",
149        ":tensorflow_core_util_mobile_srcs_no_runtime",
150        ":tensorflow_core_util_mobile_srcs_only_runtime",
151        ":tensorflow_core_platform_mobile_srcs_no_runtime",
152        ":tensorflow_core_platform_mobile_srcs_only_runtime",
153        ":tensorflow_core_profiler_mobile_srcs_no_runtime",
154        ":tensorflow_core_tfrt_fallback_op_kernel_runner",
155        ":tensorflow_tsl_platform_default_mobile_srcs_no_runtime",
156        ":tensorflow_tsl_platform_default_mobile_srcs_only_runtime",
157        ":tensorflow_core_lib_io_mobile_src_only_runtime",
158        ":tensorflow_core_lib_mobile_src_only_runtime",
159        ":tensorflow_core_lib_mobile_src_no_runtime",
160        "tensorflow/core/nccl/collective_communicator.cc",
161        "tensorflow/core/example/feature_util.cc",
162        "tensorflow/core/ops/no_op.cc",
163        "tensorflow/core/ops/array_ops.cc",
164        "tensorflow/core/ops/parsing_ops.cc",
165        "tensorflow/core/ops/dataset_ops.cc",
166        "tensorflow/core/ops/function_ops.cc",
167        "tensorflow/core/ops/io_ops.cc",
168        "tensorflow/core/ops/nn_ops.cc",
169        "tensorflow/core/ops/string_ops.cc",
170        "tensorflow/core/lib/wav/wav_io.cc",
171        "tensorflow/compiler/jit/defs.cc",
172    ],
173    export_include_dirs: ["."],
174    whole_static_libs: [
175        "libabsl",
176        "libdoubleconversion",
177        "libfft2d",
178        "libruy_static",
179        "libtextclassifier_hash_static",
180        "tensorflow_core_proto_cpp_lite",
181    ],
182    header_libs: [
183        "fp16_headers",
184        "jni_headers",
185        "liblog_headers",
186    ],
187    generated_headers: ["libtflite_mutable_schema"],
188    shared_libs: [
189        "libz",
190    ],
191    include_dirs: [
192        "external/FP16",
193        "external/eigen",
194        "external/flatbuffers/include",
195        "external/gemmlowp",
196        "external/libtextclassifier/native/",
197        "external/tensorflow",
198        "external/neon_2_sse",
199    ],
200    cflags: [
201        "-DNAMESPACE_FOR_HASH_FUNCTIONS=farmhash",
202        "-DTF_ANDROID_ENABLE_LOGSINK",
203        "-DPLATFORM_POSIX_ANDROID",
204        "-DENABLE_ABSL_IN_TENSORFLOW",
205        "-DIS_MOBILE_PLATFORM",
206        "-DTF_ANDROID_ENABLE_LOG_EVERY_N_SECONDS",
207        // Used to support int64, string type in //tensorflow/core/framework/register_types.h.
208        "-D__ANDROID_TYPES_FULL__",
209        "-Wno-defaulted-function-deleted",
210        "-Wno-deprecated-builtins",
211        "-Wno-deprecated-declarations",
212        "-Wno-expansion-to-defined",
213        "-Wno-ignored-qualifiers",
214        "-Wno-missing-field-initializers",
215        "-Wno-mismatched-tags",
216        "-Wno-unused-const-variable",
217        "-Wno-unused-but-set-variable",
218        "-Wno-unused-parameter",
219        "-Wno-user-defined-warnings",
220        "-Wno-gnu-inline-cpp-without-extern",
221    ],
222    cpp_std: "gnu++17",
223    stl: "libc++_static",
224    min_sdk_version: "33",
225    sdk_version: "current",
226    apex_available: ["com.android.ondevicepersonalization"],
227}
228
229cc_library_static {
230    name: "tflite_configuration_proto",
231    proto: {
232        type: "lite",
233        canonical_path_from_root: false,
234        export_proto_headers: true,
235    },
236    stl: "libc++",
237    srcs: ["tensorflow/lite/experimental/acceleration/configuration/**/*.proto"],
238    sdk_version: "current",
239    min_sdk_version: "30",
240    apex_available: [
241        "com.android.adservices",
242        "com.android.extservices",
243    ],
244}
245
246filegroup {
247    name: "tensorflow_core_protobuf_src",
248    srcs: [
249        "tensorflow/core/protobuf/bfc_memory_map.proto",
250        "tensorflow/core/protobuf/config.proto",
251        "tensorflow/core/protobuf/coordination_config.proto",
252        "tensorflow/core/protobuf/coordination_service.proto",
253        "tensorflow/core/protobuf/cluster.proto",
254        "tensorflow/core/protobuf/debug.proto",
255        "tensorflow/core/protobuf/device_filters.proto",
256        "tensorflow/core/protobuf/device_properties.proto",
257        "tensorflow/core/protobuf/data_service.proto",
258        "tensorflow/core/protobuf/debug_event.proto",
259        "tensorflow/core/protobuf/eager_service.proto",
260        "tensorflow/core/protobuf/graph_debug_info.proto",
261        "tensorflow/core/protobuf/queue_runner.proto",
262        "tensorflow/core/protobuf/rewriter_config.proto",
263        "tensorflow/core/protobuf/tensor_bundle.proto",
264        "tensorflow/core/protobuf/saver.proto",
265        "tensorflow/core/protobuf/verifier_config.proto",
266        "tensorflow/core/protobuf/error_codes.proto",
267        "tensorflow/core/protobuf/composite_tensor_variant.proto",
268        "tensorflow/core/protobuf/master.proto",
269        "tensorflow/core/protobuf/meta_graph.proto",
270        "tensorflow/core/protobuf/named_tensor.proto",
271        "tensorflow/core/protobuf/remote_tensor_handle.proto",
272        "tensorflow/core/protobuf/saved_model.proto",
273        "tensorflow/core/protobuf/saved_object_graph.proto",
274        "tensorflow/core/protobuf/status.proto",
275        "tensorflow/core/protobuf/struct.proto",
276        "tensorflow/core/protobuf/worker.proto",
277        "tensorflow/core/protobuf/tensorflow_server.proto",
278        "tensorflow/core/protobuf/trackable_object_graph.proto",
279        "tensorflow/core/protobuf/transport_options.proto",
280        "tensorflow/core/grappler/costs/op_performance_data.proto",
281        "tensorflow/compiler/xla/pjrt/distributed/protocol.proto",
282        "tensorflow/compiler/xla/stream_executor/dnn.proto",
283    ],
284}
285
286cc_library_static {
287    name: "tensorflow_core_proto_cpp_lite",
288    proto: {
289        export_proto_headers: true,
290        canonical_path_from_root: false,
291        type: "lite",
292        include_dirs: ["external/protobuf/src"],
293    },
294    srcs: [
295        "tensorflow/core/framework/*.proto",
296        "tensorflow/core/example/example.proto",
297        "tensorflow/core/example/feature.proto",
298        "tensorflow/core/example/example_parser_configuration.proto",
299        "tensorflow/core/profiler/protobuf/xplane.proto",
300        "tensorflow/core/profiler/profiler_options.proto",
301        "tensorflow/core/util/saved_tensor_slice.proto",
302        "tensorflow/core/util/event.proto",
303        ":tensorflow_core_protobuf_src",
304        ":libprotobuf-internal-protos",
305    ],
306    shared_libs: [
307        "liblog",
308    ],
309    static_libs: [
310        "libprotobuf-cpp-lite-ndk",
311    ],
312    sdk_version: "current",
313    export_include_dirs: ["."],
314    stl: "libc++_static",
315    min_sdk_version: "33",
316    apex_available: ["com.android.ondevicepersonalization"],
317}
318
319java_library_static {
320    name: "tensorflow_core_proto_java_lite",
321    srcs: [
322        "tensorflow/core/framework/*.proto",
323        "tensorflow/core/example/example.proto",
324        "tensorflow/core/example/feature.proto",
325        "tensorflow/core/example/example_parser_configuration.proto",
326        "tensorflow/core/profiler/protobuf/xplane.proto",
327        "tensorflow/core/profiler/profiler_options.proto",
328        "tensorflow/core/util/saved_tensor_slice.proto",
329        "tensorflow/core/util/event.proto",
330        ":tensorflow_core_protobuf_src",
331        ":libprotobuf-internal-protos",
332    ],
333    proto: {
334        canonical_path_from_root: false,
335        include_dirs: [
336            "external/protobuf/src",
337            "external/protobuf/java",
338        ],
339        type: "lite",
340    },
341    static_libs: ["libprotobuf-java-lite"],
342    sdk_version: "current",
343    min_sdk_version: "33",
344    apex_available: ["com.android.ondevicepersonalization"],
345}
346
347// Clients that want to link in custom ops/delegates need to manually link in the JNI bridge
348// to their own custom shared libraries.
349filegroup {
350    name: "tensorflowlite_jni_src",
351    srcs: ["tensorflow/lite/java/src/main/native/*.cc"],
352    visibility: [
353        "//packages/modules/OnDevicePersonalization:__subpackages__",
354    ],
355}
356