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") 8 9package( 10 default_visibility = ["//visibility:public"], 11 licenses = ["notice"], # Apache 2.0 12) 13 14# Generates a platform-specific shared library containing the TensorFlow Lite C 15# API implementation as define in `c_api.h`. The exact output library name 16# is platform dependent: 17# - Linux/Android: `libtensorflowlite_c.so` 18# - Mac: `libtensorflowlite_c.dylib` 19# - Windows: `tensorflowlite_c.dll` 20tflite_cc_shared_object( 21 name = "tensorflowlite_c", 22 linkopts = select({ 23 "//tensorflow:ios": [ 24 "-Wl,-exported_symbols_list,$(location //tensorflow/lite/c:exported_symbols.lds)", 25 ], 26 "//tensorflow:macos": [ 27 "-Wl,-exported_symbols_list,$(location //tensorflow/lite/c:exported_symbols.lds)", 28 ], 29 "//tensorflow:windows": [], 30 "//conditions:default": [ 31 "-z defs", 32 "-Wl,--version-script,$(location //tensorflow/lite/c:version_script.lds)", 33 ], 34 }), 35 per_os_targets = True, 36 deps = [ 37 ":c_api", 38 ":c_api_experimental", 39 ":exported_symbols.lds", 40 ":version_script.lds", 41 ], 42) 43 44cc_library( 45 name = "c_api_internal", 46 hdrs = ["c_api_internal.h"], 47 copts = tflite_copts(), 48 visibility = ["//visibility:private"], 49 deps = [ 50 ":common", 51 "//tensorflow/lite:builtin_ops", 52 "//tensorflow/lite:framework", 53 "//tensorflow/lite/core/api", 54 ], 55) 56 57cc_library( 58 name = "c_api", 59 srcs = ["c_api.cc"], 60 hdrs = ["c_api.h"], 61 copts = tflite_copts(), 62 deps = [ 63 ":c_api_internal", 64 ":c_api_types", 65 "//tensorflow/lite:builtin_ops", 66 "//tensorflow/lite:create_op_resolver_with_builtin_ops", 67 "//tensorflow/lite:framework", 68 "//tensorflow/lite:version", 69 "//tensorflow/lite/delegates:interpreter_utils", 70 "//tensorflow/lite/delegates/nnapi:nnapi_delegate", 71 "//tensorflow/lite/kernels/internal:compatibility", 72 ], 73 alwayslink = 1, # Why?? TODO(b/161243354): eliminate this. 74) 75 76cc_library( 77 name = "c_api_experimental", 78 srcs = ["c_api_experimental.cc"], 79 hdrs = ["c_api_experimental.h"], 80 copts = tflite_copts(), 81 deps = [ 82 ":c_api", 83 ":c_api_internal", 84 ":common", 85 "//tensorflow/lite:framework", 86 "//tensorflow/lite:kernel_api", 87 ], 88 alwayslink = 1, # Why?? TODO(b/161243354): eliminate this. 89) 90 91cc_library( 92 name = "c_api_types", 93 hdrs = ["c_api_types.h"], 94 compatible_with = get_compatible_with_portable(), 95 copts = tflite_copts(), 96) 97 98cc_test( 99 name = "c_api_test", 100 size = "small", 101 srcs = ["c_api_test.cc"], 102 copts = tflite_copts(), 103 data = [ 104 "//tensorflow/lite:testdata/add.bin", 105 "//tensorflow/lite:testdata/add_quantized.bin", 106 ], 107 deps = [ 108 ":c_api", 109 ":common", 110 "//tensorflow/lite/testing:util", 111 "@com_google_googletest//:gtest", 112 ], 113) 114 115tflite_custom_c_library( 116 name = "selectively_built_c_api_test_lib", 117 testonly = 1, 118 models = [ 119 "//tensorflow/lite:testdata/add.bin", 120 "//tensorflow/lite:testdata/add_quantized.bin", 121 ], 122 visibility = ["//visibility:private"], 123) 124 125cc_test( 126 name = "selectively_built_c_api_test", 127 size = "small", 128 srcs = ["c_api_test.cc"], 129 copts = tflite_copts(), 130 data = [ 131 "//tensorflow/lite:testdata/add.bin", 132 "//tensorflow/lite:testdata/add_quantized.bin", 133 ], 134 deps = [ 135 ":common", 136 ":selectively_built_c_api_test_lib", 137 "//tensorflow/lite/testing:util", 138 "@com_google_googletest//:gtest", 139 ], 140) 141 142cc_test( 143 name = "c_api_experimental_test", 144 size = "small", 145 srcs = ["c_api_experimental_test.cc"], 146 copts = tflite_copts(), 147 data = ["//tensorflow/lite:testdata/add.bin"], 148 deps = [ 149 ":c_api", 150 ":c_api_experimental", 151 ":common", 152 "//tensorflow/lite:kernel_api", 153 "//tensorflow/lite/delegates:delegate_test_util", 154 "//tensorflow/lite/testing:util", 155 "@com_google_googletest//:gtest", 156 ], 157) 158 159cc_library( 160 name = "common", 161 srcs = ["common.c"], 162 hdrs = [ 163 "builtin_op_data.h", 164 "common.h", 165 ], 166 compatible_with = get_compatible_with_portable(), 167 copts = tflite_copts(), 168 deps = [ 169 ":c_api_types", 170 ], 171 alwayslink = 1, # Why?? TODO(b/161243354): eliminate this. 172) 173 174# For use with library targets that can't use relative paths. 175exports_files([ 176 "c_api.h", 177 "c_api_experimental.h", 178 "c_api_types.h", 179 "common.h", 180]) 181 182# For use in selective build rule for C API. 183filegroup( 184 name = "c_api_srcs", 185 srcs = [ 186 "c_api.cc", 187 "c_api_internal.h", 188 ], 189) 190 191# Test the C extension API code. 192cc_test( 193 name = "common_test", 194 size = "small", 195 srcs = ["common_test.cc"], 196 deps = [ 197 ":common", 198 "@com_google_googletest//:gtest", 199 ], 200) 201 202cc_test( 203 name = "builtin_op_data_test", 204 size = "small", 205 srcs = ["builtin_op_data_test.cc"], 206 copts = ["-Wno-unused-variable"], 207 deps = [ 208 ":common", 209 "@com_google_googletest//:gtest", 210 ], 211) 212 213cc_test( 214 name = "c_test", 215 size = "small", 216 srcs = ["c_test.c"], 217 copts = tflite_copts(), 218 data = [ 219 "//tensorflow/lite:testdata/add.bin", 220 ], 221 deps = [ 222 ":c_api", 223 ":c_api_experimental", 224 ":common", 225 ], 226) 227