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 "libabsl", 137 "liblua", 138 "libtflite_static", 139 "libutf", 140 "marisa-trie", 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 "libabsl", 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: [ 260 "general-tests", 261 "mts-extservices", 262 ], 263 264 data: [ 265 "**/test_data/*", 266 "**/*.bfbs", 267 ], 268 269 srcs: ["**/*.cc"], 270 exclude_srcs: [":libtextclassifier_java_test_sources"], 271 272 header_libs: ["jni_headers"], 273 274 static_libs: [ 275 "libgmock_ndk", 276 "libgtest_ndk_c++", 277 "libbase_ndk", 278 ], 279 280 generated_headers: [ 281 "libtextclassifier_fbgen_utils_flatbuffers_flatbuffers_test", 282 "libtextclassifier_fbgen_utils_lua_utils_tests", 283 ], 284 285 compile_multilib: "both", 286 multilib: { 287 lib32: { 288 suffix: "32", 289 }, 290 lib64: { 291 suffix: "64", 292 }, 293 }, 294 // A workaround for code coverage. See b/166040889#comment23 295 sdk_variant_only: true, 296 test_config: "AndroidTest-tplus.xml", 297} 298 299cc_test { 300 name: "libtextclassifier_tests-sminus", 301 defaults: ["libtextclassifier_defaults"], 302 303 test_suites: [ 304 "general-tests", 305 "mts-extservices", 306 ], 307 308 data: [ 309 "**/test_data/*", 310 "**/*.bfbs", 311 ], 312 313 srcs: ["**/*.cc"], 314 exclude_srcs: [":libtextclassifier_java_test_sources"], 315 316 header_libs: ["jni_headers"], 317 318 static_libs: [ 319 "libgmock_ndk", 320 "libgtest_ndk_c++", 321 "libbase_ndk", 322 ], 323 324 generated_headers: [ 325 "libtextclassifier_fbgen_utils_flatbuffers_flatbuffers_test", 326 "libtextclassifier_fbgen_utils_lua_utils_tests", 327 ], 328 329 compile_multilib: "both", 330 multilib: { 331 lib32: { 332 suffix: "32", 333 }, 334 lib64: { 335 suffix: "64", 336 }, 337 }, 338 // A workaround for code coverage. See b/166040889#comment23 339 sdk_variant_only: true, 340 test_config: "AndroidTest-sminus.xml", 341} 342 343// ------------------------------------ 344// Native tests require the JVM to run 345// ------------------------------------ 346cc_test_library { 347 name: "libjvm_test_launcher", 348 defaults: ["libtextclassifier_defaults"], 349 srcs: [ 350 ":libtextclassifier_java_test_sources", 351 "annotator/datetime/testing/*.cc", 352 "actions/test-utils.cc", 353 "utils/testing/annotator.cc", 354 "utils/testing/logging_event_listener.cc", 355 "testing/jvm_test_launcher.cc", 356 ], 357 version_script: "jni.lds", 358 static_libs: [ 359 "libflatbuffers-cpp", 360 "libgmock_ndk", 361 "libgtest_ndk_c++", 362 "libbase_ndk", 363 "libtextclassifier", 364 ], 365 header_libs: [ 366 "libtextclassifier_flatbuffer_testonly_headers", 367 ], 368} 369 370android_test { 371 name: "libtextclassifier_java_tests", 372 srcs: ["testing/JvmTestLauncher.java"], 373 min_sdk_version: "30", 374 test_suites: [ 375 "general-tests", 376 "mts-extservices", 377 ], 378 static_libs: [ 379 "androidx.test.ext.junit", 380 "androidx.test.rules", 381 "androidx.test.espresso.core", 382 "androidx.test.ext.truth", 383 "truth", 384 "TextClassifierCoverageLib", 385 ], 386 jni_libs: [ 387 "libjvm_test_launcher", 388 ], 389 jni_uses_sdk_apis: true, 390 data: [ 391 "**/*.bfbs", 392 "**/test_data/*", 393 ], 394 test_config: "JavaTest.xml", 395 compile_multilib: "both", 396} 397 398// ---------------- 399// Annotator models 400// ---------------- 401 402prebuilt_etc { 403 name: "libtextclassifier_annotator_en_model", 404 filename: "textclassifier.en.model", 405 owner: "google", 406 src: "models/textclassifier.en.model", 407 sub_dir: "textclassifier", 408} 409 410prebuilt_etc { 411 name: "libtextclassifier_annotator_universal_model", 412 filename: "textclassifier.universal.model", 413 owner: "google", 414 src: "models/textclassifier.universal.model", 415 sub_dir: "textclassifier", 416} 417 418// --------------------------- 419// Actions Suggestions models 420// --------------------------- 421 422prebuilt_etc { 423 name: "libtextclassifier_actions_suggestions_universal_model", 424 filename: "actions_suggestions.universal.model", 425 owner: "google", 426 src: "models/actions_suggestions.universal.model", 427 sub_dir: "textclassifier", 428} 429 430// ------------ 431// LangId model 432// ------------ 433 434prebuilt_etc { 435 name: "libtextclassifier_lang_id_model", 436 filename: "lang_id.model", 437 owner: "google", 438 src: "models/lang_id.model", 439 sub_dir: "textclassifier", 440} 441 442build = [ 443 "FlatBufferHeaders.bp", 444 "JavaTests.bp", 445] 446