xref: /aosp_15_r20/external/executorch/codegen/tools/targets.bzl (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
2
3def define_common_targets(is_fbcode = False):
4    """Defines targets that should be shared between fbcode and xplat.
5
6    The directory containing this targets.bzl file should also contain both
7    TARGETS and BUCK files that call this function.
8
9    See README.md for instructions on selective build.
10    """
11    runtime.python_library(
12        name = "gen_oplist_lib",
13        srcs = ["gen_oplist.py"],
14        base_module = "executorch.codegen.tools",
15        visibility = [
16            "//executorch/...",
17        ],
18        external_deps = ["torchgen"],
19        deps = select({
20            "DEFAULT": [],
21            "ovr_config//os:linux": [] if runtime.is_oss else ["//executorch/codegen/tools/fb:selective_build"],  # TODO(larryliu0820) :selective_build doesn't build in OSS yet
22        }),
23    )
24
25    runtime.python_binary(
26        name = "gen_oplist",
27        main_module = "executorch.codegen.tools.gen_oplist",
28        deps = [
29            ":gen_oplist_lib",
30        ],
31        package_style = "inplace",
32        visibility = [
33            "//executorch/...",
34            "@EXECUTORCH_CLIENTS",
35        ],
36    )
37
38    runtime.python_library(
39        name = "yaml_util",
40        base_module = "executorch.codegen.tools",
41        srcs = ["yaml_util.py"],
42    )
43
44    runtime.python_library(
45        name = "merge_yaml_lib",
46        srcs = ["merge_yaml.py"],
47        base_module = "executorch.codegen.tools",
48        deps = [
49            ":yaml_util",
50        ],
51        external_deps = ["torchgen"],
52    )
53
54    runtime.python_binary(
55        name = "merge_yaml",
56        main_module = "executorch.codegen.tools.merge_yaml",
57        deps = [
58            ":merge_yaml_lib",
59        ],
60        package_style = "inplace",
61        _is_external_target = True,
62        visibility = ["PUBLIC"],
63    )
64
65    runtime.python_test(
66        name = "test_gen_oplist",
67        base_module = "",
68        srcs = [
69            "test/test_gen_oplist.py",
70        ],
71        deps = [
72            ":gen_oplist_lib",
73        ],
74        package_style = "inplace",
75        visibility = [
76            "//executorch/...",
77            "@EXECUTORCH_CLIENTS",
78        ],
79    )
80
81    runtime.python_library(
82        name = "gen_oplist_copy_from_core",
83        srcs = [
84            "gen_oplist_copy_from_core.py",
85        ],
86        base_module = "tools_copy.code_analyzer",
87        external_deps = ["torchgen"],
88    )
89
90    runtime.python_library(
91        name = "gen_all_oplist_lib",
92        srcs = ["gen_all_oplist.py"],
93        base_module = "executorch.codegen.tools",
94        visibility = [
95            "//executorch/...",
96        ],
97        deps = [":gen_oplist_copy_from_core"],
98    )
99
100    runtime.python_binary(
101        name = "gen_all_oplist",
102        main_module = "executorch.codegen.tools.gen_all_oplist",
103        package_style = "inplace",
104        visibility = [
105            "PUBLIC",
106        ],
107        deps = [
108            ":gen_all_oplist_lib",
109        ],
110        _is_external_target = True,
111    )
112
113    runtime.python_test(
114        name = "test_gen_all_oplist",
115        srcs = [
116            "test/test_gen_all_oplist.py",
117        ],
118        package_style = "inplace",
119        visibility = [
120            "PUBLIC",
121        ],
122        deps = [
123            ":gen_all_oplist_lib",
124        ],
125        _is_external_target = True,
126    )
127
128    runtime.python_library(
129        name = "gen_selected_op_variants_lib",
130        srcs = ["gen_selected_op_variants.py"],
131        base_module = "executorch.codegen.tools",
132        visibility = ["//executorch/..."],
133        deps = [":gen_oplist_copy_from_core"],
134    )
135
136    runtime.python_binary(
137        name = "gen_selected_op_variants",
138        main_module = "executorch.codegen.tools.gen_selected_op_variants",
139        package_style = "inplace",
140        visibility = [
141            "PUBLIC",
142        ],
143        deps = [
144            ":gen_selected_op_variants_lib",
145        ],
146        _is_external_target = True,
147    )
148
149    runtime.python_test(
150        name = "test_gen_selected_op_variants",
151        srcs = [
152            "test/test_gen_selected_op_variants.py",
153        ],
154        package_style = "inplace",
155        visibility = [
156            "PUBLIC",
157        ],
158        deps = [
159            ":gen_selected_op_variants_lib",
160            "fbsource//third-party/pypi/expecttest:expecttest",
161        ],
162        _is_external_target = True,
163    )
164
165    # TODO(larryliu0820): This is a hack to only run these two on fbcode. These targets depends on exir which is only available in fbcode.
166    if not runtime.is_oss and is_fbcode:
167        runtime.python_binary(
168            name = "gen_functions_yaml",
169            srcs = ["gen_ops_def.py"],
170            main_module = "executorch.codegen.tools.gen_ops_def",
171            package_style = "inplace",
172            visibility = [
173                "//executorch/...",
174                "@EXECUTORCH_CLIENTS",
175            ],
176            deps = [
177                "fbsource//third-party/pypi/pyyaml:pyyaml",
178                ":yaml_util",
179                "//caffe2:torch",
180                "//executorch/exir:schema",
181                "//executorch/exir/_serialize:lib",
182            ],
183        )
184
185        runtime.python_test(
186            name = "test_gen_oplist_real_model",
187            srcs = ["test/test_gen_oplist_real_model.py"],
188            base_module = "",
189            resources = {
190                "//executorch/test/models:exported_programs[ModuleLinear.pte]": "test/ModuleLinear.pte",
191            },
192            visibility = [
193                "//executorch/...",
194            ],
195            deps = [
196                ":gen_oplist_lib",
197                "//libfb/py:parutil",
198            ],
199        )
200