load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target")
oncall("executorch")
# add this empty BUCK file to unblock landing. Without this, we get land error:
#   "No build file at xplat/executorch/exir/BUCK when resolving target fbsource//xplat/executorch/exir:."


# !!!! fbcode/executorch/exir/TARGETS was merged into this file, see https://fburl.com/workplace/xl8l9yuo for more info !!!!

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


fbcode_target(_kind = runtime.python_library,
    name = "tracer",
    srcs = [
        "tracer.py",
    ],
    deps = [
        "fbsource//third-party/pypi/typing-extensions:typing-extensions",
        ":common",
        ":error",
        ":graph_module",
        ":types",
        "//caffe2:torch",
        "//executorch/exir/operator:convert",
        "//executorch/exir/operator:util",
        "//executorch/extension/pytree:pylib",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "graph",
    srcs = [
        "graph.py",
    ],
    deps = [
        ":tensor",
        "//caffe2:torch",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "graph_module",
    srcs = [
        "graph_module.py",
    ],
    deps = [
        "//caffe2:torch",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "scalar_type",
    srcs = [
        "scalar_type.py",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "schema",
    srcs = [
        "schema.py",
    ],
    deps = [
        ":scalar_type",
        "//executorch/exir/backend:compile_spec_schema",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "version",
    srcs = [
        "version.py",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "tensor",
    srcs = [
        "tensor.py",
    ],
    deps = [
        ":error",
        ":schema",
        "//caffe2:torch",
        "//executorch/exir:sym_util",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "tensor_layout",
    srcs = [
        "tensor_layout.py",
    ],
    deps = [
        ":scalar_type",
        ":tensor",
    ]
)

fbcode_target(_kind = runtime.python_library,
    name = "memory",
    srcs = [
        "memory.py",
    ],
    deps = [
        "fbsource//third-party/pypi/typing-extensions:typing-extensions",
        ":tensor",
        "//caffe2:torch",
        "//executorch/exir:sym_util",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "control_flow",
    srcs = [
        "control_flow.py",
    ],
    deps = [
        ":error",
        ":tracer",
        ":wrap",
        "//caffe2:torch",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "delegate",
    srcs = [
        "delegate.py",
        "delegate.pyi",
    ],
    deps = [
        "//caffe2:torch",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "lowered_backend_module",
    srcs = [
        "lowered_backend_module.py",
    ],
    deps = [
        ":delegate",
        ":graph_module",
        ":schema",
        ":tracer",
        "//caffe2:torch",
        "//executorch/exir/_serialize:lib",
        "//executorch/exir/backend:backend_details",
        "//executorch/exir/backend:compile_spec_schema",
        "//executorch/exir/emit:lib",
        "//executorch/exir/passes:delegate_scratch_pass",
        "//executorch/exir/passes:memory_planning_pass",
        "//executorch/exir/passes:spec_prop_pass",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "lib",
    srcs = [
        "__init__.py",
    ],
    deps = [
        ":tracer",
        "//caffe2:torch",
        "//executorch/exir/capture:lib",
        "//executorch/exir/emit:lib",
        "//executorch/exir/program:lib",
        "//executorch/exir/serde:serialize",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "inplace_aliasing",
    srcs = [
        "inplace_aliasing.py",
    ],
    deps = [
        ":error",
        ":tensor",
        "//caffe2:torch",
        "//executorch/exir/operator:convert",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "memory_planning",
    srcs = [
        "memory_planning.py",
    ],
    deps = [
        ":control_flow",
        ":delegate",
        ":error",
        ":inplace_aliasing",
        ":memory",
        ":schema",
        ":tensor",
        "//caffe2:torch",
        "//executorch/exir/operator:convert",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "banked_memory_planning",
    srcs = [
        "banked_memory_planning.py",
    ],
    deps = [
        ":memory_planning",
        ":tensor",
        "//caffe2:torch",
        "//executorch/exir/passes:memory_planning_pass",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "common",
    srcs = [
        "common.py",
    ],
    deps = [
        "//caffe2:torch",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "error",
    srcs = [
        "error.py",
    ],
    deps = [],
)

fbcode_target(_kind = runtime.python_library,
    name = "types",
    srcs = [
        "types.py",
    ],
    deps = [
        "fbsource//third-party/pypi/typing-extensions:typing-extensions",
        ":tensor",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "wrap",
    srcs = [
        "wrap.py",
    ],
    deps = [
        ":tracer",
        "//caffe2:torch",
        "//caffe2/functorch:functorch",  # @manual
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "print_program",
    srcs = [
        "print_program.py",
    ],
    deps = [
        ":error",
        ":schema",
        "//caffe2:torch",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "dynamic_shape",
    srcs = [
        "dynamic_shape.py",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "pass_base",
    srcs = [
        "pass_base.py",
    ],
    deps = [
        ":delegate",
        ":error",
        ":memory",
        "//caffe2:torch",
        "//executorch/exir/dialects:lib",
        "//executorch/exir/dialects/edge:lib",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "_program_utils",
    srcs = [
        "_program_utils.py",
    ],
    deps = [
        "//caffe2:torch",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "pass_manager",
    srcs = [
        "pass_manager.py",
    ],
    deps = [
        "fbsource//third-party/pypi/typing-extensions:typing-extensions",
        ":_program_utils",
        ":error",
        ":pass_base",
        "//caffe2:torch",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "sym_util",
    srcs = ["sym_util.py"],
    deps = [
        "fbsource//third-party/pypi/sympy:sympy",
        "//caffe2:torch",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "dim_order_utils",
    srcs = ["dim_order_utils.py"],
    deps = [
        "//caffe2:torch",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "_warnings",
    srcs = ["_warnings.py"],
    deps = [
        "fbsource//third-party/pypi/typing-extensions:typing-extensions",
    ],
)

fbcode_target(_kind = runtime.python_library,
    name = "debug_handle_utils",
    srcs = ["debug_handle_utils.py"],
    deps = [
        "//caffe2:torch",
    ],
)
