|
| 1 | +load( |
| 2 | + "//tensorflow/lite/micro:build_def.bzl", |
| 3 | + "tflm_cc_library", |
| 4 | + "tflm_cc_test", |
| 5 | +) |
| 6 | +load( |
| 7 | + "@flatbuffers//:build_defs.bzl", |
| 8 | + "flatbuffer_cc_library", |
| 9 | + "flatbuffer_py_library", |
| 10 | +) |
| 11 | +load("@rules_python//python:defs.bzl", "py_test") |
| 12 | +load("@tflm_pip_deps//:requirements.bzl", "requirement") |
| 13 | + |
| 14 | +package( |
| 15 | + default_visibility = [ |
| 16 | + "//visibility:public", |
| 17 | + ], |
| 18 | +) |
| 19 | + |
| 20 | +flatbuffer_cc_library( |
| 21 | + # Generates the header-only library "metadata_generated.h", used to read |
| 22 | + # the metadata flatbuffer. |
| 23 | + name = "metadata_cc", |
| 24 | + srcs = ["metadata.fbs"], |
| 25 | +) |
| 26 | + |
| 27 | +tflm_cc_library( |
| 28 | + # The header-only library generated by flatc in ":metadata_cc" is saved to |
| 29 | + # the source tree and comitted to git as "metadata_saved.h", which is used |
| 30 | + # by code which builds via the Make build system, which has no means of |
| 31 | + # generating the header on the fly. Code which builds via both bazel and |
| 32 | + # Make should #include the saved header and use this target in its bazel |
| 33 | + # BUILD deps. Code built exclusively via bazel would typically depend |
| 34 | + # directly on ":metadata_cc", which would generate a header from the schema |
| 35 | + # on the fly, during the build. |
| 36 | + # |
| 37 | + # When the schema definition "metadata.fbs" is changed, this saved header |
| 38 | + # should be updated by running the script "./metadata_saved_update.sh", |
| 39 | + # outside of bazel (because bazel cannot modify the source tree). The |
| 40 | + # script regenerates the header from the schema and copies it to the source |
| 41 | + # tree as "metadata_saved.h". |
| 42 | + # |
| 43 | + # Comitting the generated file risks inconsistency between the schema and |
| 44 | + # the saved header, so consistency ensured by the unit test |
| 45 | + # ":metadata_saved_test". |
| 46 | + # |
| 47 | + name = "metadata_saved", |
| 48 | + hdrs = ["metadata_saved.h"], |
| 49 | +) |
| 50 | + |
| 51 | +sh_test( |
| 52 | + # Ensures consistency bewteen the schema and the saved generated header. |
| 53 | + # Fails if they mismatch, in which case, ./metadata_saved_update.sh should |
| 54 | + # be run. See :metadata_saved above. |
| 55 | + name = "metadata_saved_test", |
| 56 | + size = "small", |
| 57 | + srcs = ["metadata_saved_test.sh"], |
| 58 | + args = [ |
| 59 | + "$(location metadata_saved.h)", |
| 60 | + "$(location :metadata_cc_srcs)", |
| 61 | + ], |
| 62 | + data = [ |
| 63 | + "metadata_saved.h", |
| 64 | + ":metadata_cc_srcs", |
| 65 | + ], |
| 66 | +) |
| 67 | + |
| 68 | +tflm_cc_test( |
| 69 | + name = "metadata_test_cc", |
| 70 | + size = "small", |
| 71 | + srcs = ["metadata_test.cc"], |
| 72 | + deps = [ |
| 73 | + ":metadata_saved", |
| 74 | + "//tensorflow/lite/micro:hexdump", |
| 75 | + "//tensorflow/lite/micro/testing:micro_test", |
| 76 | + "@flatbuffers//:runtime_cc", |
| 77 | + ], |
| 78 | +) |
| 79 | + |
| 80 | +flatbuffer_py_library( |
| 81 | + # Generates the Python module "metadata_py_generated", used to read the |
| 82 | + # metadata flatbuffer. |
| 83 | + name = "metadata_py", |
| 84 | + srcs = ["metadata.fbs"], |
| 85 | +) |
| 86 | + |
| 87 | +py_test( |
| 88 | + name = "metadata_test_py", |
| 89 | + size = "small", |
| 90 | + srcs = ["metadata_test.py"], |
| 91 | + main = "metadata_test.py", |
| 92 | + deps = [ |
| 93 | + "metadata_py", |
| 94 | + "@flatbuffers//:runtime_py", |
| 95 | + requirement("hexdump"), |
| 96 | + ], |
| 97 | +) |
0 commit comments