• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# TensorFlow Lite for Objective-C
2
3load("//tensorflow/lite:special_rules.bzl", "ios_visibility_whitelist", "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"],  # Apache 2.0
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_whitelist(),
65    deps = [
66        "//tensorflow/lite/c:c_api",
67        "//tensorflow/lite/delegates/coreml:coreml_delegate",
68        "//tensorflow/lite/delegates/gpu:metal_delegate",
69        "//tensorflow/lite/delegates/xnnpack:xnnpack_delegate",
70    ],
71    alwayslink = 1,
72)
73
74# NOTE: This test target name must be lower-cased in order to match it with the
75# directory name. (See: b/174508866)
76ios_unit_test(
77    name = "tests",
78    size = "medium",
79    minimum_os_version = TFL_MINIMUM_OS_VERSION,
80    runner = tflite_ios_lab_runner("IOS_LATEST"),
81    tags = TFL_DEFAULT_TAGS + TFL_DISABLED_SANITIZER_TAGS,
82    deps = [
83        ":TestsLibrary",
84    ],
85)
86
87objc_library(
88    name = "TestsLibrary",
89    testonly = 1,
90    srcs = glob([
91        "tests/*.m",
92    ]),
93    hdrs = glob([
94        "apis/*.h",
95        "sources/*.h",
96        "tests/*.h",
97    ]),
98    copts = TEST_COPTS,
99    data = [
100        "//tensorflow/lite:testdata/add.bin",
101        "//tensorflow/lite:testdata/add_quantized.bin",
102    ],
103    tags = TFL_DEFAULT_TAGS + ["builder_default_ios_x86_64"],
104    deps = [
105        ":TensorFlowLite",
106    ],
107)
108
109ios_application(
110    name = "TestApp",
111    app_icons = glob(["apps/TestApp/TestApp/Assets.xcassets/AppIcon.appiconset/**"]),
112    bundle_id = "com.tensorflow.lite.objc.TestApp",
113    families = [
114        "ipad",
115        "iphone",
116    ],
117    infoplists = ["apps/TestApp/TestApp/Info.plist"],
118    minimum_os_version = TFL_MINIMUM_OS_VERSION,
119    sdk_frameworks = [
120        "CoreGraphics",
121    ],
122    tags = TFL_DEFAULT_TAGS,
123    deps = [
124        ":TestAppLibrary",
125    ],
126)
127
128objc_library(
129    name = "TestAppLibrary",
130    srcs = glob(["apps/TestApp/TestApp/*.m"]),
131    hdrs = glob(["apps/TestApp/TestApp/*.h"]),
132    data = glob(["apps/TestApp/TestApp/Base.lproj/*.storyboard"]) + [
133        "//tensorflow/lite:testdata/add.bin",
134        "//tensorflow/lite:testdata/add_quantized.bin",
135        "//tensorflow/lite:testdata/multi_add.bin",
136    ],
137    includes = [
138        "apis",
139    ],
140    module_name = "TestApp",
141    tags = TFL_DEFAULT_TAGS + [
142        "manual",
143        "builder_default_ios_x86_64",
144    ],
145    deps = [
146        ":TensorFlowLite",
147    ],
148)
149