blob: 34d4bd8ab20c4fb064f289c7b0a775384ab8ca09 [file] [log] [blame]
Brian Silverman049dcb62015-09-27 19:08:00 -04001def _gen_embedded_impl(ctx):
2 ctx.action(
3 inputs = ctx.files.srcs,
Brian Silvermanacdabeb2019-03-23 14:04:36 -07004 outputs = [ ctx.outputs.source ],
Brian Silverman049dcb62015-09-27 19:08:00 -04005 executable = ctx.executable._gen_embedded,
Brian Silvermanacdabeb2019-03-23 14:04:36 -07006 arguments = [ ctx.outputs.source.path ] + [f.path for f in ctx.files.srcs],
7 progress_message = 'Generating %s' % ctx.outputs.source.short_path,
Brian Silverman049dcb62015-09-27 19:08:00 -04008 mnemonic = 'GenEmbedded',
9 )
10
11 return struct(
Brian Silvermanacdabeb2019-03-23 14:04:36 -070012 files = depset([ ctx.outputs.source ]),
Brian Silverman049dcb62015-09-27 19:08:00 -040013 )
14
15_do_gen_embedded = rule(
Brian Silvermanacdabeb2019-03-23 14:04:36 -070016 attrs = {
17 "srcs": attr.label_list(
18 mandatory = True,
19 non_empty = True,
20 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):
45 _do_gen_embedded(
46 name = name + '__do_gen',
47 visibility = ['//visibility:private'],
48 srcs = srcs,
49 )
50 native.cc_library(
51 name = name,
Brian Silvermanacdabeb2019-03-23 14:04:36 -070052 visibility = visibility,
53 linkstatic = True,
54 srcs = [
Brian Silverman049dcb62015-09-27 19:08:00 -040055 ':%s__do_gen' % name,
56 ],
Brian Silvermanacdabeb2019-03-23 14:04:36 -070057 deps = [
58 '@//third_party/seasocks',
59 ],
Brian Silverman049dcb62015-09-27 19:08:00 -040060 )