blob: a5158cc17fe9261c700b4653df9fe3b8b9b1eb6b [file] [log] [blame]
James Kuszmaulac0912d2024-05-21 15:56:59 -07001load("//tools/build_rules:clean_dep.bzl", "clean_dep")
2
James Kuszmaul6b609292023-01-28 15:58:43 -08003def cc_static_flatbuffer(name, target, function, bfbs_name = None, visibility = None):
Austin Schuh0de30f32020-12-06 12:44:28 -08004 """Creates a cc_library which encodes a file as a Span.
5
6 args:
7 target, The file to encode.
8 function, The inline function, with full namespaces, to create.
James Kuszmaul6b609292023-01-28 15:58:43 -08009 bfbs_name, For flatbuffer targets that have multiple fbs files, this
10 specifies the basename of the bfbs file to generate a schema for.
Austin Schuh0de30f32020-12-06 12:44:28 -080011 """
12 native.genrule(
13 name = name + "_gen",
James Kuszmaulac0912d2024-05-21 15:56:59 -070014 tools = [clean_dep("//aos:flatbuffers_static")],
Austin Schuh0de30f32020-12-06 12:44:28 -080015 srcs = [target],
16 outs = [name + ".h"],
James Kuszmaulac0912d2024-05-21 15:56:59 -070017 cmd = "$(location " + clean_dep("//aos:flatbuffers_static") + ") '$(SRCS)' $(OUTS) '" + function + "' " + (bfbs_name if bfbs_name else "-"),
Austin Schuh0de30f32020-12-06 12:44:28 -080018 )
19
20 native.cc_library(
21 name = name,
22 hdrs = [name + ".h"],
23 deps = [
24 "@com_google_absl//absl/types:span",
25 ],
Austin Schuha9df9ad2021-06-16 14:49:39 -070026 visibility = visibility,
Austin Schuh0de30f32020-12-06 12:44:28 -080027 )