blob: c26906a8468434bfeb47a4170b1893090e7b9765 [file] [log] [blame]
James Kuszmaul6b609292023-01-28 15:58:43 -08001def cc_static_flatbuffer(name, target, function, bfbs_name = None, visibility = None):
Austin Schuh0de30f32020-12-06 12:44:28 -08002 """Creates a cc_library which encodes a file as a Span.
3
4 args:
5 target, The file to encode.
6 function, The inline function, with full namespaces, to create.
James Kuszmaul6b609292023-01-28 15:58:43 -08007 bfbs_name, For flatbuffer targets that have multiple fbs files, this
8 specifies the basename of the bfbs file to generate a schema for.
Austin Schuh0de30f32020-12-06 12:44:28 -08009 """
10 native.genrule(
11 name = name + "_gen",
Austin Schuha9df9ad2021-06-16 14:49:39 -070012 tools = ["@org_frc971//aos:flatbuffers_static"],
Austin Schuh0de30f32020-12-06 12:44:28 -080013 srcs = [target],
14 outs = [name + ".h"],
James Kuszmaul6b609292023-01-28 15:58:43 -080015 cmd = "$(location @org_frc971//aos:flatbuffers_static) '$(SRCS)' $(OUTS) '" + function + "' " + (bfbs_name if bfbs_name else "-"),
Austin Schuh0de30f32020-12-06 12:44:28 -080016 )
17
18 native.cc_library(
19 name = name,
20 hdrs = [name + ".h"],
21 deps = [
22 "@com_google_absl//absl/types:span",
23 ],
Austin Schuha9df9ad2021-06-16 14:49:39 -070024 visibility = visibility,
Austin Schuh0de30f32020-12-06 12:44:28 -080025 )