summaryrefslogtreecommitdiff
path: root/build_extra/flatbuffers
diff options
context:
space:
mode:
Diffstat (limited to 'build_extra/flatbuffers')
-rw-r--r--build_extra/flatbuffers/BUILD.gn122
-rw-r--r--build_extra/flatbuffers/flatbuffer.gni233
2 files changed, 355 insertions, 0 deletions
diff --git a/build_extra/flatbuffers/BUILD.gn b/build_extra/flatbuffers/BUILD.gn
new file mode 100644
index 000000000..0433c5d1d
--- /dev/null
+++ b/build_extra/flatbuffers/BUILD.gn
@@ -0,0 +1,122 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("flatbuffer.gni")
+
+fb_src = flatbuffers_source_location
+
+config("flatbuffers_config") {
+ include_dirs = [ "$fb_src/include" ]
+
+ if (is_clang) {
+ cflags = [
+ "-Wno-exit-time-destructors",
+ "-Wno-header-hygiene",
+ ]
+ }
+}
+
+# The part of FlatBuffers that Chrome is interested in.
+source_set("flatbuffers") {
+ sources = [
+ "$fb_src/include/flatbuffers/flatbuffers.h",
+ ]
+
+ configs -= [ "//build/config/compiler:chromium_code" ]
+ configs += [ "//build/config/compiler:no_chromium_code" ]
+
+ public_configs = [ ":flatbuffers_config" ]
+}
+
+# The complete FlatBuffers library, as required to build the flatc compiler and
+# some of the tests.
+source_set("compiler_files") {
+ include_dirs = [ "$fb_src/grpc" ]
+ sources = [
+ "$fb_src/grpc/src/compiler/config.h",
+ "$fb_src/grpc/src/compiler/config.h",
+ "$fb_src/grpc/src/compiler/cpp_generator.cc",
+ "$fb_src/grpc/src/compiler/cpp_generator.h",
+ "$fb_src/grpc/src/compiler/go_generator.cc",
+ "$fb_src/grpc/src/compiler/go_generator.h",
+ "$fb_src/grpc/src/compiler/java_generator.cc",
+ "$fb_src/grpc/src/compiler/java_generator.h",
+ "$fb_src/grpc/src/compiler/schema_interface.h",
+ "$fb_src/include/flatbuffers/code_generators.h",
+ "$fb_src/include/flatbuffers/flatc.h",
+ "$fb_src/include/flatbuffers/flexbuffers.h",
+ "$fb_src/include/flatbuffers/grpc.h",
+ "$fb_src/include/flatbuffers/hash.h",
+ "$fb_src/include/flatbuffers/idl.h",
+ "$fb_src/include/flatbuffers/reflection.h",
+ "$fb_src/include/flatbuffers/reflection_generated.h",
+ "$fb_src/include/flatbuffers/util.h",
+ "$fb_src/src/code_generators.cpp",
+ "$fb_src/src/flatc.cpp",
+ "$fb_src/src/idl_gen_cpp.cpp",
+ "$fb_src/src/idl_gen_fbs.cpp",
+ "$fb_src/src/idl_gen_general.cpp",
+ "$fb_src/src/idl_gen_go.cpp",
+ "$fb_src/src/idl_gen_grpc.cpp",
+ "$fb_src/src/idl_gen_js.cpp",
+ "$fb_src/src/idl_gen_json_schema.cpp",
+ "$fb_src/src/idl_gen_php.cpp",
+ "$fb_src/src/idl_gen_python.cpp",
+ "$fb_src/src/idl_gen_rust.cpp",
+ "$fb_src/src/idl_gen_text.cpp",
+ "$fb_src/src/idl_parser.cpp",
+ "$fb_src/src/reflection.cpp",
+ "$fb_src/src/util.cpp",
+ ]
+ configs -= [ "//build/config/compiler:chromium_code" ]
+ configs += [ "//build/config/compiler:no_chromium_code" ]
+ visibility = [ ":*" ]
+ deps = [
+ ":flatbuffers",
+ ]
+}
+
+executable("flatc") {
+ sources = [
+ "$fb_src/src/flatc_main.cpp",
+ ]
+ deps = [
+ ":compiler_files",
+ ":flatbuffers",
+ ]
+}
+
+# The following is just for testing.
+
+flatbuffer("flatbuffers_samplebuffer") {
+ testonly = true
+ sources = [
+ "$fb_src/tests/include_test/include_test1.fbs",
+ "$fb_src/tests/include_test/sub/include_test2.fbs",
+ "$fb_src/tests/monster_test.fbs",
+ "$fb_src/tests/namespace_test/namespace_test1.fbs",
+ "$fb_src/tests/namespace_test/namespace_test2.fbs",
+ ]
+ flatc_include_dirs = [ "$fb_src/tests/include_test" ]
+}
+
+# test("flatbuffers_unittest") {
+# sources = [
+# "src/tests/test.cpp",
+# ]
+# deps = [
+# ":compiler_files",
+# ":flatbuffers",
+# ":flatbuffers_samplebuffer",
+# ]
+# data = [
+# "src/tests/",
+# ]
+#
+# if (is_win) {
+# # Suppress "object allocated on the heap may not be aligned 16".
+# cflags = [ "/wd4316" ]
+# }
+# defines = [ "FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE" ]
+# }
diff --git a/build_extra/flatbuffers/flatbuffer.gni b/build_extra/flatbuffers/flatbuffer.gni
new file mode 100644
index 000000000..0bac1802c
--- /dev/null
+++ b/build_extra/flatbuffers/flatbuffer.gni
@@ -0,0 +1,233 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//build/compiled_action.gni")
+
+declare_args() {
+ # Location of flatbuffers source code.
+ flatbuffers_source_location = "//third_party/flatbuffers/"
+
+ # Absolute location flatbuffers BUILD.gn file.
+ flatbuffers_build_location = "//build_extra/flatbuffers/"
+}
+
+# Compile a flatbuffer for C++.
+#
+# flatc_out_dir (optional)
+# Specifies the path suffix that output files are generated under. This
+# path will be appended to root_gen_dir.
+#
+# Targets that depend on the flatbuffer target will be able to include
+# the resulting FlatBuffers header with an include like:
+# #include "dir/for/my_flatbuffer/buffer_generated.h"
+# If undefined, this defaults to matchign the input directory for each
+# .fbs file (you should almost always use the default mode).
+#
+# flatc_include_dirs (optional)
+# Specifies the directories which FlatBuffers compiler uses to find
+# included .fbs files in. Almost always should be empty.
+#
+# The list always has an implicit first item corresponding to the root of
+# the source tree. This enables including .fbs files by absolute path.
+#
+# The compiler will try the directories in the order given, and if all
+# fail it will try to load relative to the directory of the schema file
+# being parsed.
+#
+# deps (optional)
+# Additional dependencies.
+#
+# Parameters for compiling the generated code:
+#
+# defines (optional)
+# Defines to supply to the source set that compiles the generated source
+# code.
+#
+# extra_configs (optional)
+# A list of config labels that will be appended to the configs applying
+# to the source set.
+#
+# testonly (optional)
+# Boolean to indicate whether the generated source sets should be labeled
+# as testonly.
+#
+# Example:
+# flatbuffer("mylib") {
+# sources = [
+# "foo.fbs",
+# ]
+# }
+template("flatbuffer") {
+ assert(defined(invoker.sources), "Need sources for flatbuffers_library")
+
+ # Don't apply OS-specific sources filtering to the assignments later on.
+ # Platform files should have gotten filtered out in the sources assignment
+ # when this template was invoked. If they weren't, it was on purpose and
+ # this template shouldn't re-apply the filter.
+ set_sources_assignment_filter([])
+
+ action_name = "${target_name}_gen"
+ source_set_name = target_name
+ compiled_action_foreach(action_name) {
+ visibility = [ ":$source_set_name" ]
+
+ tool = "$flatbuffers_build_location:flatc"
+
+ sources = invoker.sources
+ deps = []
+
+ if (defined(invoker.flatc_out_dir)) {
+ out_dir = "$root_gen_dir/" + invoker.flatc_out_dir
+ } else {
+ out_dir = "{{source_gen_dir}}"
+ }
+
+ outputs = [
+ "$out_dir/{{source_name_part}}_generated.h",
+ ]
+
+ args = [
+ "-c",
+ "--keep-prefix",
+ "-o",
+ "$out_dir",
+ "-I",
+ rebase_path("//", root_build_dir),
+ ]
+
+ if (defined(invoker.flatc_include_dirs)) {
+ foreach(include_dir, invoker.flatc_include_dirs) {
+ args += [
+ "-I",
+ rebase_path(include_dir, root_build_dir),
+ ]
+ }
+ }
+
+ args += [ "{{source}}" ]
+
+ # The deps may have steps that have to run before running flatc.
+ if (defined(invoker.deps)) {
+ deps += invoker.deps
+ }
+ }
+
+ source_set(target_name) {
+ forward_variables_from(invoker,
+ [
+ "visibility",
+ "defines",
+ ])
+
+ sources = get_target_outputs(":$action_name")
+
+ if (defined(invoker.extra_configs)) {
+ configs += invoker.extra_configs
+ }
+
+ if (defined(invoker.testonly)) {
+ testonly = invoker.testonly
+ }
+
+ public_configs = [ "$flatbuffers_build_location:flatbuffers_config" ]
+
+ public_deps = [
+ # The generated headers reference headers within FlatBuffers, so
+ # dependencies must be able to find those headers too.
+ flatbuffers_build_location,
+ ]
+ deps = [
+ ":$action_name",
+ ]
+
+ # This will link any libraries in the deps (the use of invoker.deps in the
+ # action won't link it).
+ if (defined(invoker.deps)) {
+ deps += invoker.deps
+ }
+
+ # Same for public_deps.
+ if (defined(invoker.public_deps)) {
+ public_deps += invoker.public_deps
+ }
+ }
+}
+
+# Compile a flatbuffer to typescript.
+#
+# flatc_include_dirs (optional)
+# Specifies the directories which FlatBuffers compiler uses to find
+# included .fbs files in. Almost always should be empty.
+#
+# The list always has an implicit first item corresponding to the root of
+# the source tree. This enables including .fbs files by absolute path.
+#
+# The compiler will try the directories in the order given, and if all
+# fail it will try to load relative to the directory of the schema file
+# being parsed.
+#
+# deps (optional)
+# Additional dependencies.
+#
+# Example:
+# ts_flatbuffer("foo_ts") {
+# sources = [
+# "foo.fbs",
+# ]
+# }
+template("ts_flatbuffer") {
+ assert(defined(invoker.sources), "Need sources for flatbuffers_library")
+
+ # Don't apply OS-specific sources filtering to the assignments later on.
+ # Platform files should have gotten filtered out in the sources assignment
+ # when this template was invoked. If they weren't, it was on purpose and
+ # this template shouldn't re-apply the filter.
+ set_sources_assignment_filter([])
+
+ copy_name = target_name + "_copy"
+
+ copy(copy_name) {
+ sources = [ "$flatbuffers_source_location/js/flatbuffers.js" ]
+ outputs = [ "$target_gen_dir/flatbuffers.js" ]
+ }
+
+ compiled_action_foreach(target_name) {
+ tool = "$flatbuffers_build_location:flatc"
+
+ sources = invoker.sources
+ deps = [ ":" + copy_name ]
+
+ out_dir = target_gen_dir
+
+ outputs = [
+ "$out_dir/{{source_name_part}}_generated.ts",
+ ]
+
+ args = [
+ "--ts",
+ "--no-fb-import",
+ "--gen-mutable",
+ "-o",
+ rebase_path(out_dir, root_build_dir),
+ "-I",
+ rebase_path("//", root_build_dir),
+ ]
+
+ if (defined(invoker.flatc_include_dirs)) {
+ foreach(include_dir, invoker.flatc_include_dirs) {
+ args += [
+ "-I",
+ rebase_path(include_dir, root_build_dir),
+ ]
+ }
+ }
+
+ args += [ "{{source}}" ]
+
+ # The deps may have steps that have to run before running flatc.
+ if (defined(invoker.deps)) {
+ deps += invoker.deps
+ }
+ }
+}