1load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cpp_toolchain", "use_cc_toolchain")
2
3def _pico_btstack_make_gatt_header_impl(ctx):
4    cc_toolchain = find_cpp_toolchain(ctx)
5    feature_configuration = cc_common.configure_features(
6        ctx = ctx,
7        cc_toolchain = cc_toolchain,
8        requested_features = ctx.features,
9        unsupported_features = ctx.disabled_features,
10    )
11
12    out = ctx.actions.declare_file(
13        "{}_gatt_generated/{}.h".format(ctx.label.name, ctx.file.src.basename.removesuffix(".gatt")),
14    )
15
16    ctx.actions.run(
17        executable = ctx.executable._make_gat_header_tool,
18        arguments = [
19            ctx.file.src.path,
20            out.path,
21            "-I",
22            ctx.file._btstack_hdr.dirname,
23        ] + [
24
25        ],
26        inputs = [
27            ctx.file.src,
28            ctx.file._btstack_hdr,
29        ],
30        outputs = [out],
31    )
32
33    cc_ctx = cc_common.create_compilation_context(
34        headers = depset(direct = [out]),
35        includes = depset(direct = [out.dirname]),
36    )
37
38    return [
39        DefaultInfo(files = depset(direct = [out])),
40        CcInfo(compilation_context = cc_ctx)
41    ]
42
43pico_btstack_make_gatt_header = rule(
44    implementation = _pico_btstack_make_gatt_header_impl,
45    attrs = {
46        "src": attr.label(mandatory = True, allow_single_file = True),
47        "_btstack_hdr": attr.label(
48            default = "@btstack//:src/bluetooth_gatt.h",
49            allow_single_file = True,
50        ),
51        "_make_gat_header_tool": attr.label(
52            default = "@btstack//:compile_gatt",
53            cfg = "exec",
54            executable = True,
55        ),
56    },
57    fragments = ["cpp"],
58    toolchains = use_cc_toolchain(),
59)
60