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