Brian Silverman | 049dcb6 | 2015-09-27 19:08:00 -0400 | [diff] [blame] | 1 | def _gen_embedded_impl(ctx): |
Philipp Schrader | 5dd9eda | 2020-11-08 10:16:35 -0800 | [diff] [blame] | 2 | ctx.actions.run( |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 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 Silverman | 049dcb6 | 2015-09-27 19:08:00 -0400 | [diff] [blame] | 10 | |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 11 | return struct( |
| 12 | files = depset([ctx.outputs.source]), |
| 13 | ) |
Brian Silverman | 049dcb6 | 2015-09-27 19:08:00 -0400 | [diff] [blame] | 14 | |
| 15 | _do_gen_embedded = rule( |
Brian Silverman | acdabeb | 2019-03-23 14:04:36 -0700 | [diff] [blame] | 16 | attrs = { |
| 17 | "srcs": attr.label_list( |
| 18 | mandatory = True, |
Austin Schuh | 849954c | 2020-09-10 23:11:57 -0700 | [diff] [blame] | 19 | allow_empty = False, |
Brian Silverman | acdabeb | 2019-03-23 14:04:36 -0700 | [diff] [blame] | 20 | allow_files = True, |
| 21 | ), |
| 22 | "_gen_embedded": attr.label( |
| 23 | executable = True, |
| 24 | default = Label("//aos/seasocks:gen_embedded"), |
Adam Snaider | 13d48d9 | 2023-08-03 12:20:15 -0700 | [diff] [blame^] | 25 | cfg = "exec", |
Brian Silverman | acdabeb | 2019-03-23 14:04:36 -0700 | [diff] [blame] | 26 | ), |
| 27 | }, |
| 28 | output_to_genfiles = True, |
| 29 | outputs = { |
| 30 | "source": "embedded.cc", |
| 31 | }, |
| 32 | implementation = _gen_embedded_impl, |
Brian Silverman | 049dcb6 | 2015-09-27 19:08:00 -0400 | [diff] [blame] | 33 | ) |
| 34 | |
Brian Silverman | acdabeb | 2019-03-23 14:04:36 -0700 | [diff] [blame] | 35 | """Generates the header for Seasocks to load the embedded files. |
Brian Silverman | 049dcb6 | 2015-09-27 19:08:00 -0400 | [diff] [blame] | 36 | |
| 37 | This always outputs a file named "embedded.h" in the current package, so there |
| 38 | can be a maximum of one of these rules in each package. |
| 39 | |
| 40 | Attrs: |
| 41 | srcs: Files to allow loading. |
Brian Silverman | acdabeb | 2019-03-23 14:04:36 -0700 | [diff] [blame] | 42 | """ |
| 43 | |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 44 | def gen_embedded(name, srcs, visibility = None, target_compatible_with = None): |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 45 | _do_gen_embedded( |
| 46 | name = name + "__do_gen", |
| 47 | visibility = ["//visibility:private"], |
| 48 | srcs = srcs, |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 49 | target_compatible_with = target_compatible_with, |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 50 | ) |
| 51 | native.cc_library( |
| 52 | name = name, |
| 53 | visibility = visibility, |
| 54 | linkstatic = True, |
| 55 | srcs = [ |
| 56 | ":%s__do_gen" % name, |
| 57 | ], |
| 58 | deps = [ |
Austin Schuh | 6c06639 | 2022-08-17 20:31:10 -0700 | [diff] [blame] | 59 | "//third_party/seasocks", |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 60 | ], |
Philipp Schrader | dada107 | 2020-11-24 11:34:46 -0800 | [diff] [blame] | 61 | target_compatible_with = target_compatible_with, |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 62 | ) |