xref: /aosp_15_r20/external/executorch/extension/pybindings/TARGETS (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1# Any targets that should be shared between fbcode and xplat must be defined in
2# targets.bzl. This file can contain fbcode-only targets.
3
4load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
5load("@fbsource//xplat/executorch/extension/pybindings:pybindings.bzl", "ATEN_MODULE_DEPS", "MODELS_ATEN_OPS_ATEN_MODE_GENERATED_LIB", "MODELS_ATEN_OPS_LEAN_MODE_GENERATED_LIB", "PORTABLE_MODULE_DEPS", "executorch_pybindings")
6
7oncall("executorch")
8
9# Export this so the internal fb/ subdir can create pybindings with custom internal deps
10# without forking the pybinding source.
11runtime.export_file(
12    name = "pybindings.cpp",
13    visibility = ["//executorch/extension/pybindings/..."],
14)
15
16# cxx_python_extension kwarg 'types' can't take export_file rules directly and we need to rename the .pyi
17# file to match the lib anyway, so we just expose the file like this and then have genrules consume and
18# rename it before passing it to executorch pybindings.
19runtime.filegroup(
20    name = "pybinding_types",
21    srcs = ["pybindings.pyi"],
22    visibility = ["//executorch/extension/pybindings/..."],
23)
24
25# In order to have pyre recognize the pybindings module, the name of the .pyi must exactly match the
26# name of the lib. To avoid copy pasting the pyi file in tree a whole bunch of times we use genrules
27# to do it for us
28runtime.genrule(
29    name = "pybindings_types_gen",
30    srcs = [":pybinding_types"],
31    outs = {
32        "aten_lib.pyi": ["aten_lib.pyi"],
33        "core.pyi": ["core.pyi"],
34        "_portable_lib.pyi": ["_portable_lib.pyi"],
35    },
36    cmd = "cp $(location :pybinding_types)/* $OUT/_portable_lib.pyi && cp $(location :pybinding_types)/* $OUT/aten_lib.pyi && cp $(location :pybinding_types)/* $OUT/core.pyi",
37    visibility = ["//executorch/extension/pybindings/..."],
38)
39
40executorch_pybindings(
41    compiler_flags = ["-std=c++17"],
42    cppdeps = PORTABLE_MODULE_DEPS,
43    python_module_name = "core",
44    types = ["//executorch/extension/pybindings:pybindings_types_gen[core.pyi]"],
45    visibility = ["PUBLIC"],
46)
47
48executorch_pybindings(
49    compiler_flags = ["-std=c++17"],
50    cppdeps = PORTABLE_MODULE_DEPS + MODELS_ATEN_OPS_LEAN_MODE_GENERATED_LIB,
51    # Give this an underscore prefix because it has a pure python wrapper.
52    python_module_name = "_portable_lib",
53    types = ["//executorch/extension/pybindings:pybindings_types_gen[_portable_lib.pyi]"],
54    visibility = ["PUBLIC"],
55)
56
57executorch_pybindings(
58    compiler_flags = ["-std=c++17"],
59    cppdeps = ATEN_MODULE_DEPS + MODELS_ATEN_OPS_ATEN_MODE_GENERATED_LIB,
60    python_module_name = "aten_lib",
61    types = ["//executorch/extension/pybindings:pybindings_types_gen[aten_lib.pyi]"],
62    visibility = ["PUBLIC"],
63)
64
65runtime.python_library(
66    name = "portable_lib",
67    srcs = ["portable_lib.py"],
68    visibility = [
69        "//executorch/exir/...",
70        "//executorch/runtime/...",
71        "@EXECUTORCH_CLIENTS",
72    ],
73    deps = [":_portable_lib"],
74)
75