1load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") 2load("@fbsource//xplat/executorch/kernels/portable:op_registration_util.bzl", "ATEN_OPS", "CUSTOM_OPS", "define_op_target") 3 4def define_common_targets(): 5 """Defines targets that should be shared between fbcode and xplat. 6 7 The directory containing this targets.bzl file should also contain both 8 TARGETS and BUCK files that call this function. 9 """ 10 11 # Define build targets for all operators registered in the tables above. 12 for op in ATEN_OPS: 13 define_op_target(is_aten_op = True, **op) 14 for op in CUSTOM_OPS: 15 define_op_target(is_aten_op = False, **op) 16 17 custom_op_targets = [":{}".format(op["name"]) for op in CUSTOM_OPS] 18 19 aten_op_targets = [":{}".format(op["name"]) for op in ATEN_OPS] 20 all_op_targets = custom_op_targets + aten_op_targets 21 22 runtime.cxx_library( 23 name = "cpu", 24 srcs = [], 25 visibility = [ 26 "//executorch/kernels/portable/...", 27 "//executorch/kernels/test/...", 28 ], 29 exported_deps = all_op_targets, 30 ) 31 32 runtime.cxx_library( 33 name = "cpu_aten", 34 srcs = [], 35 visibility = ["//executorch/kernels/portable/..."], 36 exported_deps = [t + "_aten" for t in custom_op_targets], 37 ) 38 39 # Only for use by op targets under //executorch. This API needs to be 40 # reevaluated before becoming a public API. 41 runtime.cxx_library( 42 name = "vec_ops", 43 srcs = [], 44 exported_headers = ["vec_ops.h"], 45 visibility = ["//executorch/kernels/portable/cpu/...", "//executorch/kernels/quantized/..."], 46 ) 47 48 # Only for use by targets in this directory. Defines constants like M_PI 49 # if they arent already defined by the toolchains cmath 50 runtime.cxx_library( 51 name = "math_constants", 52 srcs = [], 53 exported_headers = [ 54 "math_constants.h", 55 ], 56 visibility = [ 57 "//executorch/kernels/portable/cpu/...", 58 ], 59 ) 60 61 # Only for use by targets in this directory. 62 runtime.cxx_library( 63 name = "scalar_utils", 64 srcs = [], 65 exported_headers = ["scalar_utils.h", "selective_build.h"], 66 visibility = [ 67 "//executorch/kernels/portable/cpu/...", 68 "//executorch/kernels/optimized/cpu/...", 69 "//executorch/kernels/portable/test/...", 70 "@EXECUTORCH_CLIENTS", 71 ], 72 deps = [ 73 "//executorch/runtime/core/exec_aten:lib", 74 "//executorch/runtime/core/exec_aten/util:scalar_type_util", 75 ], 76 ) 77 78 # Used for dtype selective build. Collect source and header files. 79 runtime.filegroup( 80 name = "portable_source_files", 81 srcs = native.glob(["*.cpp"]), 82 visibility = ["//executorch/...", "@EXECUTORCH_CLIENTS"], 83 ) 84 85 runtime.filegroup( 86 name = "portable_header_files", 87 srcs = native.glob(["*.h"]), 88 visibility = ["//executorch/...", "@EXECUTORCH_CLIENTS"], 89 ) 90