From 13a4688fc32642ca9ca415ae77d445b95f31600c Mon Sep 17 00:00:00 2001 From: Austin Anderson Date: Wed, 22 Aug 2018 14:43:45 -0700 Subject: Convert TensorFlow's flatbuffers dependency to new third party import method PiperOrigin-RevId: 209833197 --- third_party/flatbuffers/BUILD | 16 +- third_party/flatbuffers/BUILD.bazel | 155 +++++++++++++ third_party/flatbuffers/BUILD.system | 38 +++ third_party/flatbuffers/build_defs.bzl | 368 ++++++++++++++++-------------- third_party/flatbuffers/flatbuffers.BUILD | 152 ------------ third_party/flatbuffers/workspace.bzl | 19 ++ third_party/systemlibs/flatbuffers.BUILD | 38 --- 7 files changed, 406 insertions(+), 380 deletions(-) create mode 100644 third_party/flatbuffers/BUILD.bazel create mode 100644 third_party/flatbuffers/BUILD.system delete mode 100644 third_party/flatbuffers/flatbuffers.BUILD create mode 100644 third_party/flatbuffers/workspace.bzl delete mode 100644 third_party/systemlibs/flatbuffers.BUILD (limited to 'third_party') diff --git a/third_party/flatbuffers/BUILD b/third_party/flatbuffers/BUILD index fbdf19f205..82bab3ffd9 100644 --- a/third_party/flatbuffers/BUILD +++ b/third_party/flatbuffers/BUILD @@ -1,15 +1 @@ -package(default_visibility = ["//visibility:public"]) - -licenses(["notice"]) # Apache 2.0 - -filegroup( - name = "all_files", - srcs = glob( - ["**/*"], - exclude = [ - "**/METADATA", - "**/OWNERS", - ], - ), - visibility = ["//tensorflow:__subpackages__"], -) +# This empty BUILD file is required to make Bazel treat this directory as a package. diff --git a/third_party/flatbuffers/BUILD.bazel b/third_party/flatbuffers/BUILD.bazel new file mode 100644 index 0000000000..9d233a30d6 --- /dev/null +++ b/third_party/flatbuffers/BUILD.bazel @@ -0,0 +1,155 @@ +package( + default_visibility = ["//visibility:public"], +) + +licenses(["notice"]) # Apache 2.0 + +exports_files(["LICENSE.txt"]) + +config_setting( + name = "freebsd", + values = {"cpu": "freebsd"}, + visibility = ["//visibility:public"], +) + +config_setting( + name = "windows", + values = {"cpu": "x64_windows"}, +) + +FLATBUFFERS_COPTS = select({ + ":windows": [], + "//conditions:default": [ + "-Wno-implicit-fallthrough", + "-fexceptions", + ], +}) + +# Public flatc library to compile flatbuffer files at runtime. +cc_library( + name = "flatbuffers", + srcs = [ + "include/flatbuffers/code_generators.h", + "include/flatbuffers/reflection_generated.h", + "src/code_generators.cpp", + "src/idl_gen_fbs.cpp", + "src/idl_gen_general.cpp", + "src/idl_gen_text.cpp", + "src/idl_parser.cpp", + "src/reflection.cpp", + "src/util.cpp", + ], + hdrs = [ + "include/flatbuffers/base.h", + "include/flatbuffers/flatbuffers.h", + "include/flatbuffers/flexbuffers.h", + "include/flatbuffers/hash.h", + "include/flatbuffers/idl.h", + "include/flatbuffers/reflection.h", + "include/flatbuffers/stl_emulation.h", + "include/flatbuffers/util.h", + ], + copts = FLATBUFFERS_COPTS, + includes = ["include/"], +) + +# Public flatc compiler library. +cc_library( + name = "flatc_library", + srcs = [ + "grpc/src/compiler/config.h", + "grpc/src/compiler/go_generator.h", + "grpc/src/compiler/schema_interface.h", + "include/flatbuffers/base.h", + "include/flatbuffers/code_generators.h", + "include/flatbuffers/flatbuffers.h", + "include/flatbuffers/flatc.h", + "include/flatbuffers/flexbuffers.h", + "include/flatbuffers/hash.h", + "include/flatbuffers/idl.h", + "include/flatbuffers/reflection.h", + "include/flatbuffers/reflection_generated.h", + "include/flatbuffers/stl_emulation.h", + "include/flatbuffers/util.h", + "src/code_generators.cpp", + "src/flatc.cpp", + "src/idl_gen_fbs.cpp", + "src/idl_parser.cpp", + "src/reflection.cpp", + "src/util.cpp", + ], + hdrs = [ + "include/flatbuffers/base.h", + "include/flatbuffers/code_generators.h", + "include/flatbuffers/flatbuffers.h", + "include/flatbuffers/flatc.h", + "include/flatbuffers/idl.h", + "include/flatbuffers/reflection.h", + "include/flatbuffers/stl_emulation.h", + "include/flatbuffers/util.h", + ], + copts = FLATBUFFERS_COPTS, + includes = [ + "grpc/", + "include/", + ], +) + +# Public flatc compiler. +cc_binary( + name = "flatc", + srcs = [ + "grpc/src/compiler/cpp_generator.cc", + "grpc/src/compiler/cpp_generator.h", + "grpc/src/compiler/go_generator.cc", + "grpc/src/compiler/go_generator.h", + "grpc/src/compiler/java_generator.cc", + "grpc/src/compiler/java_generator.h", + "grpc/src/compiler/schema_interface.h", + "src/flatc_main.cpp", + "src/idl_gen_cpp.cpp", + "src/idl_gen_general.cpp", + "src/idl_gen_go.cpp", + "src/idl_gen_grpc.cpp", + "src/idl_gen_js.cpp", + "src/idl_gen_json_schema.cpp", + "src/idl_gen_php.cpp", + "src/idl_gen_python.cpp", + "src/idl_gen_text.cpp", + ], + copts = FLATBUFFERS_COPTS, + includes = [ + "grpc/", + "include/", + ], + linkopts = select({ + ":freebsd": [ + "-lm", + ], + ":windows": [], + "//conditions:default": [ + "-lm", + "-ldl", + ], + }), + deps = [ + ":flatc_library", + ], +) + +filegroup( + name = "runtime_cc_srcs", + srcs = [ + "include/flatbuffers/base.h", + "include/flatbuffers/flatbuffers.h", + "include/flatbuffers/stl_emulation.h", + "include/flatbuffers/util.h", + ], +) + +cc_library( + name = "runtime_cc", + hdrs = ["runtime_cc_srcs"], + includes = ["include"], + linkstatic = 1, +) diff --git a/third_party/flatbuffers/BUILD.system b/third_party/flatbuffers/BUILD.system new file mode 100644 index 0000000000..14fceada82 --- /dev/null +++ b/third_party/flatbuffers/BUILD.system @@ -0,0 +1,38 @@ +licenses(["notice"]) # Apache 2.0 + +filegroup( + name = "LICENSE.txt", + visibility = ["//visibility:public"], +) + +# Public flatc library to compile flatbuffer files at runtime. +cc_library( + name = "flatbuffers", + linkopts = ["-lflatbuffers"], + visibility = ["//visibility:public"], +) + +# Public flatc compiler library. +cc_library( + name = "flatc_library", + linkopts = ["-lflatbuffers"], + visibility = ["//visibility:public"], +) + +genrule( + name = "lnflatc", + outs = ["flatc.bin"], + cmd = "ln -s $$(which flatc) $@", +) + +# Public flatc compiler. +sh_binary( + name = "flatc", + srcs = ["flatc.bin"], + visibility = ["//visibility:public"], +) + +cc_library( + name = "runtime_cc", + visibility = ["//visibility:public"], +) diff --git a/third_party/flatbuffers/build_defs.bzl b/third_party/flatbuffers/build_defs.bzl index ae8d7feebe..2f25156668 100644 --- a/third_party/flatbuffers/build_defs.bzl +++ b/third_party/flatbuffers/build_defs.bzl @@ -1,5 +1,4 @@ -# Description: -# BUILD rules for generating flatbuffer files. +"""BUILD rules for generating flatbuffer files.""" flatc_path = "@flatbuffers//:flatc" @@ -8,66 +7,50 @@ DEFAULT_FLATC_ARGS = [ "--gen-object-api", ] -def flatbuffer_library_public(name, - srcs, - outs, - language_flag, - out_prefix="", - includes=[], - include_paths=[], - flatc_args=DEFAULT_FLATC_ARGS, - reflection_name="", - reflection_visiblity=None, - output_to_bindir=False): - '''Generates code files for reading/writing the given flatbuffers in the requested language using the public compiler. - - Args: - name: Rule name. - srcs: Source .fbs files. Sent in order to the compiler. - outs: Output files from flatc. - language_flag: Target language flag. One of [-c, -j, -js]. - out_prefix: Prepend this path to the front of all generated files except on - single source targets. Usually is a directory name. - includes: Optional, list of filegroups of schemas that the srcs depend on. - include_paths: Optional, list of paths the includes files can be found in. - flatc_args: Optional, list of additional arguments to pass to flatc. - reflection_name: Optional, if set this will generate the flatbuffer - reflection binaries for the schemas. - reflection_visiblity: The visibility of the generated reflection Fileset. - output_to_bindir: Passed to genrule for output to bin directory. - Outs: - filegroup(name): all generated source files. - Fileset([reflection_name]): (Optional) all generated reflection binaries. - ''' - include_paths_cmd = ["-I %s" % (s) for s in include_paths] - # '$(@D)' when given a single source target will give the appropriate - # directory. Appending 'out_prefix' is only necessary when given a build - # target with multiple sources. - output_directory = ( - ("-o $(@D)/%s" % (out_prefix)) if len(srcs) > 1 else ("-o $(@D)")) - genrule_cmd = " ".join([ - "for f in $(SRCS); do", - "$(location %s)" % (flatc_path), - " ".join(flatc_args), - " ".join(include_paths_cmd), - language_flag, - output_directory, - "$$f;", - "done", - ]) - native.genrule( - name=name, - srcs=srcs, - outs=outs, - output_to_bindir=output_to_bindir, - tools=includes + [flatc_path,], - cmd=genrule_cmd, - message="Generating flatbuffer files for %s:" % (name),) - if reflection_name: - reflection_genrule_cmd = " ".join([ +def flatbuffer_library_public( + name, + srcs, + outs, + language_flag, + out_prefix = "", + includes = [], + include_paths = [], + flatc_args = DEFAULT_FLATC_ARGS, + reflection_name = "", + reflection_visiblity = None, + output_to_bindir = False): + """Generates code files for reading/writing the given flatbuffers in the requested language using the public compiler. + + Outs: + filegroup(name): all generated source files. + Fileset([reflection_name]): (Optional) all generated reflection binaries. + + Args: + name: Rule name. + srcs: Source .fbs files. Sent in order to the compiler. + outs: Output files from flatc. + language_flag: Target language flag. One of [-c, -j, -js]. + out_prefix: Prepend this path to the front of all generated files except on + single source targets. Usually is a directory name. + includes: Optional, list of filegroups of schemas that the srcs depend on. + include_paths: Optional, list of paths the includes files can be found in. + flatc_args: Optional, list of additional arguments to pass to flatc. + reflection_name: Optional, if set this will generate the flatbuffer + reflection binaries for the schemas. + reflection_visiblity: The visibility of the generated reflection Fileset. + output_to_bindir: Passed to genrule for output to bin directory. + """ + include_paths_cmd = ["-I %s" % (s) for s in include_paths] + + # '$(@D)' when given a single source target will give the appropriate + # directory. Appending 'out_prefix' is only necessary when given a build + # target with multiple sources. + output_directory = ( + ("-o $(@D)/%s" % (out_prefix)) if len(srcs) > 1 else ("-o $(@D)") + ) + genrule_cmd = " ".join([ "for f in $(SRCS); do", "$(location %s)" % (flatc_path), - "-b --schema", " ".join(flatc_args), " ".join(include_paths_cmd), language_flag, @@ -75,122 +58,157 @@ def flatbuffer_library_public(name, "$$f;", "done", ]) - reflection_outs = [ - (out_prefix + "%s.bfbs") % (s.replace(".fbs", "").split("/")[-1]) for s in srcs - ] native.genrule( - name= "%s_srcs" % reflection_name, - srcs=srcs, - outs=reflection_outs, - output_to_bindir=output_to_bindir, - tools=includes + [flatc_path,], - cmd=reflection_genrule_cmd, - message="Generating flatbuffer reflection binary for %s:" % (name),) - native.Fileset( - name=reflection_name, - out="%s_out" % reflection_name, - entries=[ - native.FilesetEntry(files=reflection_outs), - ], - visibility=reflection_visiblity + name = name, + srcs = srcs, + outs = outs, + output_to_bindir = output_to_bindir, + tools = includes + [flatc_path], + cmd = genrule_cmd, + message = "Generating flatbuffer files for %s:" % (name), ) + if reflection_name: + reflection_genrule_cmd = " ".join([ + "for f in $(SRCS); do", + "$(location %s)" % (flatc_path), + "-b --schema", + " ".join(flatc_args), + " ".join(include_paths_cmd), + language_flag, + output_directory, + "$$f;", + "done", + ]) + reflection_outs = [ + (out_prefix + "%s.bfbs") % (s.replace(".fbs", "").split("/")[-1]) + for s in srcs + ] + native.genrule( + name = "%s_srcs" % reflection_name, + srcs = srcs, + outs = reflection_outs, + output_to_bindir = output_to_bindir, + tools = includes + [flatc_path], + cmd = reflection_genrule_cmd, + message = "Generating flatbuffer reflection binary for %s:" % (name), + ) + native.Fileset( + name = reflection_name, + out = "%s_out" % reflection_name, + entries = [ + native.FilesetEntry(files = reflection_outs), + ], + visibility = reflection_visiblity, + ) + +def flatbuffer_cc_library( + name, + srcs, + srcs_filegroup_name = "", + out_prefix = "", + includes = [], + include_paths = [], + flatc_args = DEFAULT_FLATC_ARGS, + visibility = None, + srcs_filegroup_visibility = None, + gen_reflections = False): + '''A cc_library with the generated reader/writers for the given flatbuffer definitions. + + Outs: + filegroup([name]_srcs): all generated .h files. + filegroup(srcs_filegroup_name if specified, or [name]_includes if not): + Other flatbuffer_cc_library's can pass this in for their `includes` + parameter, if they depend on the schemas in this library. + Fileset([name]_reflection): (Optional) all generated reflection binaries. + cc_library([name]): library with sources and flatbuffers deps. + + Remarks: + ** Because the genrule used to call flatc does not have any trivial way of + computing the output list of files transitively generated by includes and + --gen-includes (the default) being defined for flatc, the --gen-includes + flag will not work as expected. The way around this is to add a dependency + to the flatbuffer_cc_library defined alongside the flatc included Fileset. + For example you might define: + + flatbuffer_cc_library( + name = "my_fbs", + srcs = [ "schemas/foo.fbs" ], + includes = [ "//third_party/bazz:bazz_fbs_includes" ], + ) + In which foo.fbs includes a few files from the Fileset defined at + //third_party/bazz:bazz_fbs_includes. When compiling the library that + includes foo_generated.h, and therefore has my_fbs as a dependency, it + will fail to find any of the bazz *_generated.h files unless you also + add bazz's flatbuffer_cc_library to your own dependency list, e.g.: -def flatbuffer_cc_library(name, srcs, srcs_filegroup_name="", - out_prefix="", includes=[], include_paths=[], - flatc_args=DEFAULT_FLATC_ARGS, - visibility=None, srcs_filegroup_visibility=None, - gen_reflections=False): - '''A cc_library with the generated reader/writers for the given flatbuffer definitions. - - Args: - name: Rule name. - srcs: Source .fbs files. Sent in order to the compiler. - srcs_filegroup_name: Name of the output filegroup that holds srcs. Pass this - filegroup into the `includes` parameter of any other - flatbuffer_cc_library that depends on this one's schemas. - out_prefix: Prepend this path to the front of all generated files. Usually - is a directory name. - includes: Optional, list of filegroups of schemas that the srcs depend on. - ** SEE REMARKS BELOW ** - include_paths: Optional, list of paths the includes files can be found in. - flatc_args: Optional list of additional arguments to pass to flatc - (e.g. --gen-mutable). - visibility: The visibility of the generated cc_library. By default, use the - default visibility of the project. - srcs_filegroup_visibility: The visibility of the generated srcs filegroup. - By default, use the value of the visibility parameter above. - gen_reflections: Optional, if true this will generate the flatbuffer - reflection binaries for the schemas. - Outs: - filegroup([name]_srcs): all generated .h files. - filegroup(srcs_filegroup_name if specified, or [name]_includes if not): - Other flatbuffer_cc_library's can pass this in for their `includes` - parameter, if they depend on the schemas in this library. - Fileset([name]_reflection): (Optional) all generated reflection binaries. - cc_library([name]): library with sources and flatbuffers deps. - - Remarks: - ** Because the genrule used to call flatc does not have any trivial way of - computing the output list of files transitively generated by includes and - --gen-includes (the default) being defined for flatc, the --gen-includes - flag will not work as expected. The way around this is to add a dependency - to the flatbuffer_cc_library defined alongside the flatc included Fileset. - For example you might define: - - flatbuffer_cc_library( - name = "my_fbs", - srcs = [ "schemas/foo.fbs" ], - includes = [ "//third_party/bazz:bazz_fbs_includes" ], - ) - - In which foo.fbs includes a few files from the Fileset defined at - //third_party/bazz:bazz_fbs_includes. When compiling the library that - includes foo_generated.h, and therefore has my_fbs as a dependency, it - will fail to find any of the bazz *_generated.h files unless you also - add bazz's flatbuffer_cc_library to your own dependency list, e.g.: - - cc_library( - name = "my_lib", - deps = [ - ":my_fbs", - "//third_party/bazz:bazz_fbs" - ], - ) - - Happy dependent Flatbuffering! - ''' - output_headers = [ - (out_prefix + "%s_generated.h") % (s.replace(".fbs", "").split("/")[-1]) for s in srcs - ] - reflection_name = "%s_reflection" % name if gen_reflections else "" - - flatbuffer_library_public(name="%s_srcs" % (name), - srcs=srcs, - outs=output_headers, - language_flag="-c", - out_prefix=out_prefix, - includes=includes, - include_paths=include_paths, - flatc_args=flatc_args, - reflection_name=reflection_name, - reflection_visiblity=visibility,) - native.cc_library(name=name, - hdrs=output_headers, - srcs=output_headers, - features=[ - "-parse_headers", - ], - deps=[ - "@flatbuffers//:runtime_cc", - ], - includes=["."], - linkstatic=1, - visibility=visibility) - - # A filegroup for the `srcs`. That is, all the schema files for this - # Flatbuffer set. - native.filegroup( - name = srcs_filegroup_name if srcs_filegroup_name else "%s_includes" % (name), - srcs = srcs, - visibility=srcs_filegroup_visibility if srcs_filegroup_visibility != None else visibility) + cc_library( + name = "my_lib", + deps = [ + ":my_fbs", + "//third_party/bazz:bazz_fbs" + ], + ) + + Happy dependent Flatbuffering! + + Args: + name: Rule name. + srcs: Source .fbs files. Sent in order to the compiler. + srcs_filegroup_name: Name of the output filegroup that holds srcs. Pass this + filegroup into the `includes` parameter of any other + flatbuffer_cc_library that depends on this one's schemas. + out_prefix: Prepend this path to the front of all generated files. Usually + is a directory name. + includes: Optional, list of filegroups of schemas that the srcs depend on. + ** SEE REMARKS BELOW ** + include_paths: Optional, list of paths the includes files can be found in. + flatc_args: Optional list of additional arguments to pass to flatc + (e.g. --gen-mutable). + visibility: The visibility of the generated cc_library. By default, use the + default visibility of the project. + srcs_filegroup_visibility: The visibility of the generated srcs filegroup. + By default, use the value of the visibility parameter above. + gen_reflections: Optional, if true this will generate the flatbuffer + reflection binaries for the schemas. + ''' + output_headers = [ + (out_prefix + "%s_generated.h") % (s.replace(".fbs", "").split("/")[-1]) + for s in srcs + ] + reflection_name = "%s_reflection" % name if gen_reflections else "" + + flatbuffer_library_public( + name = "%s_srcs" % (name), + srcs = srcs, + outs = output_headers, + language_flag = "-c", + out_prefix = out_prefix, + includes = includes, + include_paths = include_paths, + flatc_args = flatc_args, + reflection_name = reflection_name, + reflection_visiblity = visibility, + ) + native.cc_library( + name = name, + hdrs = output_headers, + srcs = output_headers, + features = [ + "-parse_headers", + ], + deps = [ + "@flatbuffers//:runtime_cc", + ], + includes = ["."], + linkstatic = 1, + visibility = visibility, + ) + + # A filegroup for the `srcs`. That is, all the schema files for this + # Flatbuffer set. + native.filegroup( + name = srcs_filegroup_name if srcs_filegroup_name else "%s_includes" % (name), + srcs = srcs, + visibility = srcs_filegroup_visibility if srcs_filegroup_visibility != None else visibility, + ) diff --git a/third_party/flatbuffers/flatbuffers.BUILD b/third_party/flatbuffers/flatbuffers.BUILD deleted file mode 100644 index 4a3701e893..0000000000 --- a/third_party/flatbuffers/flatbuffers.BUILD +++ /dev/null @@ -1,152 +0,0 @@ -package( - default_visibility = ["//visibility:public"], -) - -licenses(["notice"]) # Apache 2.0 - -exports_files(["LICENSE.txt"]) - -config_setting( - name = "freebsd", - values = {"cpu": "freebsd"}, - visibility = ["//visibility:public"], -) - -config_setting( - name = "windows", - values = {"cpu": "x64_windows"}, -) - -FLATBUFFERS_COPTS = select({ - ":windows": [], - "//conditions:default": ["-Wno-implicit-fallthrough", "-fexceptions"], -}) - -# Public flatc library to compile flatbuffer files at runtime. -cc_library( - name = "flatbuffers", - srcs = [ - "include/flatbuffers/code_generators.h", - "include/flatbuffers/reflection_generated.h", - "src/code_generators.cpp", - "src/idl_gen_fbs.cpp", - "src/idl_gen_general.cpp", - "src/idl_gen_text.cpp", - "src/idl_parser.cpp", - "src/reflection.cpp", - "src/util.cpp", - ], - hdrs = [ - "include/flatbuffers/base.h", - "include/flatbuffers/flatbuffers.h", - "include/flatbuffers/flexbuffers.h", - "include/flatbuffers/hash.h", - "include/flatbuffers/idl.h", - "include/flatbuffers/reflection.h", - "include/flatbuffers/stl_emulation.h", - "include/flatbuffers/util.h", - ], - copts = FLATBUFFERS_COPTS, - includes = ["include/"], -) - -# Public flatc compiler library. -cc_library( - name = "flatc_library", - srcs = [ - "grpc/src/compiler/config.h", - "grpc/src/compiler/go_generator.h", - "grpc/src/compiler/schema_interface.h", - "include/flatbuffers/base.h", - "include/flatbuffers/code_generators.h", - "include/flatbuffers/flatbuffers.h", - "include/flatbuffers/flatc.h", - "include/flatbuffers/flexbuffers.h", - "include/flatbuffers/hash.h", - "include/flatbuffers/idl.h", - "include/flatbuffers/reflection.h", - "include/flatbuffers/reflection_generated.h", - "include/flatbuffers/stl_emulation.h", - "include/flatbuffers/util.h", - "src/code_generators.cpp", - "src/flatc.cpp", - "src/idl_gen_fbs.cpp", - "src/idl_parser.cpp", - "src/reflection.cpp", - "src/util.cpp", - ], - hdrs = [ - "include/flatbuffers/base.h", - "include/flatbuffers/code_generators.h", - "include/flatbuffers/flatbuffers.h", - "include/flatbuffers/flatc.h", - "include/flatbuffers/idl.h", - "include/flatbuffers/reflection.h", - "include/flatbuffers/stl_emulation.h", - "include/flatbuffers/util.h", - ], - copts = FLATBUFFERS_COPTS, - includes = [ - "grpc/", - "include/", - ], -) - -# Public flatc compiler. -cc_binary( - name = "flatc", - srcs = [ - "grpc/src/compiler/cpp_generator.cc", - "grpc/src/compiler/cpp_generator.h", - "grpc/src/compiler/go_generator.cc", - "grpc/src/compiler/go_generator.h", - "grpc/src/compiler/java_generator.cc", - "grpc/src/compiler/java_generator.h", - "grpc/src/compiler/schema_interface.h", - "src/flatc_main.cpp", - "src/idl_gen_cpp.cpp", - "src/idl_gen_general.cpp", - "src/idl_gen_go.cpp", - "src/idl_gen_grpc.cpp", - "src/idl_gen_js.cpp", - "src/idl_gen_json_schema.cpp", - "src/idl_gen_php.cpp", - "src/idl_gen_python.cpp", - "src/idl_gen_text.cpp", - ], - copts = FLATBUFFERS_COPTS, - includes = [ - "grpc/", - "include/", - ], - linkopts = select({ - ":freebsd": [ - "-lm", - ], - ":windows": [], - "//conditions:default": [ - "-lm", - "-ldl", - ], - }), - deps = [ - ":flatc_library", - ], -) - -filegroup( - name = "runtime_cc_srcs", - srcs = [ - "include/flatbuffers/base.h", - "include/flatbuffers/flatbuffers.h", - "include/flatbuffers/stl_emulation.h", - "include/flatbuffers/util.h", - ], -) - -cc_library( - name = "runtime_cc", - hdrs = ["runtime_cc_srcs"], - includes = ["include"], - linkstatic = 1, -) diff --git a/third_party/flatbuffers/workspace.bzl b/third_party/flatbuffers/workspace.bzl new file mode 100644 index 0000000000..3aeef96a72 --- /dev/null +++ b/third_party/flatbuffers/workspace.bzl @@ -0,0 +1,19 @@ +"""Loads the Flatbuffers library, used by TF Lite.""" + +load("//third_party:repo.bzl", "third_party_http_archive") + +def repo(): + third_party_http_archive( + name = "flatbuffers", + strip_prefix = "flatbuffers-1.9.0", + sha256 = "5ca5491e4260cacae30f1a5786d109230db3f3a6e5a0eb45d0d0608293d247e3", + urls = [ + "https://mirror.bazel.build/github.com/google/flatbuffers/archive/v1.9.0.tar.gz", + "https://github.com/google/flatbuffers/archive/v1.9.0.tar.gz", + ], + build_file = "//third_party/flatbuffers:BUILD.bazel", + system_build_file = "//third_party/flatbuffers:BUILD.system", + link_files = { + "//third_party/flatbuffers:build_defs.bzl": "build_defs.bzl", + }, + ) diff --git a/third_party/systemlibs/flatbuffers.BUILD b/third_party/systemlibs/flatbuffers.BUILD deleted file mode 100644 index 14fceada82..0000000000 --- a/third_party/systemlibs/flatbuffers.BUILD +++ /dev/null @@ -1,38 +0,0 @@ -licenses(["notice"]) # Apache 2.0 - -filegroup( - name = "LICENSE.txt", - visibility = ["//visibility:public"], -) - -# Public flatc library to compile flatbuffer files at runtime. -cc_library( - name = "flatbuffers", - linkopts = ["-lflatbuffers"], - visibility = ["//visibility:public"], -) - -# Public flatc compiler library. -cc_library( - name = "flatc_library", - linkopts = ["-lflatbuffers"], - visibility = ["//visibility:public"], -) - -genrule( - name = "lnflatc", - outs = ["flatc.bin"], - cmd = "ln -s $$(which flatc) $@", -) - -# Public flatc compiler. -sh_binary( - name = "flatc", - srcs = ["flatc.bin"], - visibility = ["//visibility:public"], -) - -cc_library( - name = "runtime_cc", - visibility = ["//visibility:public"], -) -- cgit v1.2.3