• 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.neuralnetworks",
32        "test_com.android.neuralnetworks",
33    ],
34}
35
36cc_defaults {
37    name: "libtextclassifier_hash_defaults",
38    vendor_available: true,
39    host_supported: true,
40    srcs: [
41        "utils/hash/farmhash.cc",
42    ],
43    cflags: [
44        "-DNAMESPACE_FOR_HASH_FUNCTIONS=farmhash",
45        "-Wall",
46        "-Werror",
47        "-Wno-unused-function",
48    ],
49}
50
51cc_library_shared {
52    name: "libtextclassifier_hash",
53    defaults: ["libtextclassifier_hash_defaults"],
54    vendor_available: true,
55    double_loadable: true,
56}
57
58cc_library_static {
59    name: "libtextclassifier_hash_static",
60    defaults: ["libtextclassifier_hash_defaults"],
61    sdk_version: "current",
62    stl: "libc++_static",
63    apex_available: [
64        "//apex_available:platform",
65        "com.android.neuralnetworks",
66        "test_com.android.neuralnetworks",
67        "com.android.extservices",
68    ],
69}
70
71cc_defaults {
72    name: "libtextclassifier_defaults",
73    stl: "libc++_static",
74    sdk_version: "current",
75    // For debug / treemap purposes.
76    //strip: {
77    //    keep_symbols: true,
78    //},
79
80    cflags: [
81        "-Wall",
82        "-Werror",
83        "-Wno-deprecated-declarations",
84        "-Wno-ignored-qualifiers",
85        "-Wno-missing-field-initializers",
86        "-Wno-sign-compare",
87        "-Wno-tautological-constant-out-of-range-compare",
88        "-Wno-undefined-var-template",
89        "-Wno-unused-function",
90        "-Wno-unused-parameter",
91        "-Wno-extern-c-compat",
92
93        "-funsigned-char",
94        "-fvisibility=hidden",
95
96        "-DLIBTEXTCLASSIFIER_UNILIB_ICU",
97        "-DZLIB_CONST",
98        "-DSAFTM_COMPACT_LOGGING",
99        "-DTC3_WITH_ACTIONS_OPS",
100        "-DTC3_UNILIB_JAVAICU",
101        "-DTC3_CALENDAR_JAVAICU",
102        "-DTC3_AOSP",
103        "-DTC3_VOCAB_ANNOTATOR_IMPL",
104        "-DTC3_POD_NER_ANNOTATOR_IMPL",
105    ],
106
107    product_variables: {
108        debuggable: {
109            // Only enable debug logging in userdebug/eng builds.
110            cflags: ["-DTC3_DEBUG_LOGGING=1"],
111        },
112    },
113
114    header_libs: [
115        "jni_headers",
116        "tensorflow_headers",
117        "flatbuffer_headers",
118        "libtextclassifier_flatbuffer_headers",
119    ],
120
121    shared_libs: [
122        "liblog",
123        "libz",
124    ],
125
126    static_libs: [
127        "marisa-trie",
128        "libtextclassifier_abseil",
129        "liblua",
130        "libutf",
131        "libtflite_static",
132        "tflite_support"
133    ],
134}
135
136// -----------------
137// Generate headers with FlatBuffer schema compiler.
138// -----------------
139genrule_defaults {
140    name: "fbgen",
141    tools: ["flatc"],
142    // "depfile" is used here in conjunction with flatc's -M to gather the deps
143    cmd: "$(location flatc) --cpp --no-union-value-namespacing --gen-object-api --keep-prefix -I external/libtextclassifier/native -M $(in) >$(depfile) && " +
144        "$(location flatc) --cpp --no-union-value-namespacing --gen-object-api --keep-prefix -I external/libtextclassifier/native -o $$(dirname $(out)) $(in)",
145    depfile: true,
146}
147
148genrule {
149    name: "libtextclassifier_fbgen_utils_flatbuffers_flatbuffers_test",
150    srcs: ["utils/flatbuffers/flatbuffers_test.fbs"],
151    out: ["utils/flatbuffers/flatbuffers_test_generated.h"],
152    defaults: ["fbgen"],
153}
154
155genrule {
156    name: "libtextclassifier_fbgen_utils_lua_utils_tests",
157    srcs: ["utils/lua_utils_tests.fbs"],
158    out: ["utils/lua_utils_tests_generated.h"],
159    defaults: ["fbgen"],
160}
161
162// -----------------
163// libtextclassifier
164// -----------------
165cc_library {
166    name: "libtextclassifier",
167    defaults: ["libtextclassifier_defaults"],
168    min_sdk_version: "30",
169    srcs: ["**/*.cc"],
170    exclude_srcs: [
171        "**/*_test.*",
172        "**/*-test-lib.*",
173        "**/testing/*.*",
174        "**/*test-util.*",
175        "**/*test-utils.*",
176        "**/*test_util.*",
177        "**/*test_utils.*",
178        "**/*_test-include.*",
179        "**/*unittest.*",
180    ],
181
182    version_script: "jni.lds",
183
184    apex_available: [
185        "//apex_available:platform",
186        "com.android.extservices",
187    ],
188}
189
190// -----------------------
191// libtextclassifier_tests
192// -----------------------
193cc_test {
194    name: "libtextclassifier_tests",
195    defaults: ["libtextclassifier_defaults"],
196
197    test_suites: ["general-tests", "mts-extservices"],
198
199    data: [
200        "**/test_data/*",
201        "**/*.bfbs",
202    ],
203
204    srcs: ["**/*.cc"],
205    exclude_srcs: [":libtextclassifier_java_test_sources"],
206
207    header_libs: ["jni_headers"],
208
209    static_libs: [
210        "libgmock_ndk",
211        "libgtest_ndk_c++",
212        "libbase_ndk",
213    ],
214
215    generated_headers: [
216        "libtextclassifier_fbgen_utils_flatbuffers_flatbuffers_test",
217        "libtextclassifier_fbgen_utils_lua_utils_tests",
218    ],
219
220    compile_multilib: "prefer32",
221
222    // A workaround for code coverage. See b/166040889#comment23
223    sdk_variant_only: true,
224}
225
226// ------------------------------------
227// Native tests require the JVM to run
228// ------------------------------------
229cc_test_library {
230    name: "libjvm_test_launcher",
231    defaults: ["libtextclassifier_defaults"],
232    srcs: [
233        ":libtextclassifier_java_test_sources",
234        "annotator/datetime/testing/*.cc",
235        "actions/test-utils.cc",
236        "utils/testing/annotator.cc",
237        "utils/testing/logging_event_listener.cc",
238        "testing/jvm_test_launcher.cc",
239    ],
240    version_script: "jni.lds",
241    static_libs: [
242        "libgmock_ndk",
243        "libgtest_ndk_c++",
244        "libbase_ndk",
245        "libtextclassifier",
246    ],
247    header_libs: [
248        "libtextclassifier_flatbuffer_testonly_headers",
249    ],
250}
251
252android_test {
253    name: "libtextclassifier_java_tests",
254    srcs: ["testing/JvmTestLauncher.java"],
255    min_sdk_version: "30",
256    test_suites: [
257        "general-tests",
258        "mts-extservices",
259    ],
260    static_libs: [
261        "androidx.test.ext.junit",
262        "androidx.test.rules",
263        "androidx.test.espresso.core",
264        "androidx.test.ext.truth",
265        "truth-prebuilt",
266        "TextClassifierCoverageLib",
267    ],
268    jni_libs: [
269        "libjvm_test_launcher",
270    ],
271    jni_uses_sdk_apis: true,
272    data: [
273        "**/*.bfbs",
274        "**/test_data/*",
275    ],
276    test_config: "JavaTest.xml",
277    compile_multilib: "both",
278}
279
280// ----------------
281// Annotator models
282// ----------------
283
284prebuilt_etc {
285    name: "libtextclassifier_annotator_en_model",
286    filename: "textclassifier.en.model",
287    owner: "google",
288    src: "models/textclassifier.en.model",
289    sub_dir: "textclassifier",
290}
291
292prebuilt_etc {
293    name: "libtextclassifier_annotator_universal_model",
294    filename: "textclassifier.universal.model",
295    owner: "google",
296    src: "models/textclassifier.universal.model",
297    sub_dir: "textclassifier",
298}
299
300// ---------------------------
301// Actions Suggestions models
302// ---------------------------
303
304prebuilt_etc {
305    name: "libtextclassifier_actions_suggestions_universal_model",
306    filename: "actions_suggestions.universal.model",
307    owner: "google",
308    src: "models/actions_suggestions.universal.model",
309    sub_dir: "textclassifier",
310}
311
312// ------------
313// LangId model
314// ------------
315
316prebuilt_etc {
317    name: "libtextclassifier_lang_id_model",
318    filename: "lang_id.model",
319    owner: "google",
320    src: "models/lang_id.model",
321    sub_dir: "textclassifier",
322}
323
324build = ["FlatBufferHeaders.bp", "JavaTests.bp"]
325