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