1load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "get_oss_build_kwargs", "is_xplat", "runtime") 2load("@fbsource//xplat/executorch/codegen:codegen.bzl", "et_operator_library", "executorch_generated_lib") 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 # Select all ops: register all the ops in portable/functions.yaml 12 et_operator_library( 13 name = "select_all_ops", 14 include_all_operators = True, 15 ) 16 17 executorch_generated_lib( 18 name = "select_all_lib", 19 functions_yaml_target = "//executorch/kernels/portable:functions.yaml", 20 kernel_deps = [ 21 "//executorch/kernels/portable:operators", 22 ], 23 deps = [ 24 ":select_all_ops", 25 ], 26 ) 27 28 # Select a list of operators: defined in `ops` 29 et_operator_library( 30 name = "select_ops_in_list", 31 ops = [ 32 "aten::add.out", 33 "aten::mm.out", 34 ], 35 ) 36 37 executorch_generated_lib( 38 name = "select_ops_in_list_lib", 39 functions_yaml_target = "//executorch/kernels/portable:functions.yaml", 40 kernel_deps = [ 41 "//executorch/kernels/portable:operators", 42 ], 43 deps = [ 44 ":select_ops_in_list", 45 ], 46 ) 47 48 # Select a dictionary of ops with kernel metadata 49 et_operator_library( 50 name = "select_ops_in_dict", 51 ops_dict = { 52 "aten::add.out": ["v1/3;0,1", "v1/6;0,1"], # int, float 53 "aten::mm.out": [], # all dtypes 54 }, 55 ) 56 57 executorch_generated_lib( 58 name = "select_ops_in_dict_lib", 59 functions_yaml_target = "//executorch/kernels/portable:functions.yaml", 60 kernel_deps = [ 61 "//executorch/kernels/portable:operators", 62 ], 63 deps = [ 64 ":select_ops_in_dict", 65 ], 66 dtype_selective_build = True, 67 visibility = ["//executorch/..."], 68 ) 69 70 # Select all ops from a yaml file 71 et_operator_library( 72 name = "select_ops_from_yaml", 73 ops_schema_yaml_target = "//executorch/examples/portable/custom_ops:custom_ops.yaml", 74 ) 75 76 executorch_generated_lib( 77 name = "select_ops_from_yaml_lib", 78 custom_ops_yaml_target = "//executorch/examples/portable/custom_ops:custom_ops.yaml", 79 kernel_deps = [ 80 "//executorch/examples/portable/custom_ops:custom_ops_1", 81 "//executorch/examples/portable/custom_ops:custom_ops_2", 82 ], 83 deps = [ 84 ":select_ops_from_yaml", 85 ], 86 ) 87 88 # Select all ops from a given model 89 # TODO(larryliu0820): Add this 90 91 if not runtime.is_oss and not is_xplat(): 92 runtime.genrule( 93 name = "add_mul_model", 94 outs = {"add_mul": ["add_mul.pte"]}, 95 cmd = "$(exe fbcode//executorch/examples/portable/scripts:export) --model_name add_mul --output_dir $OUT", 96 macros_only = False, 97 visibility = ["//executorch/..."], 98 ) 99 100 et_operator_library( 101 name = "select_ops_from_model", 102 model = ":add_mul_model[add_mul]", 103 ) 104 105 executorch_generated_lib( 106 name = "select_ops_from_model_lib", 107 functions_yaml_target = "//executorch/kernels/portable:functions.yaml", 108 kernel_deps = ["//executorch/kernels/portable:operators"], 109 deps = [":select_ops_from_model"], 110 visibility = ["//executorch/kernels/..."], 111 ) 112 113 # ~~~ Test binary for selective build ~~~ 114 select_ops = native.read_config("executorch", "select_ops", None) 115 lib = [] 116 if select_ops == "all": 117 lib.append(":select_all_lib") 118 elif select_ops == "list": 119 lib.append(":select_ops_in_list_lib") 120 elif select_ops == "dict": 121 lib.append(":select_ops_in_dict_lib") 122 elif select_ops == "yaml": 123 lib.append(":select_ops_from_yaml_lib") 124 elif select_ops == "model": 125 lib.append(":select_ops_from_model_lib") 126 runtime.cxx_binary( 127 name = "selective_build_test", 128 srcs = [], 129 deps = [ 130 "//executorch/examples/portable/executor_runner:executor_runner_lib", 131 ] + lib, 132 define_static_target = True, 133 **get_oss_build_kwargs() 134 ) 135