blob: 3db1a7dbf537f7de8c1ce8e72545a592ca071e50 [file] [log] [blame]
Brian Silverman049dcb62015-09-27 19:08:00 -04001def _gen_embedded_impl(ctx):
Philipp Schrader5dd9eda2020-11-08 10:16:35 -08002 ctx.actions.run(
Austin Schuh8e17be92019-12-24 09:32:11 -08003 inputs = ctx.files.srcs,
4 outputs = [ctx.outputs.source],
5 executable = ctx.executable._gen_embedded,
6 arguments = [ctx.outputs.source.path] + [f.path for f in ctx.files.srcs],
7 progress_message = "Generating %s" % ctx.outputs.source.short_path,
8 mnemonic = "GenEmbedded",
9 )
Brian Silverman049dcb62015-09-27 19:08:00 -040010
Austin Schuh8e17be92019-12-24 09:32:11 -080011 return struct(
12 files = depset([ctx.outputs.source]),
13 )
Brian Silverman049dcb62015-09-27 19:08:00 -040014
15_do_gen_embedded = rule(
Brian Silvermanacdabeb2019-03-23 14:04:36 -070016 attrs = {
17 "srcs": attr.label_list(
18 mandatory = True,
Austin Schuh849954c2020-09-10 23:11:57 -070019 allow_empty = False,
Brian Silvermanacdabeb2019-03-23 14:04:36 -070020 allow_files = True,
21 ),
22 "_gen_embedded": attr.label(
23 executable = True,
24 default = Label("//aos/seasocks:gen_embedded"),
Adam Snaider13d48d92023-08-03 12:20:15 -070025 cfg = "exec",
Brian Silvermanacdabeb2019-03-23 14:04:36 -070026 ),
27 },
28 output_to_genfiles = True,
29 outputs = {
30 "source": "embedded.cc",
31 },
32 implementation = _gen_embedded_impl,
Brian Silverman049dcb62015-09-27 19:08:00 -040033)
34
Brian Silvermanacdabeb2019-03-23 14:04:36 -070035"""Generates the header for Seasocks to load the embedded files.
Brian Silverman049dcb62015-09-27 19:08:00 -040036
37This always outputs a file named "embedded.h" in the current package, so there
38can be a maximum of one of these rules in each package.
39
40Attrs:
41 srcs: Files to allow loading.
Brian Silvermanacdabeb2019-03-23 14:04:36 -070042"""
43
Philipp Schraderdada1072020-11-24 11:34:46 -080044def gen_embedded(name, srcs, visibility = None, target_compatible_with = None):
Austin Schuh8e17be92019-12-24 09:32:11 -080045 _do_gen_embedded(
46 name = name + "__do_gen",
47 visibility = ["//visibility:private"],
48 srcs = srcs,
Philipp Schraderdada1072020-11-24 11:34:46 -080049 target_compatible_with = target_compatible_with,
Austin Schuh8e17be92019-12-24 09:32:11 -080050 )
51 native.cc_library(
52 name = name,
53 visibility = visibility,
54 linkstatic = True,
55 srcs = [
56 ":%s__do_gen" % name,
57 ],
58 deps = [
Austin Schuh6c066392022-08-17 20:31:10 -070059 "//third_party/seasocks",
Austin Schuh8e17be92019-12-24 09:32:11 -080060 ],
Philipp Schraderdada1072020-11-24 11:34:46 -080061 target_compatible_with = target_compatible_with,
Austin Schuh8e17be92019-12-24 09:32:11 -080062 )