xref: /aosp_15_r20/external/executorch/backends/xnnpack/third-party/xnnpack_src_defs.bzl (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1load(
2    "//backends/xnnpack/third-party/XNNPACK:build_srcs.bzl",
3    _LOGGING_SRCS = "LOGGING_SRCS",
4    _OPERATOR_SRCS = "OPERATOR_SRCS",
5    _SUBGRAPH_SRCS = "SUBGRAPH_SRCS",
6    _TABLE_SRCS = "TABLE_SRCS",
7    _XNNPACK_SRCS = "XNNPACK_SRCS",
8)
9load("//backends/xnnpack/third-party/XNNPACK/gen:microkernels.bzl", "prod_srcs_for_arch")
10load("//third-party:glob_defs.bzl", "subdir_glob")
11
12def define_xnnpack_build_src(xnnpack_build_src):
13    return ["XNNPACK/{}".format(src) for src in xnnpack_build_src]
14
15def prod_srcs_for_arch_wrapper(arch):
16    prod_srcs = prod_srcs_for_arch(arch)
17    return define_xnnpack_build_src(prod_srcs)
18
19def get_xnnpack_headers():
20    # XNNPACK Headers in the path containing xnnpack/ or configs/
21    # do not contain the src/ path. However headers not in xnnpack/ or
22    # configs/ are prepend with the src/ path. This function helps us
23    # to correctly parse all the header files to the correct name
24    src_headers = subdir_glob([
25        ("XNNPACK/src", "**/*.h"),
26    ])
27    fixed_headers = {}
28    for k, v in src_headers.items():
29        new_key = k
30        if not k.startswith("xnnpack") and not k.startswith("configs"):
31            new_key = "src/{}".format(k)
32        fixed_headers[new_key] = v
33    include_headers = subdir_glob([
34        ("XNNPACK/include", "*.h"),
35    ])
36
37    return fixed_headers | include_headers
38
39OPERATOR_SRCS = define_xnnpack_build_src(_OPERATOR_SRCS)
40SUBGRAPH_SRCS = define_xnnpack_build_src(_SUBGRAPH_SRCS)
41TABLE_SRCS = define_xnnpack_build_src(_TABLE_SRCS)
42XNNPACK_SRCS = define_xnnpack_build_src(_XNNPACK_SRCS)
43LOGGING_SRCS = define_xnnpack_build_src(_LOGGING_SRCS)
44