xref: /aosp_15_r20/external/executorch/runtime/executor/targets.bzl (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
2
3def _program_preprocessor_flags():
4    """Returns the preprocessor_flags to use when building Program.cpp"""
5
6    # The code for flatbuffer verification can add ~30k of .text to the binary.
7    # It's a valuable feature, but make it optional for space-constrained
8    # systems.
9    enable_verification = native.read_config(
10        "executorch",
11        "enable_program_verification",
12        # Default value
13        "true",
14    )
15    if enable_verification == "false":
16        return ["-DET_ENABLE_PROGRAM_VERIFICATION=0"]
17    elif enable_verification == "true":
18        # Enabled by default.
19        return []
20    else:
21        fail("executorch.enable_program_verification must be one of 'true' or 'false'; saw '" +
22             enable_verification + "'")
23
24def define_common_targets():
25    """Defines targets that should be shared between fbcode and xplat.
26
27    The directory containing this targets.bzl file should also contain both
28    TARGETS and BUCK files that call this function.
29    """
30
31    runtime.cxx_library(
32        name = "memory_manager",
33        exported_headers = [
34            "memory_manager.h",
35        ],
36        exported_deps = [
37            "//executorch/runtime/core:memory_allocator",
38        ],
39        visibility = [
40            "//executorch/...",
41            "@EXECUTORCH_CLIENTS",
42        ],
43    )
44
45    for aten_mode in (True, False):
46        aten_suffix = "_aten" if aten_mode else ""
47        runtime.cxx_library(
48            name = "program" + aten_suffix,
49            exported_deps = [
50                ":program_no_prim_ops" + aten_suffix,
51                "//executorch/kernels/prim_ops:prim_ops_registry" + aten_suffix,
52            ],
53            visibility = [
54                "//executorch/runtime/executor/...",
55                "@EXECUTORCH_CLIENTS",
56            ],
57        )
58
59        runtime.cxx_library(
60            name = "program_no_prim_ops" + aten_suffix,
61            srcs = [
62                "method.cpp",
63                "method_meta.cpp",
64                "program.cpp",
65                "tensor_parser_exec_aten.cpp",
66                "tensor_parser{}.cpp".format(aten_suffix if aten_mode else "_portable"),
67            ],
68            headers = [
69                "platform_memory_allocator.h",
70            ],
71            exported_headers = [
72                "method.h",
73                "method_meta.h",
74                "program.h",
75                "tensor_parser.h",
76            ],
77            preprocessor_flags = _program_preprocessor_flags(),
78            exported_deps = [
79                ":memory_manager",
80                "//executorch/runtime/backend:interface",
81                "//executorch/runtime/core:core",
82                "//executorch/runtime/core:evalue" + aten_suffix,
83                "//executorch/runtime/core:event_tracer" + aten_suffix,
84                "//executorch/runtime/core/exec_aten:lib" + aten_suffix,
85                "//executorch/runtime/core/exec_aten/util:tensor_util" + aten_suffix,
86                "//executorch/runtime/kernel:kernel_runtime_context" + aten_suffix,
87                "//executorch/runtime/kernel:operator_registry",
88                "//executorch/runtime/platform:platform",
89                "//executorch/schema:extended_header",
90            ],
91            deps = [
92                "//executorch/schema:program",
93            ],
94            visibility = [
95                "//executorch/runtime/executor/...",
96                "@EXECUTORCH_CLIENTS",
97            ],
98        )
99