blob: cb50726b4d16d6891dc64251ec8f63ea754a3abb [file] [log] [blame]
Austin Schuhe89fa2d2019-08-14 20:24:23 -07001# Description:
2# BUILD rules for generating flatbuffer files in various languages.
3
4"""
5Rules for building C++ flatbuffers with Bazel.
6"""
Austin Schuh7c75e582020-11-14 16:41:18 -08007
Alex Perry0d0aae32022-02-09 21:10:17 -08008load("@io_bazel_rules_go//go:def.bzl", "go_library")
James Kuszmauldac091f2022-03-22 09:35:06 -07009load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
10load("@npm//@bazel/typescript:index.bzl", "ts_project")
11load("@rules_cc//cc:defs.bzl", "cc_library")
Austin Schuhe89fa2d2019-08-14 20:24:23 -070012
13flatc_path = "@com_github_google_flatbuffers//:flatc"
14
15DEFAULT_INCLUDE_PATHS = [
16 "./",
17 "$(GENDIR)",
18 "$(BINDIR)",
Alex Perrycb7da4b2019-08-28 19:35:56 -070019 "$(execpath @com_github_google_flatbuffers//:flatc).runfiles/com_github_google_flatbuffers",
Austin Schuhe89fa2d2019-08-14 20:24:23 -070020]
21
22DEFAULT_FLATC_ARGS = [
23 "--gen-object-api",
24 "--gen-compare",
Alex Perrycb7da4b2019-08-28 19:35:56 -070025 "--keep-prefix",
milind upadhyay328d3392020-11-25 19:34:00 -080026 "--cpp-std",
27 "c++17",
Austin Schuhf13042b2020-11-25 23:11:41 -080028 "--require-explicit-ids",
Austin Schuhe89fa2d2019-08-14 20:24:23 -070029 "--gen-mutable",
30 "--reflect-names",
31 "--cpp-ptr-type flatbuffers::unique_ptr",
Alex Perrycb7da4b2019-08-28 19:35:56 -070032 "--force-empty",
Austin Schuh872723c2019-12-25 14:38:09 -080033 "--scoped-enums",
Alex Perrycb7da4b2019-08-28 19:35:56 -070034 "--gen-name-strings",
Austin Schuhe89fa2d2019-08-14 20:24:23 -070035]
36
Alex Perry0d0aae32022-02-09 21:10:17 -080037DEFAULT_FLATC_GO_ARGS = [
38 "--gen-onefile",
Philipp Schradercdb5cfc2022-02-20 14:57:07 -080039 "--gen-object-api",
Philipp Schrader2d4ad412022-02-25 15:56:20 -080040 "--require-explicit-ids",
Alex Perry0d0aae32022-02-09 21:10:17 -080041]
42
Alex Perryb3b50792020-01-18 16:13:45 -080043DEFAULT_FLATC_TS_ARGS = [
James Kuszmauldac091f2022-03-22 09:35:06 -070044 "--gen-object-api",
45 "--gen-mutable",
Alex Perryb3b50792020-01-18 16:13:45 -080046 "--reflect-names",
Alex Perry5f474f22020-02-01 12:14:24 -080047 "--gen-name-strings",
James Kuszmauldac091f2022-03-22 09:35:06 -070048 "--ts-flat-files",
49 "--keep-prefix",
Alex Perryb3b50792020-01-18 16:13:45 -080050]
51
Austin Schuhe89fa2d2019-08-14 20:24:23 -070052def flatbuffer_library_public(
53 name,
54 srcs,
55 outs,
56 language_flag,
57 out_prefix = "",
58 includes = [],
59 include_paths = DEFAULT_INCLUDE_PATHS,
60 flatc_args = DEFAULT_FLATC_ARGS,
61 reflection_name = "",
62 reflection_visibility = None,
Alex Perrycb7da4b2019-08-28 19:35:56 -070063 compatible_with = None,
Austin Schuh7c75e582020-11-14 16:41:18 -080064 restricted_to = None,
Philipp Schraderdada1072020-11-24 11:34:46 -080065 target_compatible_with = None,
Austin Schuhe89fa2d2019-08-14 20:24:23 -070066 output_to_bindir = False):
Philipp Schraderdada1072020-11-24 11:34:46 -080067 """Generates code files for reading/writing the given flatbuffers in the
68 requested language using the public compiler.
Austin Schuhe89fa2d2019-08-14 20:24:23 -070069
70 Args:
71 name: Rule name.
72 srcs: Source .fbs files. Sent in order to the compiler.
73 outs: Output files from flatc.
74 language_flag: Target language flag. One of [-c, -j, -js].
75 out_prefix: Prepend this path to the front of all generated files except on
76 single source targets. Usually is a directory name.
77 includes: Optional, list of filegroups of schemas that the srcs depend on.
78 include_paths: Optional, list of paths the includes files can be found in.
79 flatc_args: Optional, list of additional arguments to pass to flatc.
80 reflection_name: Optional, if set this will generate the flatbuffer
81 reflection binaries for the schemas.
82 reflection_visibility: The visibility of the generated reflection Fileset.
83 output_to_bindir: Passed to genrule for output to bin directory.
Austin Schuh7c75e582020-11-14 16:41:18 -080084 compatible_with: Optional, The list of environments this rule can be
85 built for, in addition to default-supported environments.
86 restricted_to: Optional, The list of environments this rule can be built
87 for, instead of default-supported environments.
James Kuszmauldac091f2022-03-22 09:35:06 -070088 target_compatible_with: Optional, The list of target platform constraints
89 to use.
Austin Schuh7c75e582020-11-14 16:41:18 -080090 output_to_bindir: Passed to genrule for output to bin directory.
Austin Schuhe89fa2d2019-08-14 20:24:23 -070091
92
93 This rule creates a filegroup(name) with all generated source files, and
94 optionally a Fileset([reflection_name]) with all generated reflection
95 binaries.
96 """
97 include_paths_cmd = ["-I %s" % (s) for s in include_paths]
98
99 # '$(@D)' when given a single source target will give the appropriate
100 # directory. Appending 'out_prefix' is only necessary when given a build
101 # target with multiple sources.
102 output_directory = (
103 ("-o $(@D)/%s" % (out_prefix)) if len(srcs) > 1 else ("-o $(@D)")
104 )
105 genrule_cmd = " ".join([
106 "SRCS=($(SRCS));",
107 "for f in $${SRCS[@]:0:%s}; do" % len(srcs),
108 "$(location %s)" % (flatc_path),
109 " ".join(include_paths_cmd),
110 " ".join(flatc_args),
111 language_flag,
112 output_directory,
113 "$$f;",
114 "done",
115 ])
116 native.genrule(
117 name = name,
118 srcs = srcs + includes,
119 outs = outs,
120 output_to_bindir = output_to_bindir,
121 tools = [flatc_path],
122 cmd = genrule_cmd,
Alex Perrycb7da4b2019-08-28 19:35:56 -0700123 compatible_with = compatible_with,
Philipp Schraderdada1072020-11-24 11:34:46 -0800124 target_compatible_with = target_compatible_with,
James Kuszmauldac091f2022-03-22 09:35:06 -0700125 restricted_to = restricted_to,
Austin Schuh7c75e582020-11-14 16:41:18 -0800126 message = "Generating flatbuffer files for %s:" % (name),
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700127 )
128 if reflection_name:
129 reflection_genrule_cmd = " ".join([
130 "SRCS=($(SRCS));",
131 "for f in $${SRCS[@]:0:%s}; do" % len(srcs),
132 "$(location %s)" % (flatc_path),
133 "-b --schema",
134 " ".join(flatc_args),
135 " ".join(include_paths_cmd),
136 language_flag,
137 output_directory,
138 "$$f;",
139 "done",
140 ])
141 reflection_outs = [
142 (out_prefix + "%s.bfbs") % (s.replace(".fbs", "").split("/")[-1])
143 for s in srcs
144 ]
145 native.genrule(
146 name = "%s_srcs" % reflection_name,
147 srcs = srcs + includes,
148 outs = reflection_outs,
149 output_to_bindir = output_to_bindir,
150 tools = [flatc_path],
Austin Schuh7c75e582020-11-14 16:41:18 -0800151 compatible_with = compatible_with,
152 restricted_to = restricted_to,
Philipp Schraderdada1072020-11-24 11:34:46 -0800153 target_compatible_with = target_compatible_with,
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700154 cmd = reflection_genrule_cmd,
155 message = "Generating flatbuffer reflection binary for %s:" % (name),
James Kuszmauldac091f2022-03-22 09:35:06 -0700156 visibility = reflection_visibility,
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700157 )
Alex Perrycb7da4b2019-08-28 19:35:56 -0700158 native.filegroup(
159 name = "%s_out" % reflection_name,
160 srcs = reflection_outs,
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700161 visibility = reflection_visibility,
Alex Perrycb7da4b2019-08-28 19:35:56 -0700162 compatible_with = compatible_with,
Austin Schuh7c75e582020-11-14 16:41:18 -0800163 restricted_to = restricted_to,
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700164 )
165
166def flatbuffer_cc_library(
167 name,
168 srcs,
169 srcs_filegroup_name = "",
170 out_prefix = "",
James Kuszmauldac091f2022-03-22 09:35:06 -0700171 deps = [],
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700172 includes = [],
173 include_paths = DEFAULT_INCLUDE_PATHS,
James Kuszmauldac091f2022-03-22 09:35:06 -0700174 cc_include_paths = [],
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700175 flatc_args = DEFAULT_FLATC_ARGS,
176 visibility = None,
Austin Schuh7c75e582020-11-14 16:41:18 -0800177 compatible_with = None,
178 restricted_to = None,
Philipp Schraderdada1072020-11-24 11:34:46 -0800179 target_compatible_with = None,
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700180 srcs_filegroup_visibility = None,
181 gen_reflections = False):
James Kuszmauldac091f2022-03-22 09:35:06 -0700182 """A cc_library with the generated reader/writers for the given flatbuffer definitions.
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700183
184 Args:
185 name: Rule name.
186 srcs: Source .fbs files. Sent in order to the compiler.
187 srcs_filegroup_name: Name of the output filegroup that holds srcs. Pass this
188 filegroup into the `includes` parameter of any other
189 flatbuffer_cc_library that depends on this one's schemas.
190 out_prefix: Prepend this path to the front of all generated files. Usually
191 is a directory name.
James Kuszmauldac091f2022-03-22 09:35:06 -0700192 deps: Optional, list of other flatbuffer_cc_library's to depend on. Cannot be specified
193 alongside includes.
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700194 includes: Optional, list of filegroups of schemas that the srcs depend on.
James Kuszmauldac091f2022-03-22 09:35:06 -0700195 Use of this is discouraged, and may be deprecated.
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700196 include_paths: Optional, list of paths the includes files can be found in.
James Kuszmauldac091f2022-03-22 09:35:06 -0700197 cc_include_paths: Optional, list of paths to add to the cc_library includes attribute.
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700198 flatc_args: Optional list of additional arguments to pass to flatc
199 (e.g. --gen-mutable).
200 visibility: The visibility of the generated cc_library. By default, use the
201 default visibility of the project.
Philipp Schraderdada1072020-11-24 11:34:46 -0800202 target_compatible_with: Optional, the list of constraints the target
203 platform must satisfy for this target to be considered compatible.
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700204 srcs_filegroup_visibility: The visibility of the generated srcs filegroup.
205 By default, use the value of the visibility parameter above.
206 gen_reflections: Optional, if true this will generate the flatbuffer
207 reflection binaries for the schemas.
Austin Schuh7c75e582020-11-14 16:41:18 -0800208 compatible_with: Optional, The list of environments this rule can be built
209 for, in addition to default-supported environments.
210 restricted_to: Optional, The list of environments this rule can be built
211 for, instead of default-supported environments.
James Kuszmauldac091f2022-03-22 09:35:06 -0700212 target_compatible_with: Optional, The list of target platform constraints
213 to use.
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700214
215 This produces:
216 filegroup([name]_srcs): all generated .h files.
217 filegroup(srcs_filegroup_name if specified, or [name]_includes if not):
218 Other flatbuffer_cc_library's can pass this in for their `includes`
219 parameter, if they depend on the schemas in this library.
220 Fileset([name]_reflection): (Optional) all generated reflection binaries.
221 cc_library([name]): library with sources and flatbuffers deps.
James Kuszmauldac091f2022-03-22 09:35:06 -0700222 """
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700223 output_headers = [
James Kuszmauldac091f2022-03-22 09:35:06 -0700224 (out_prefix + "%s_generated.h") % (s.replace(".fbs", "").split("/")[-1].split(":")[-1])
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700225 for s in srcs
226 ]
James Kuszmauldac091f2022-03-22 09:35:06 -0700227 if deps and includes:
228 # There is no inherent reason we couldn't support both, but this discourages
229 # use of includes without good reason.
230 fail("Cannot specify both deps and include in flatbuffer_cc_library.")
231 if deps:
232 includes = [d + "_includes" for d in deps]
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700233 reflection_name = "%s_reflection" % name if gen_reflections else ""
234
235 srcs_lib = "%s_srcs" % (name)
236 flatbuffer_library_public(
237 name = srcs_lib,
238 srcs = srcs,
239 outs = output_headers,
240 language_flag = "-c",
241 out_prefix = out_prefix,
242 includes = includes,
243 include_paths = include_paths,
244 flatc_args = flatc_args,
Austin Schuh7c75e582020-11-14 16:41:18 -0800245 compatible_with = compatible_with,
246 restricted_to = restricted_to,
James Kuszmauldac091f2022-03-22 09:35:06 -0700247 target_compatible_with = target_compatible_with,
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700248 reflection_name = reflection_name,
249 reflection_visibility = visibility,
250 )
251 native.cc_library(
252 name = name,
253 hdrs = [
254 ":" + srcs_lib,
255 ],
256 srcs = [
257 ":" + srcs_lib,
258 ],
259 features = [
260 "-parse_headers",
261 ],
262 deps = [
263 "@com_github_google_flatbuffers//:runtime_cc",
James Kuszmauldac091f2022-03-22 09:35:06 -0700264 "@com_github_google_flatbuffers//:flatbuffers",
265 ] + deps,
266 includes = cc_include_paths,
Austin Schuh7c75e582020-11-14 16:41:18 -0800267 compatible_with = compatible_with,
268 restricted_to = restricted_to,
Philipp Schraderdada1072020-11-24 11:34:46 -0800269 target_compatible_with = target_compatible_with,
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700270 linkstatic = 1,
271 visibility = visibility,
272 )
273
274 # A filegroup for the `srcs`. That is, all the schema files for this
275 # Flatbuffer set.
276 native.filegroup(
277 name = srcs_filegroup_name if srcs_filegroup_name else "%s_includes" % (name),
James Kuszmauldac091f2022-03-22 09:35:06 -0700278 srcs = srcs + includes,
Alex Perrycb7da4b2019-08-28 19:35:56 -0700279 compatible_with = compatible_with,
Austin Schuh7c75e582020-11-14 16:41:18 -0800280 restricted_to = restricted_to,
281 visibility = srcs_filegroup_visibility if srcs_filegroup_visibility != None else visibility,
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700282 )
James Kuszmaulf385c462019-12-24 09:37:34 -0800283
Brian Silverman28760272020-02-02 13:21:51 -0800284def flatbuffer_py_library(
James Kuszmaulf385c462019-12-24 09:37:34 -0800285 name,
286 srcs,
287 namespace,
288 tables,
289 compatible_with = None,
Philipp Schraderdada1072020-11-24 11:34:46 -0800290 target_compatible_with = None,
James Kuszmaulf385c462019-12-24 09:37:34 -0800291 includes = [],
292 include_paths = DEFAULT_INCLUDE_PATHS,
293 flatc_args = DEFAULT_FLATC_ARGS,
294 visibility = None,
295 srcs_filegroup_visibility = None):
296 """Generates a py_library rule for a given flatbuffer definition.
297
298 Args:
299 name: Name of the generated py_library rule.
300 srcs: Source .fbs file(s).
301 namespace: Namespace of the specified flatbuffer schema. Until
302 we make the rules sophisticated enough to figure out what
303 python files will be generated from a given schema, the user
304 has to manually specify this.
305 tables: List of table names--currently, we don't do anything to
306 automatically figure out how to handle the fact that a separate
307 python file will be generated for every table definition, and that
308 we can't know what files will be output until after the file has
309 been parsed. As such, we just force the user to manually specify
310 things.
311 """
Austin Schuha4f69d62020-02-28 13:58:14 -0800312 python_files = ["%s/%s.py" % (namespace.replace(".", "/"), table) for table in tables]
James Kuszmaulf385c462019-12-24 09:37:34 -0800313
314 srcs_lib = "%s_srcs" % (name)
315 flatbuffer_library_public(
316 name = srcs_lib,
317 srcs = srcs,
318 outs = python_files,
319 language_flag = "--python",
320 includes = includes,
321 include_paths = include_paths,
322 flatc_args = flatc_args,
323 compatible_with = compatible_with,
Philipp Schraderdada1072020-11-24 11:34:46 -0800324 target_compatible_with = target_compatible_with,
James Kuszmaulf385c462019-12-24 09:37:34 -0800325 )
326 native.py_library(
327 name = name,
328 srcs = python_files,
329 visibility = visibility,
330 compatible_with = compatible_with,
Philipp Schraderdada1072020-11-24 11:34:46 -0800331 target_compatible_with = target_compatible_with,
James Kuszmaulf385c462019-12-24 09:37:34 -0800332 imports = ["."],
333 deps = ["@com_github_google_flatbuffers//:flatpy"],
334 )
Alex Perryb3b50792020-01-18 16:13:45 -0800335
Alex Perry0d0aae32022-02-09 21:10:17 -0800336def flatbuffer_go_library(
337 name,
338 srcs,
339 importpath,
340 compatible_with = None,
341 target_compatible_with = None,
342 includes = [],
343 include_paths = DEFAULT_INCLUDE_PATHS,
344 flatc_args = DEFAULT_FLATC_GO_ARGS,
345 visibility = None,
346 srcs_filegroup_visibility = None):
347 srcs_lib = "%s_srcs" % (name)
348 outs = ["%s_generated.go" % (s.replace(".fbs", "").split("/")[-1]) for s in srcs]
349 flatc_args = flatc_args + ["--go-namespace", importpath.split("/")[-1]]
350
351 flatbuffer_library_public(
352 name = srcs_lib,
353 srcs = srcs,
354 outs = outs,
355 language_flag = "--go",
356 includes = includes,
357 include_paths = include_paths,
358 flatc_args = flatc_args,
359 compatible_with = compatible_with,
360 target_compatible_with = target_compatible_with,
361 )
362 go_library(
363 name = name,
364 srcs = outs,
365 deps = ["@com_github_google_flatbuffers//go"],
366 importpath = importpath,
367 visibility = visibility,
368 compatible_with = compatible_with,
369 target_compatible_with = target_compatible_with,
370 )
371
Alex Perryb3b50792020-01-18 16:13:45 -0800372def flatbuffer_ts_library(
373 name,
374 srcs,
375 compatible_with = None,
Philipp Schraderdada1072020-11-24 11:34:46 -0800376 target_compatible_with = None,
James Kuszmauldac091f2022-03-22 09:35:06 -0700377 deps = [],
Alex Perryb3b50792020-01-18 16:13:45 -0800378 include_paths = DEFAULT_INCLUDE_PATHS,
379 flatc_args = DEFAULT_FLATC_TS_ARGS,
380 visibility = None,
James Kuszmauldac091f2022-03-22 09:35:06 -0700381 restricted_to = None,
382 include_reflection = True):
Alex Perryb3b50792020-01-18 16:13:45 -0800383 """Generates a ts_library rule for a given flatbuffer definition.
384
385 Args:
386 name: Name of the generated ts_library rule.
387 srcs: Source .fbs file(s).
James Kuszmauldac091f2022-03-22 09:35:06 -0700388 deps: Other flatbuffer_ts_library's to depend on. Note that currently
389 you must specify all your transitive dependencies manually.
390 include_paths: Optional, list of paths the includes files can be found in.
391 flatc_args: Optional list of additional arguments to pass to flatc
392 (e.g. --gen-mutable).
393 visibility: The visibility of the generated cc_library. By default, use the
394 default visibility of the project.
395 compatible_with: Optional, The list of environments this rule can be built
396 for, in addition to default-supported environments.
397 restricted_to: Optional, The list of environments this rule can be built
398 for, instead of default-supported environments.
399 target_compatible_with: Optional, The list of target platform constraints
400 to use.
401 include_reflection: Optional, Whether to depend on the flatbuffer
402 reflection library automatically. Only really relevant for the
403 target that builds the reflection library itself.
Alex Perryb3b50792020-01-18 16:13:45 -0800404 """
405 srcs_lib = "%s_srcs" % (name)
James Kuszmauldac091f2022-03-22 09:35:06 -0700406
407 # frc971-specific modification: Add a genrule that overwrites the imports for any flatbuffer
408 # types (mostly just for reflection) because they need to point to external/, not to
409 # third_party/.
410 # TODO(james): There absolutely are better ways to do this, but this was the quick and dirty
411 # one....
412 pre_outs = ["%s_pregenerated.ts" % (s.replace(".fbs", "").split("/")[-1]) for s in srcs]
Alex Perryb3b50792020-01-18 16:13:45 -0800413 outs = ["%s_generated.ts" % (s.replace(".fbs", "").split("/")[-1]) for s in srcs]
James Kuszmauldac091f2022-03-22 09:35:06 -0700414 includes = [d + "_includes" for d in deps]
Alex Perryb3b50792020-01-18 16:13:45 -0800415 flatbuffer_library_public(
416 name = srcs_lib,
417 srcs = srcs,
James Kuszmauldac091f2022-03-22 09:35:06 -0700418 outs = pre_outs,
Alex Perryb3b50792020-01-18 16:13:45 -0800419 language_flag = "--ts",
420 includes = includes,
421 include_paths = include_paths,
James Kuszmauldac091f2022-03-22 09:35:06 -0700422 flatc_args = flatc_args + ["--filename-suffix _pregenerated"],
Alex Perryb3b50792020-01-18 16:13:45 -0800423 compatible_with = compatible_with,
James Kuszmauldac091f2022-03-22 09:35:06 -0700424 restricted_to = restricted_to,
Philipp Schraderdada1072020-11-24 11:34:46 -0800425 target_compatible_with = target_compatible_with,
Alex Perryb3b50792020-01-18 16:13:45 -0800426 )
James Kuszmauldac091f2022-03-22 09:35:06 -0700427 genrule_cmd = " ".join([
428 "SRCS=($(SRCS));",
429 "OUTS=($(OUTS));",
430 "for i in $${!SRCS[@]}; do",
431 "sed 's/third_party\\/flatbuffers/external\\/com_github_google_flatbuffers/' $${SRCS[i]} > $${OUTS[i]};",
432 "sed -i 's/_pregenerated/_generated/' $${OUTS[i]};",
433 "done",
434 ])
435 native.genrule(
436 name = name + "_reimporter",
437 srcs = pre_outs,
438 outs = outs,
439 cmd = genrule_cmd,
440 )
441 ts_project(
442 name = name + "_ts",
Alex Perryb3b50792020-01-18 16:13:45 -0800443 srcs = outs,
James Kuszmauldac091f2022-03-22 09:35:06 -0700444 declaration = True,
Alex Perryb3b50792020-01-18 16:13:45 -0800445 visibility = visibility,
446 compatible_with = compatible_with,
James Kuszmauldac091f2022-03-22 09:35:06 -0700447 restricted_to = restricted_to,
Philipp Schraderdada1072020-11-24 11:34:46 -0800448 target_compatible_with = target_compatible_with,
James Kuszmauldac091f2022-03-22 09:35:06 -0700449 tsconfig = {
450 "compilerOptions": {
451 "declaration": True,
452 "lib": [
453 "ES2015",
454 "ES2020.BigInt",
455 "DOM",
456 ],
457 "module": "es2015",
458 "moduleResolution": "node",
459 "strict": True,
460 "types": ["node"],
461 },
462 },
463 deps = deps + ["@com_github_google_flatbuffers//ts:flatbuffers"] + (["@com_github_google_flatbuffers//reflection:reflection_ts_fbs"] if include_reflection else []),
464 )
465 js_library(
466 name = name,
467 visibility = visibility,
468 compatible_with = compatible_with,
469 restricted_to = restricted_to,
470 target_compatible_with = target_compatible_with,
471 deps = [name + "_ts"],
472 )
473 native.filegroup(
474 name = "%s_includes" % (name),
475 srcs = srcs + includes,
476 compatible_with = compatible_with,
477 restricted_to = restricted_to,
478 visibility = visibility,
Alex Perryb3b50792020-01-18 16:13:45 -0800479 )