xref: /aosp_15_r20/external/executorch/backends/apple/mps/targets.bzl (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1#
2#  Copyright (c) 2023 Apple Inc. All rights reserved.
3#  Provided subject to the LICENSE file in the top level directory.
4#
5
6load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
7
8def define_common_targets(is_xplat = False, platforms = []):
9    """Defines targets that should be shared between fbcode and xplat.
10
11    The directory containing this targets.bzl file should also contain both
12    TARGETS and BUCK files that call this function.
13    """
14    kwargs = {
15        "name": "mps",
16        "compiler_flags": [
17            "-DEXIR_MPS_DELEGATE=1",
18            "-Wno-global-constructors",
19            "-Wno-missing-prototypes",
20            "-Wno-nullable-to-nonnull-conversion",
21            "-Wno-undeclared-selector",
22            "-Wno-unused-const-variable",
23            "-Wno-unused-variable",
24            "-fno-objc-arc",
25            "-std=c++17",
26        ],
27        "deps": [
28            "//executorch/runtime/core:core",
29            "//executorch/runtime/core/exec_aten/util:tensor_util",
30            ":mps_schema",
31        ],
32        "exported_deps": [
33            "//executorch/runtime/backend:interface",
34            ":mps_schema",
35        ],
36        "headers": native.glob([
37            "runtime/*.h",
38            "runtime/operations/*.h",
39        ]),
40        "srcs": native.glob([
41            "runtime/*.mm",
42            "runtime/operations/*.mm",
43        ]),
44        "visibility": [
45            "//executorch/backends/apple/...",
46            "//executorch/examples/...",
47            "//executorch/exir/backend:backend_lib",
48            "//executorch/extension/pybindings/...",
49            "//executorch/runtime/backend/...",
50            "//executorch/devtools/runners/...",
51            "//executorch/test/...",
52            "@EXECUTORCH_CLIENTS",
53        ],
54        "link_whole": True,
55    }
56
57    if is_xplat:
58        kwargs["fbobjc_frameworks"] = [
59            "Foundation",
60            "Metal",
61            "MetalPerformanceShaders",
62            "MetalPerformanceShadersGraph",
63        ]
64        kwargs["platforms"] = platforms
65
66    if runtime.is_oss or is_xplat:
67        runtime.genrule(
68            name = "gen_mps_schema",
69            srcs = [
70                "serialization/schema.fbs",
71            ],
72            outs = {
73                "schema_generated.h": ["schema_generated.h"],
74            },
75            cmd = " ".join([
76                "$(exe {})".format(runtime.external_dep_location("flatc")),
77                "--cpp",
78                "--cpp-std c++11",
79                "--scoped-enums",
80                "-o ${OUT}",
81                "${SRCS}",
82            ]),
83            default_outs = ["."],
84        )
85
86        runtime.cxx_library(
87            name = "mps_schema",
88            srcs = [],
89            exported_headers = {
90                "schema_generated.h": ":gen_mps_schema[schema_generated.h]",
91            },
92            exported_external_deps = ["flatbuffers-api"],
93            visibility = [
94                "//executorch/backends/apple/...",
95                "//executorch/examples/...",
96            ],
97        )
98
99        runtime.cxx_library(**kwargs)
100