blob: 5bdb80da40917cfc1fdd333db7cb67b58fb37d7b [file] [log] [blame]
Brian Silverman049dcb62015-09-27 19:08:00 -04001def _gen_embedded_impl(ctx):
Austin Schuh8e17be92019-12-24 09:32:11 -08002 ctx.action(
3 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"),
25 cfg = "host",
26 ),
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
Brian Silverman049dcb62015-09-27 19:08:00 -040044def gen_embedded(name, srcs, visibility = None):
Austin Schuh8e17be92019-12-24 09:32:11 -080045 _do_gen_embedded(
46 name = name + "__do_gen",
47 visibility = ["//visibility:private"],
48 srcs = srcs,
49 )
50 native.cc_library(
51 name = name,
52 visibility = visibility,
53 linkstatic = True,
54 srcs = [
55 ":%s__do_gen" % name,
56 ],
57 deps = [
58 "@//third_party/seasocks",
59 ],
60 )