• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    // See: http://go/android-license-faq
17    // A large-scale-change added 'default_applicable_licenses' to import
18    // all of the 'license_kinds' from "external_libtextclassifier_license"
19    // to get the below license kinds:
20    //   SPDX-license-identifier-Apache-2.0
21    default_applicable_licenses: ["external_libtextclassifier_license"],
22}
23
24cc_library_headers {
25    name: "libtextclassifier_hash_headers",
26    vendor_available: true,
27    host_supported: true,
28    export_include_dirs: ["."],
29    apex_available: [
30        "//apex_available:platform",
31        "com.android.btservices",
32        "com.android.neuralnetworks",
33        "test_com.android.neuralnetworks",
34        "com.android.ondevicepersonalization",
35    ],
36    min_sdk_version: "apex_inherit",
37    sdk_version: "current",
38}
39
40cc_defaults {
41    name: "libtextclassifier_hash_defaults",
42    vendor_available: true,
43    host_supported: true,
44    srcs: [
45        "utils/hash/farmhash.cc",
46    ],
47    cflags: [
48        "-DNAMESPACE_FOR_HASH_FUNCTIONS=farmhash",
49        "-Wall",
50        "-Werror",
51        "-Wno-unused-function",
52    ],
53}
54
55cc_library_shared {
56    name: "libtextclassifier_hash",
57    defaults: ["libtextclassifier_hash_defaults"],
58    vendor_available: true,
59    double_loadable: true,
60}
61
62cc_library_static {
63    name: "libtextclassifier_hash_static",
64    defaults: ["libtextclassifier_hash_defaults"],
65    sdk_version: "current",
66    stl: "libc++_static",
67    min_sdk_version: "apex_inherit",
68    apex_available: [
69        "//apex_available:platform",
70        "com.android.btservices",
71        "com.android.neuralnetworks",
72        "test_com.android.neuralnetworks",
73        "com.android.extservices",
74        "com.android.adservices",
75        "com.android.ondevicepersonalization",
76    ],
77}
78
79cc_defaults {
80    name: "libtextclassifier_defaults",
81    stl: "libc++_static",
82    cpp_std: "gnu++17",
83    sdk_version: "current",
84    // For debug / treemap purposes.
85    //strip: {
86    //    keep_symbols: true,
87    //},
88
89    cflags: [
90        "-Wall",
91        "-Werror",
92        "-Wno-deprecated-declarations",
93        "-Wno-ignored-qualifiers",
94        "-Wno-missing-field-initializers",
95        "-Wno-sign-compare",
96        "-Wno-tautological-constant-out-of-range-compare",
97        "-Wno-undefined-var-template",
98        "-Wno-unused-function",
99        "-Wno-unused-parameter",
100        "-Wno-extern-c-compat",
101
102        "-funsigned-char",
103        "-fvisibility=hidden",
104
105        "-DLIBTEXTCLASSIFIER_UNILIB_ICU",
106        "-DZLIB_CONST",
107        "-DSAFTM_COMPACT_LOGGING",
108        "-DTC3_WITH_ACTIONS_OPS",
109        "-DTC3_UNILIB_JAVAICU",
110        "-DTC3_CALENDAR_JAVAICU",
111        "-DTC3_AOSP",
112        "-DTC3_VOCAB_ANNOTATOR_IMPL",
113        "-DTC3_POD_NER_ANNOTATOR_IMPL",
114    ],
115
116    product_variables: {
117        debuggable: {
118            // Only enable debug logging in userdebug/eng builds.
119            cflags: ["-DTC3_DEBUG_LOGGING=1"],
120        },
121    },
122
123    header_libs: [
124        "jni_headers",
125        "tensorflow_headers",
126        "flatbuffer_headers",
127        "libtextclassifier_flatbuffer_headers",
128    ],
129
130    shared_libs: [
131        "liblog",
132        "libz",
133    ],
134
135    static_libs: [
136        "marisa-trie",
137        "libtextclassifier_abseil",
138        "liblua",
139        "libutf",
140        "libtflite_static",
141        "tflite_support"
142    ],
143}
144
145cc_library_static {
146    name: "libtextclassifier_bert_tokenizer",
147    export_include_dirs: ["."],
148    visibility: ["//external/tflite-support:__subpackages__"],
149    srcs: [
150        "utils/base/logging.cc",
151        "utils/base/logging_raw.cc",
152        "utils/bert_tokenizer.cc",
153        "utils/strings/utf8.cc",
154        "utils/tokenizer-utils.cc",
155        "utils/utf8/unilib-common.cc",
156        "utils/utf8/unicodetext.cc",
157        "utils/wordpiece_tokenizer.cc",
158    ],
159    apex_available: [
160        "//apex_available:platform",
161        "com.android.extservices",
162        "com.android.adservices",
163    ],
164    cflags: [
165        "-Wno-ignored-qualifiers",
166        "-Wno-missing-field-initializers",
167        "-Wno-unused-parameter",
168
169        "-DLIBTEXTCLASSIFIER_UNILIB_ICU",
170        "-DZLIB_CONST",
171        "-DSAFTM_COMPACT_LOGGING",
172        "-DTC3_WITH_ACTIONS_OPS",
173        "-DTC3_UNILIB_JAVAICU",
174        "-DTC3_CALENDAR_JAVAICU",
175        "-DTC3_AOSP",
176        "-DTC3_VOCAB_ANNOTATOR_IMPL",
177        "-DTC3_POD_NER_ANNOTATOR_IMPL",
178    ],
179    product_variables: {
180        debuggable: {
181            // Only enable debug logging in userdebug/eng builds.
182            cflags: ["-DTC3_DEBUG_LOGGING=1"],
183        },
184    },
185    header_libs: [
186        "jni_headers",
187        "tensorflow_headers",
188        "flatbuffer_headers",
189        "libtextclassifier_flatbuffer_headers",
190    ],
191    static_libs: [
192        "libtextclassifier_abseil",
193        "tflite_support",
194    ],
195    sdk_version: "current",
196    min_sdk_version: "30",
197    stl: "libc++_static",
198}
199
200// -----------------
201// Generate headers with FlatBuffer schema compiler.
202// -----------------
203
204FBGEN_ARGS = "$(location flatc) --cpp --no-union-value-namespacing --gen-object-api --keep-prefix -I external/libtextclassifier/native -o $$(dirname $(out)) "
205
206genrule {
207    name: "libtextclassifier_fbgen_utils_flatbuffers_flatbuffers_test",
208    srcs: ["utils/flatbuffers/flatbuffers_test.fbs"],
209    out: ["utils/flatbuffers/flatbuffers_test_generated.h"],
210    tools: ["flatc"],
211    cmd: FBGEN_ARGS + "$(in)"
212}
213
214genrule {
215    name: "libtextclassifier_fbgen_utils_lua_utils_tests",
216    srcs: ["utils/lua_utils_tests.fbs"],
217    out: ["utils/lua_utils_tests_generated.h"],
218    tools: ["flatc"],
219    cmd: FBGEN_ARGS + "$(in)"
220}
221
222// -----------------
223// libtextclassifier
224// -----------------
225cc_library {
226    name: "libtextclassifier",
227    defaults: ["libtextclassifier_defaults"],
228    min_sdk_version: "30",
229    srcs: ["**/*.cc"],
230    exclude_srcs: [
231        "**/*_test.*",
232        "**/*-test-lib.*",
233        "**/testing/*.*",
234        "**/*test-util.*",
235        "**/*test-utils.*",
236        "**/*test_util.*",
237        "**/*test_utils.*",
238        "**/*_test-include.*",
239        "**/*unittest.*",
240    ],
241    static_libs: [
242        "libflatbuffers-cpp",
243    ],
244    version_script: "jni.lds",
245
246    apex_available: [
247        "//apex_available:platform",
248        "com.android.extservices",
249    ],
250}
251
252// -----------------------
253// libtextclassifier_tests
254// -----------------------
255cc_test {
256    name: "libtextclassifier_tests-tplus",
257    defaults: ["libtextclassifier_defaults"],
258
259    test_suites: ["general-tests", "mts-extservices"],
260
261    data: [
262        "**/test_data/*",
263        "**/*.bfbs",
264    ],
265
266    srcs: ["**/*.cc"],
267    exclude_srcs: [":libtextclassifier_java_test_sources"],
268
269    header_libs: ["jni_headers"],
270
271    static_libs: [
272        "libgmock_ndk",
273        "libgtest_ndk_c++",
274        "libbase_ndk",
275    ],
276
277    generated_headers: [
278        "libtextclassifier_fbgen_utils_flatbuffers_flatbuffers_test",
279        "libtextclassifier_fbgen_utils_lua_utils_tests",
280    ],
281
282    compile_multilib: "both",
283    multilib: {
284        lib32: {
285            suffix: "32",
286        },
287        lib64: {
288            suffix: "64",
289        },
290    },
291    // A workaround for code coverage. See b/166040889#comment23
292    sdk_variant_only: true,
293    test_config: "AndroidTest-tplus.xml",
294}
295
296cc_test {
297    name: "libtextclassifier_tests-sminus",
298    defaults: ["libtextclassifier_defaults"],
299
300    test_suites: ["general-tests", "mts-extservices"],
301
302    data: [
303        "**/test_data/*",
304        "**/*.bfbs",
305    ],
306
307    srcs: ["**/*.cc"],
308    exclude_srcs: [":libtextclassifier_java_test_sources"],
309
310    header_libs: ["jni_headers"],
311
312    static_libs: [
313        "libgmock_ndk",
314        "libgtest_ndk_c++",
315        "libbase_ndk",
316    ],
317
318    generated_headers: [
319        "libtextclassifier_fbgen_utils_flatbuffers_flatbuffers_test",
320        "libtextclassifier_fbgen_utils_lua_utils_tests",
321    ],
322
323    compile_multilib: "both",
324    multilib: {
325        lib32: {
326            suffix: "32",
327        },
328        lib64: {
329            suffix: "64",
330        },
331    },
332    // A workaround for code coverage. See b/166040889#comment23
333    sdk_variant_only: true,
334    test_config: "AndroidTest-sminus.xml",
335}
336
337// ------------------------------------
338// Native tests require the JVM to run
339// ------------------------------------
340cc_test_library {
341    name: "libjvm_test_launcher",
342    defaults: ["libtextclassifier_defaults"],
343    srcs: [
344        ":libtextclassifier_java_test_sources",
345        "annotator/datetime/testing/*.cc",
346        "actions/test-utils.cc",
347        "utils/testing/annotator.cc",
348        "utils/testing/logging_event_listener.cc",
349        "testing/jvm_test_launcher.cc",
350    ],
351    version_script: "jni.lds",
352    static_libs: [
353        "libflatbuffers-cpp",
354        "libgmock_ndk",
355        "libgtest_ndk_c++",
356        "libbase_ndk",
357        "libtextclassifier",
358    ],
359    header_libs: [
360        "libtextclassifier_flatbuffer_testonly_headers",
361    ],
362}
363
364android_test {
365    name: "libtextclassifier_java_tests",
366    srcs: ["testing/JvmTestLauncher.java"],
367    min_sdk_version: "30",
368    test_suites: [
369        "general-tests",
370        "mts-extservices",
371    ],
372    static_libs: [
373        "androidx.test.ext.junit",
374        "androidx.test.rules",
375        "androidx.test.espresso.core",
376        "androidx.test.ext.truth",
377        "truth",
378        "TextClassifierCoverageLib",
379    ],
380    jni_libs: [
381        "libjvm_test_launcher",
382    ],
383    jni_uses_sdk_apis: true,
384    data: [
385        "**/*.bfbs",
386        "**/test_data/*",
387    ],
388    test_config: "JavaTest.xml",
389    compile_multilib: "both",
390}
391
392// ----------------
393// Annotator models
394// ----------------
395
396prebuilt_etc {
397    name: "libtextclassifier_annotator_en_model",
398    filename: "textclassifier.en.model",
399    owner: "google",
400    src: "models/textclassifier.en.model",
401    sub_dir: "textclassifier",
402}
403
404prebuilt_etc {
405    name: "libtextclassifier_annotator_universal_model",
406    filename: "textclassifier.universal.model",
407    owner: "google",
408    src: "models/textclassifier.universal.model",
409    sub_dir: "textclassifier",
410}
411
412// ---------------------------
413// Actions Suggestions models
414// ---------------------------
415
416prebuilt_etc {
417    name: "libtextclassifier_actions_suggestions_universal_model",
418    filename: "actions_suggestions.universal.model",
419    owner: "google",
420    src: "models/actions_suggestions.universal.model",
421    sub_dir: "textclassifier",
422}
423
424// ------------
425// LangId model
426// ------------
427
428prebuilt_etc {
429    name: "libtextclassifier_lang_id_model",
430    filename: "lang_id.model",
431    owner: "google",
432    src: "models/lang_id.model",
433    sub_dir: "textclassifier",
434}
435
436build = ["FlatBufferHeaders.bp", "JavaTests.bp"]
437