1load( 2 "//tensorflow/lite:build_def.bzl", 3 "tflite_cc_shared_object", 4 "tflite_copts", 5 "tflite_custom_c_library", 6) 7load("//tensorflow:tensorflow.bzl", "get_compatible_with_portable") 8load("//tensorflow/lite:special_rules.bzl", "tflite_portable_test_suite") 9 10package( 11 default_visibility = ["//visibility:public"], 12 licenses = ["notice"], 13) 14 15# Generates a platform-specific shared library containing the TensorFlow Lite C 16# API implementation as define in `c_api.h`. The exact output library name 17# is platform dependent: 18# - Linux/Android: `libtensorflowlite_c.so` 19# - Mac: `libtensorflowlite_c.dylib` 20# - Windows: `tensorflowlite_c.dll` 21tflite_cc_shared_object( 22 name = "tensorflowlite_c", 23 linkopts = select({ 24 "//tensorflow:ios": [ 25 "-Wl,-exported_symbols_list,$(location //tensorflow/lite/c:exported_symbols.lds)", 26 ], 27 "//tensorflow:macos": [ 28 "-Wl,-exported_symbols_list,$(location //tensorflow/lite/c:exported_symbols.lds)", 29 ], 30 "//tensorflow:windows": [], 31 "//conditions:default": [ 32 "-z defs", 33 "-Wl,--version-script,$(location //tensorflow/lite/c:version_script.lds)", 34 ], 35 }), 36 per_os_targets = True, 37 deps = [ 38 ":c_api", 39 ":c_api_experimental", 40 ":exported_symbols.lds", 41 ":version_script.lds", 42 ], 43) 44 45cc_library( 46 name = "c_api", 47 hdrs = [ 48 "c_api.h", 49 "c_api_opaque.h", 50 ], 51 copts = tflite_copts(), 52 deps = [ 53 ":c_api_types", 54 ":c_api_without_op_resolver", 55 ":common", 56 "//tensorflow/lite:create_op_resolver_with_builtin_ops", 57 "//tensorflow/lite/kernels:kernel_util", 58 ], 59 alwayslink = 1, # Why?? TODO(b/161243354): eliminate this. 60) 61 62cc_library( 63 name = "c_api_for_testing", 64 testonly = True, 65 srcs = ["c_api_for_testing.cc"], 66 hdrs = ["c_api_for_testing.h"], 67 deps = [ 68 ":c_api", 69 ":c_api_internal", 70 ], 71) 72 73cc_library( 74 name = "c_api_without_op_resolver", 75 srcs = ["c_api.cc"], 76 hdrs = ["c_api.h"], 77 copts = tflite_copts(), 78 deps = [ 79 ":c_api_internal", 80 ":c_api_types", 81 ":common", 82 ":common_internal", 83 "//tensorflow/lite:builtin_ops", 84 "//tensorflow/lite:create_op_resolver_header", 85 "//tensorflow/lite:framework", 86 "//tensorflow/lite:version", 87 "//tensorflow/lite/delegates:interpreter_utils", 88 "//tensorflow/lite/delegates/nnapi:nnapi_delegate", 89 "//tensorflow/lite/kernels:kernel_util", 90 "//tensorflow/lite/kernels/internal:compatibility", 91 ], 92 alwayslink = 1, # Why?? TODO(b/161243354): eliminate this. 93) 94 95cc_library( 96 name = "c_api_experimental", 97 srcs = [ 98 "c_api_experimental.cc", 99 "c_api_opaque.cc", 100 ], 101 hdrs = [ 102 "c_api_experimental.h", 103 "c_api_opaque.h", 104 ], 105 copts = tflite_copts(), 106 deps = [ 107 ":c_api", 108 ":c_api_internal", 109 ":c_api_types", 110 ":common", 111 "//tensorflow/lite:builtin_ops", 112 "//tensorflow/lite:framework", 113 "//tensorflow/lite:kernel_api", 114 "//tensorflow/lite/kernels:kernel_util", 115 ], 116 alwayslink = 1, # Why?? TODO(b/161243354): eliminate this. 117) 118 119cc_library( 120 name = "c_api_types", 121 hdrs = ["c_api_types.h"], 122 compatible_with = get_compatible_with_portable(), 123 copts = tflite_copts(), 124) 125 126cc_library( 127 name = "c_api_internal", 128 hdrs = ["c_api_internal.h"], 129 copts = tflite_copts(), 130 visibility = ["//visibility:private"], 131 deps = [ 132 ":common", 133 "//tensorflow/lite:builtin_ops", 134 "//tensorflow/lite:framework", 135 "//tensorflow/lite/core/api", 136 ], 137) 138 139filegroup( 140 name = "c_api_test_builtin_op_models", 141 testonly = 1, 142 srcs = [ 143 "//tensorflow/lite:testdata/add.bin", 144 "//tensorflow/lite:testdata/add_quantized.bin", 145 ], 146) 147 148cc_test( 149 name = "c_api_test", 150 size = "small", 151 srcs = ["c_api_test.cc"], 152 copts = tflite_copts(), 153 data = [ 154 "//tensorflow/lite:testdata/add.bin", 155 "//tensorflow/lite:testdata/add_quantized.bin", 156 "//tensorflow/lite:testdata/custom_sinh.bin", 157 ], 158 deps = [ 159 ":c_api", 160 ":c_api_experimental", 161 ":c_api_internal", 162 ":common", 163 "//tensorflow/lite/testing:util", 164 "@com_google_googletest//:gtest_main", 165 ], 166) 167 168tflite_custom_c_library( 169 name = "selectively_built_c_api_test_lib", 170 testonly = 1, 171 models = [":c_api_test_builtin_op_models"], 172 visibility = ["//visibility:private"], 173) 174 175cc_test( 176 name = "selectively_built_c_api_test", 177 size = "small", 178 srcs = ["c_api_test.cc"], 179 copts = tflite_copts(), 180 data = [ 181 "//tensorflow/lite:testdata/add.bin", 182 "//tensorflow/lite:testdata/add_quantized.bin", 183 "//tensorflow/lite:testdata/custom_sinh.bin", 184 ], 185 deps = [ 186 ":common", 187 ":selectively_built_c_api_test_lib", 188 "//tensorflow/lite/testing:util", 189 "@com_google_googletest//:gtest_main", 190 ], 191) 192 193cc_test( 194 name = "c_api_experimental_test", 195 size = "small", 196 srcs = ["c_api_experimental_test.cc"], 197 copts = tflite_copts(), 198 data = ["//tensorflow/lite:testdata/add.bin"], 199 deps = [ 200 ":c_api", 201 ":c_api_experimental", 202 ":common", 203 "//tensorflow/lite:kernel_api", 204 "//tensorflow/lite/delegates:delegate_test_util", 205 "//tensorflow/lite/testing:util", 206 "@com_google_googletest//:gtest_main", 207 ], 208) 209 210cc_test( 211 name = "c_api_signature_runner_test", 212 size = "small", 213 srcs = ["c_api_signature_runner_test.cc"], 214 copts = tflite_copts(), 215 data = ["//tensorflow/lite:testdata/multi_signatures.bin"], 216 deps = [ 217 ":c_api", 218 ":c_api_experimental", 219 "@com_google_googletest//:gtest_main", 220 ], 221) 222 223cc_library( 224 name = "common", 225 srcs = ["common.cc"], 226 hdrs = [ 227 "builtin_op_data.h", 228 "common.h", 229 ], 230 compatible_with = get_compatible_with_portable(), 231 copts = tflite_copts(), 232 deps = [ 233 ":c_api_types", 234 ] + select({ 235 "//tensorflow/lite:tensorflow_profiler_config": [ 236 "//tensorflow/lite:macros", 237 "//tensorflow/lite:tensorflow_profiler_logger_shim", 238 ], 239 "//conditions:default": [], 240 }), 241 alwayslink = 1, # Why?? TODO(b/161243354): eliminate this. 242) 243 244cc_library( 245 name = "common_internal", 246 hdrs = ["common_internal.h"], 247 compatible_with = get_compatible_with_portable(), 248 copts = tflite_copts(), 249 visibility = ["//tensorflow/lite:__pkg__"], 250 deps = [ 251 ":c_api_types", 252 ":common", 253 ], 254) 255 256# For use with library targets that can't use relative paths. 257exports_files([ 258 "c_api.h", 259 "c_api_internal.h", 260 "c_api_opaque.h", 261 "c_api_experimental.h", 262 "c_api_opaque.h", 263 "c_api_types.h", 264 "common.h", 265]) 266 267# For use in selective build rule for C API. 268filegroup( 269 name = "c_api_srcs", 270 srcs = [ 271 "c_api.cc", 272 "c_api_experimental.cc", 273 "c_api_opaque.cc", 274 "common_internal.h", 275 ], 276) 277 278# Test the C extension API code. 279cc_test( 280 name = "common_test", 281 size = "small", 282 srcs = ["common_test.cc"], 283 deps = [ 284 ":c_api_types", 285 ":common", 286 "@com_google_googletest//:gtest_main", 287 ], 288) 289 290cc_test( 291 name = "builtin_op_data_test", 292 size = "small", 293 srcs = ["builtin_op_data_test.cc"], 294 copts = ["-Wno-unused-variable"], 295 deps = [ 296 ":common", 297 "@com_google_googletest//:gtest_main", 298 ], 299) 300 301cc_test( 302 name = "c_test", 303 size = "small", 304 srcs = ["c_test.c"], 305 copts = tflite_copts(), 306 data = [ 307 "//tensorflow/lite:testdata/add.bin", 308 "//tensorflow/lite:testdata/multi_signatures.bin", 309 ], 310 tags = [ 311 # Testing on Android uses "--gunit_output=xml:test.xml" runtime flag, 312 # but this test is C code, not C++, and hence doesn't use GUnit, 313 # so doesn't support that flag. 314 "tflite_not_portable_android", 315 ], 316 deps = [ 317 ":c_api", 318 ":c_api_experimental", 319 ":common", 320 ], 321) 322 323tflite_portable_test_suite() 324