diff options
Diffstat (limited to 'third_party/flatbuffers/flatbuffer.gni')
-rw-r--r-- | third_party/flatbuffers/flatbuffer.gni | 85 |
1 files changed, 81 insertions, 4 deletions
diff --git a/third_party/flatbuffers/flatbuffer.gni b/third_party/flatbuffers/flatbuffer.gni index 11aae5ed7..3e34465cd 100644 --- a/third_party/flatbuffers/flatbuffer.gni +++ b/third_party/flatbuffers/flatbuffer.gni @@ -2,7 +2,9 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# Compile a flatbuffer. +import("//build/compiled_action.gni") + +# Compile a flatbuffer for C++. # # flatc_out_dir (optional) # Specifies the path suffix that output files are generated under. This @@ -48,9 +50,6 @@ # "foo.fbs", # ] # } - -import("//build/compiled_action.gni") - template("flatbuffer") { assert(defined(invoker.sources), "Need sources for flatbuffers_library") @@ -146,3 +145,81 @@ template("flatbuffer") { } } } + +# 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 = [ "//third_party/flatbuffers/src/js/flatbuffers.js" ] + outputs = [ "$target_gen_dir/flatbuffers.js" ] + } + + compiled_action_foreach(target_name) { + tool = "//third_party/flatbuffers: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 + } + } +} |