• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1load("//tensorflow:tensorflow.bzl", "py_test")
2load("//tensorflow/lite:special_rules.bzl", "tflite_portable_test_suite", "tflite_schema_utils_friends")
3load("@flatbuffers//:build_defs.bzl", "flatbuffer_cc_library")
4load("//tensorflow:tensorflow.bzl", "get_compatible_with_portable")
5
6# This is the package group declaration to which targets for TensorFlow Lite
7# Flatbuffer schema utilities.
8#
9# Its usage should be rare, and is often abused by tools that are doing
10# Flatbuffer creation/manipulation in unofficially supported ways.
11package_group(
12    name = "utils_friends",
13    packages = [
14        "//tensorflow/compiler/mlir/lite/...",
15        "//tensorflow/lite/...",
16    ] + tflite_schema_utils_friends(),
17)
18
19package(
20    default_visibility = [
21        "//visibility:public",
22    ],
23    licenses = ["notice"],  # Apache 2.0
24)
25
26py_binary(
27    name = "upgrade_schema",
28    srcs = ["upgrade_schema.py"],
29    python_version = "PY3",
30    deps = [":upgrade_schema_main_lib"],
31)
32
33py_library(
34    name = "upgrade_schema_main_lib",
35    srcs = [
36        "upgrade_schema.py",
37    ],
38    data = [
39        "schema_v0.fbs",
40        "schema_v1.fbs",
41        "schema_v2.fbs",
42        "schema_v3.fbs",
43        "@flatbuffers//:flatc",
44    ],
45    srcs_version = "PY3",
46    deps = [
47        "//tensorflow:tensorflow_py",
48        "//tensorflow/python:platform",
49    ],
50)
51
52py_test(
53    name = "upgrade_schema_test",
54    size = "small",
55    srcs = ["upgrade_schema_test.py"],
56    python_version = "PY3",
57    srcs_version = "PY3",
58    tags = [
59        "manual",
60        "no_oss",
61        "no_pip",
62        "notap",
63    ],
64    deps = [
65        ":upgrade_schema_main_lib",
66        "//tensorflow/python:client_testlib",
67        "//tensorflow/python:framework_test_lib",
68    ],
69)
70
71# copybara:uncomment_begin(google-only)
72# py_test(
73#     name = "schema_validation_test",
74#     srcs = ["schema_validation_test.py"],
75#     data = [
76#         "//tensorflow/lite/schema:schema_fbs_srcs",
77#         "//tensorflow/lite/schema:schema_generated.h.oss",
78#     ],
79#     python_version = "PY3",
80#     deps = [
81#         "//pyglib",
82#         "//testing/pybase",
83#     ],
84# )
85# copybara:uncomment_end
86
87exports_files([
88    "schema.fbs",
89    "schema_v0.fbs",
90    "schema_v1.fbs",
91    "schema_v2.fbs",
92    "schema_v3.fbs",
93    "schema_v3a.fbs",
94])
95
96flatbuffer_cc_library(
97    name = "schema_fbs",
98    srcs = ["schema.fbs"],
99    compatible_with = get_compatible_with_portable(),
100)
101
102# Generic schema for flatbuffer converter (but with mutable makes bigger).
103flatbuffer_cc_library(
104    name = "schema_fbs_with_mutable",
105    srcs = ["schema.fbs"],
106    compatible_with = get_compatible_with_portable(),
107    flatc_args = [
108        "--gen-mutable",
109        "--gen-object-api",
110    ],
111    out_prefix = "mutable/",
112)
113
114# Generic schema for inference on device (but with reflections makes bigger).
115flatbuffer_cc_library(
116    name = "schema_fbs_with_reflection",
117    srcs = ["schema.fbs"],
118    compatible_with = get_compatible_with_portable(),
119    flatc_args = [
120        "--reflect-types",
121        "--reflect-names",
122        "--no-union-value-namespacing",
123        "--gen-object-api",
124    ],
125    out_prefix = "reflection/",
126)
127
128# Schema test to make sure we don't introduce backward incompatible changes
129# to schemas.
130cc_test(
131    name = "flatbuffer_compatibility_test",
132    size = "small",
133    srcs = ["flatbuffer_compatibility_test.cc"],
134    data = [
135        "schema.fbs",
136        "schema_v3a.fbs",
137    ],
138    tags = [
139        "no_oss",
140        "tflite_not_portable_android",
141        "tflite_not_portable_ios",
142    ],
143    deps = [
144        "//tensorflow/core/platform",
145        "@com_google_googletest//:gtest",
146        "@flatbuffers//:flatc_library",
147    ],
148)
149
150cc_library(
151    name = "schema_utils",
152    srcs = ["schema_utils.cc"],
153    hdrs = ["schema_utils.h"],
154    compatible_with = get_compatible_with_portable(),
155    visibility = [":utils_friends"],
156    deps = [
157        ":schema_fbs",
158        "//tensorflow/lite/kernels/internal:compatibility",
159        "@flatbuffers//:runtime_cc",
160    ],
161)
162
163cc_library(
164    name = "schema_conversion_utils",
165    srcs = ["schema_conversion_utils.cc"],
166    hdrs = ["schema_conversion_utils.h"],
167    compatible_with = get_compatible_with_portable(),
168    visibility = [":utils_friends"],
169    deps = [
170        ":schema_fbs",
171        "//tensorflow/lite/kernels/internal:compatibility",
172        "@flatbuffers",
173    ],
174)
175
176tflite_portable_test_suite()
177