#
#  Copyright (c) 2023 Apple Inc. All rights reserved.
#  Provided subject to the LICENSE file in the top level directory.
#

# 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/build:runtime_wrapper.bzl", "runtime")
load(":targets.bzl", "define_common_targets")

oncall("executorch")

define_common_targets()

runtime.python_library(
    name = "backend",
    srcs = [
        "__init__.py",
        "mps_preprocess.py",
    ],
    visibility = [
        "@EXECUTORCH_CLIENTS",
    ],
    deps = [
        ":operators",
        ":serialization",
        ":utils",
        "//caffe2:torch",
        "//executorch/exir/backend:backend_details",
        "//executorch/exir/backend:compile_spec_schema",
    ],
)

runtime.python_library(
    name = "operators",
    srcs = glob([
        "operators/*.py",
    ]),
    deps = [
        ":serialization",
        ":utils",
        "//executorch/backends/transforms:lib",
    ],
)

runtime.python_library(
    name = "partitioner",
    srcs = glob([
        "partition/*.py",
    ]),
    visibility = [
        "@EXECUTORCH_CLIENTS",
    ],
    deps = [
        ":backend",
        "//caffe2:torch",
        "//executorch/exir/backend:compile_spec_schema",
        "//executorch/exir/backend:partitioner",
        "//executorch/exir/backend/canonical_partitioners:canonical_partitioner_lib",
    ],
)

runtime.python_library(
    name = "serialization",
    srcs = glob([
        "serialization/*.py",
    ]),
    resources = [
        "serialization/schema.fbs",
    ],
)

runtime.python_library(
    name = "utils",
    srcs = glob([
        "utils/*.py",
    ]),
    deps = [
        ":serialization",
        "//caffe2:torch",
        "//executorch/exir:lib",
    ],
)

runtime.python_test(
    name = "test",
    srcs = glob([
        "test/*.py",
    ]),
    deps = [
        ":backend",
        ":partitioner",
        "//caffe2:torch",
        "//executorch/examples/models:models",
        "//executorch/exir/tests:models",
        "//executorch/extension/export_util:export_util",
        "//executorch/devtools:lib",
        "//executorch/devtools/bundled_program/serialize:lib",
        "fbsource//third-party/pypi/pytest:pytest",
    ],
)
