# Any targets that should be shared between fbcode and xplat must be defined in
# targets.bzl. This file can contain fbcode-only targets.

load("@fbsource//xplat/executorch/backends:backends.bzl", "get_all_cpu_aot_and_backend_targets")
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
load(":targets.bzl", "define_common_targets")

oncall("executorch")

define_common_targets()

# Use runtime.python_library instead of the one defined in python_library.bzl,
# so we can have access to EXECUTORCH_CLIENTS list.
runtime.python_library(
    name = "backend_api",
    srcs = [
        "backend_api.py",
    ],
    visibility = [
        "//executorch/...",
        "//executorch/test/...",
        "@EXECUTORCH_CLIENTS",
    ],
    deps = [
        ":backend_details",
        ":compile_spec_schema",
        "//caffe2:torch",
        "//executorch/exir/backend:utils",
        "//executorch/exir/backend/canonical_partitioners:duplicate_constant_node_pass",
    ],
)

runtime.python_library(
    name = "compile_spec_schema",
    srcs = [
        "compile_spec_schema.py",
    ],
    visibility = [
        "//executorch/...",
        "//executorch/test/...",
        "@EXECUTORCH_CLIENTS",
    ],
)

runtime.python_library(
    name = "operator_support",
    srcs = [
        "operator_support.py",
    ],
    visibility = [
        "//executorch/...",
        "//executorch/test/...",
        "@EXECUTORCH_CLIENTS",
    ],
)

runtime.python_library(
    name = "partitioner",
    srcs = [
        "partitioner.py",
    ],
    visibility = [
        "//executorch/...",
        "//executorch/test/...",
        "@EXECUTORCH_CLIENTS",
    ],
    deps = [
        ":compile_spec_schema",
        "//caffe2:torch",
    ],
)

runtime.python_library(
    name = "backend_details",
    srcs = [
        "backend_details.py",
    ],
    visibility = [
        "//executorch/...",
        "//executorch/test/...",
        "@EXECUTORCH_CLIENTS",
    ],
    deps = [
        ":compile_spec_schema",
        ":partitioner",
        "//caffe2:torch",
        "//executorch/exir:delegate",
        "//executorch/exir:graph_module",
    ],
)

# backend_lib includes all ahead of time apis and supported backends,
# it's supposed to be only used on server side and not for production on device.
runtime.python_library(
    name = "backend_lib",
    visibility = [
        "//executorch/...",
        "//executorch/test/...",
        "@EXECUTORCH_CLIENTS",
    ],
    deps = [
        ":backend_api",
        ":backend_details",
        ":utils",
        "//executorch/exir/backend/canonical_partitioners:canonical_partitioner_lib",
    ] + get_all_cpu_aot_and_backend_targets(),
)

runtime.python_library(
    name = "utils",
    srcs = [
        "utils.py",
    ],
    visibility = [
        "//executorch/...",
        "//executorch/exir/backend/...",
        "//executorch/test/...",
        "@EXECUTORCH_CLIENTS",
    ],
    deps = [
        "fbsource//third-party/pypi/pandas:pandas",
        "//caffe2:torch",
        "//executorch/exir:lowered_backend_module",
        "//executorch/exir/backend/canonical_partitioners:duplicate_constant_node_pass",
    ],
)
