1# TensorFlow Lite for Objective-C 2 3load("//tensorflow/lite:special_rules.bzl", "ios_visibility_allowlist", "tflite_ios_lab_runner") 4load("//tensorflow/lite/ios:ios.bzl", "TFL_DEFAULT_TAGS", "TFL_DISABLED_SANITIZER_TAGS", "TFL_MINIMUM_OS_VERSION") 5load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application", "ios_unit_test") 6 7package( 8 default_visibility = ["//visibility:private"], 9 licenses = ["notice"], 10) 11 12SOURCES = glob([ 13 "sources/*.h", 14 "sources/*.m", 15 "sources/*.mm", 16]) 17 18API_HEADERS = glob([ 19 "apis/*.h", 20]) 21 22# Compiler flags for building regular non-test libraries. 23RELEASE_COPTS = [ 24 # Enables language-specific warnings for Objective-C, Objective-C++, C, and C++. 25 "-Wall", 26 # Warns if functions, variables, and types marked with the deprecated attribute are being used. 27 "-Wdeprecated-declarations", 28 # Warns for errors in documentation. 29 "-Wdocumentation", 30 # Turns all warnings into errors. 31 "-Werror", 32 # Enables extra warning flags that are not enabled by -Wall. 33 "-Wextra", 34 # Warns if a global function is defined without a previous prototype declaration. 35 "-Wmissing-prototypes", 36 # From -Wextra. Disables warning when signed value is converted to unsigned value during comparison. 37 "-Wno-sign-compare", 38 # From -Wextra. Disables warning for unused parameters, which are common in delegate methods and block callbacks. 39 "-Wno-unused-parameter", 40 # Warns if a global or local variable or type declaration shadows another variable, parameter, type, class member, or instance variable. 41 "-Wshadow", 42 # Warns if a function is declared or defined without specifying the argument types. For a block with no args, use (void) instead of (). 43 "-Wstrict-prototypes", 44 # Warns if an @selector() expression is encountered with a method name that hasn't been defined yet. 45 "-Wundeclared-selector", 46 # Turn off warnings for headers not part of TensorFlow Lite Objective-C API. 47 "--system-header-prefix=tensorflow/lite/c/", 48] 49 50# Compiler flags for building test libraries. 51TEST_COPTS = RELEASE_COPTS + [ 52 # From -Wall. Disables warning when passing nil to a callee that requires a non-null argument. 53 "-Wno-nonnull", 54 # Disables warning when a global or local variable or type declaration shadows another. 55 "-Wno-shadow", 56] 57 58objc_library( 59 name = "TensorFlowLite", 60 srcs = SOURCES, 61 hdrs = API_HEADERS, 62 copts = RELEASE_COPTS, 63 tags = TFL_DEFAULT_TAGS, 64 visibility = ios_visibility_allowlist(), 65 deps = [ 66 "//tensorflow/lite/c:c_api", 67 "//tensorflow/lite/c:c_api_experimental", 68 "//tensorflow/lite/delegates/coreml:coreml_delegate", 69 "//tensorflow/lite/delegates/gpu:metal_delegate", 70 "//tensorflow/lite/delegates/xnnpack:xnnpack_delegate", 71 ], 72 alwayslink = 1, 73) 74 75# NOTE: This test target name must be lower-cased in order to match it with the 76# directory name. (See: b/174508866) 77ios_unit_test( 78 name = "tests", 79 size = "medium", 80 minimum_os_version = TFL_MINIMUM_OS_VERSION, 81 runner = tflite_ios_lab_runner("IOS_LATEST"), 82 tags = TFL_DEFAULT_TAGS + TFL_DISABLED_SANITIZER_TAGS, 83 deps = [ 84 ":TestsLibrary", 85 ], 86) 87 88objc_library( 89 name = "TestsLibrary", 90 testonly = 1, 91 srcs = glob([ 92 "tests/*.m", 93 ]), 94 hdrs = glob([ 95 "apis/*.h", 96 "sources/*.h", 97 "tests/*.h", 98 ]), 99 copts = TEST_COPTS, 100 data = [ 101 "//tensorflow/lite:testdata/add.bin", 102 "//tensorflow/lite:testdata/add_quantized.bin", 103 "//tensorflow/lite:testdata/multi_signatures.bin", 104 ], 105 tags = TFL_DEFAULT_TAGS + ["builder_default_ios_x86_64"], 106 deps = [ 107 ":TensorFlowLite", 108 ], 109) 110 111ios_application( 112 name = "TestApp", 113 app_icons = glob(["apps/TestApp/TestApp/Assets.xcassets/AppIcon.appiconset/**"]), 114 bundle_id = "com.tensorflow.lite.objc.TestApp", 115 families = [ 116 "ipad", 117 "iphone", 118 ], 119 infoplists = ["apps/TestApp/TestApp/Info.plist"], 120 minimum_os_version = TFL_MINIMUM_OS_VERSION, 121 sdk_frameworks = ["CoreGraphics"], 122 tags = TFL_DEFAULT_TAGS, 123 deps = [":TestAppLibrary"], 124) 125 126objc_library( 127 name = "TestAppLibrary", 128 srcs = glob(["apps/TestApp/TestApp/*.m"]), 129 hdrs = glob(["apps/TestApp/TestApp/*.h"]), 130 data = glob(["apps/TestApp/TestApp/Base.lproj/*.storyboard"]) + [ 131 "//tensorflow/lite:testdata/add.bin", 132 "//tensorflow/lite:testdata/add_quantized.bin", 133 "//tensorflow/lite:testdata/multi_add.bin", 134 ], 135 includes = [ 136 "apis", 137 ], 138 module_name = "TestApp", 139 tags = TFL_DEFAULT_TAGS + [ 140 "manual", 141 "builder_default_ios_x86_64", 142 ], 143 deps = [ 144 ":TensorFlowLite", 145 ], 146) 147