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