blob: d281027de45355c6599f3714fc216786830a33f3 [file] [log] [blame]
Alex Perrycb7da4b2019-08-28 19:35:56 -07001load("//tools/build_rules:label.bzl", "expand_label")
Austin Schuh83cbb1e2023-06-23 12:59:02 -07002load("//tools/build_rules:select.bzl", "address_size_select")
Alex Perrycb7da4b2019-08-28 19:35:56 -07003
James Kuszmaulc0c08da2020-05-10 18:56:07 -07004AosConfigInfo = provider(fields = [
5 "transitive_flatbuffers",
6 "transitive_src",
7])
Alex Perrycb7da4b2019-08-28 19:35:56 -07008
Philipp Schraderdada1072020-11-24 11:34:46 -08009def aos_config(name, src, flatbuffers = [], deps = [], visibility = None, testonly = False, target_compatible_with = None):
Alex Perrycb7da4b2019-08-28 19:35:56 -070010 _aos_config(
11 name = name,
12 src = src,
Austin Schuh83cbb1e2023-06-23 12:59:02 -070013 flags = address_size_select({
14 "32": ["--max_queue_size_override=0xffff"],
15 "64": ["--max_queue_size_override=0xffffffff"],
16 }),
James Kuszmaul7aa19332022-09-07 20:39:18 -070017 config_json = name + ".json",
18 config_stripped = name + ".stripped.json",
19 config_binary = name + ".bfbs",
Alex Perrycb7da4b2019-08-28 19:35:56 -070020 deps = deps,
21 flatbuffers = [expand_label(flatbuffer) + "_reflection_out" for flatbuffer in flatbuffers],
22 visibility = visibility,
Austin Schuh14d7d3d2020-09-10 18:14:36 -070023 testonly = testonly,
Philipp Schraderdada1072020-11-24 11:34:46 -080024 target_compatible_with = target_compatible_with,
Alex Perrycb7da4b2019-08-28 19:35:56 -070025 )
26
27def _aos_config_impl(ctx):
James Kuszmaul7aa19332022-09-07 20:39:18 -070028 config = ctx.outputs.config_json
29 stripped_config = ctx.outputs.config_stripped
30 binary_config = ctx.outputs.config_binary
Austin Schuh14d7d3d2020-09-10 18:14:36 -070031
Alex Perrycb7da4b2019-08-28 19:35:56 -070032 flatbuffers_depset = depset(
33 ctx.files.flatbuffers,
34 transitive = [dep[AosConfigInfo].transitive_flatbuffers for dep in ctx.attr.deps],
35 )
36
37 src_depset = depset(
38 ctx.files.src,
39 transitive = [dep[AosConfigInfo].transitive_src for dep in ctx.attr.deps],
40 )
41
42 all_files = flatbuffers_depset.to_list() + src_depset.to_list()
43 ctx.actions.run(
Austin Schuh15182322020-10-10 15:25:21 -070044 outputs = [config, stripped_config, binary_config],
Alex Perrycb7da4b2019-08-28 19:35:56 -070045 inputs = all_files,
Austin Schuh83cbb1e2023-06-23 12:59:02 -070046 arguments = ctx.attr.flags + [
Austin Schuh3f31eb52020-09-16 15:04:45 -070047 config.path,
48 stripped_config.path,
Austin Schuh15182322020-10-10 15:25:21 -070049 binary_config.path,
Austin Schuh3f31eb52020-09-16 15:04:45 -070050 (ctx.label.workspace_root or ".") + "/" + ctx.files.src[0].short_path,
51 ctx.bin_dir.path,
52 ] + [f.path for f in flatbuffers_depset.to_list()],
Alex Perrycb7da4b2019-08-28 19:35:56 -070053 progress_message = "Flattening config",
54 executable = ctx.executable._config_flattener,
55 )
Austin Schuh15182322020-10-10 15:25:21 -070056 runfiles = ctx.runfiles(files = [config, stripped_config, binary_config])
Austin Schuh14d7d3d2020-09-10 18:14:36 -070057 return [
58 DefaultInfo(
Austin Schuh15182322020-10-10 15:25:21 -070059 files = depset([config, stripped_config, binary_config]),
Austin Schuh14d7d3d2020-09-10 18:14:36 -070060 runfiles = runfiles,
61 ),
62 AosConfigInfo(
63 transitive_flatbuffers = flatbuffers_depset,
64 transitive_src = src_depset,
65 ),
66 ]
Alex Perrycb7da4b2019-08-28 19:35:56 -070067
68_aos_config = rule(
69 attrs = {
James Kuszmaul7aa19332022-09-07 20:39:18 -070070 "config_json": attr.output(mandatory = True),
71 "config_stripped": attr.output(mandatory = True),
72 "config_binary": attr.output(mandatory = True),
Alex Perrycb7da4b2019-08-28 19:35:56 -070073 "_config_flattener": attr.label(
74 executable = True,
75 cfg = "host",
76 default = Label("//aos:config_flattener"),
77 ),
78 "src": attr.label(
79 mandatory = True,
80 allow_files = True,
81 ),
Austin Schuh83cbb1e2023-06-23 12:59:02 -070082 "flags": attr.string_list(
83 doc = "Additional flags to pass to config_flattener.",
84 ),
Alex Perrycb7da4b2019-08-28 19:35:56 -070085 "deps": attr.label_list(
86 providers = [AosConfigInfo],
87 ),
88 "flatbuffers": attr.label_list(
89 mandatory = False,
90 ),
91 },
Alex Perrycb7da4b2019-08-28 19:35:56 -070092 implementation = _aos_config_impl,
93)