1load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") 2load("@fbsource//xplat/executorch/codegen:codegen.bzl", "et_operator_library", "executorch_generated_lib", "exir_custom_ops_aot_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 runtime.export_file( 11 name = "custom_ops.yaml", 12 visibility = [ 13 "//executorch/...", 14 "@EXECUTORCH_CLIENTS", 15 ], 16 ) 17 18 # ~~~ START of custom ops 1 `my_ops::mul3` library definitions ~~~ 19 et_operator_library( 20 name = "select_custom_ops_1", 21 ops = [ 22 "my_ops::mul3.out", 23 ], 24 define_static_targets = True, 25 visibility = [ 26 "//executorch/codegen/...", 27 "@EXECUTORCH_CLIENTS", 28 ], 29 ) 30 31 runtime.cxx_library( 32 name = "custom_ops_1", 33 srcs = ["custom_ops_1_out.cpp"], 34 deps = [ 35 "//executorch/runtime/kernel:kernel_includes", 36 ], 37 visibility = [ 38 "//executorch/...", 39 "@EXECUTORCH_CLIENTS", 40 ], 41 ) 42 43 executorch_generated_lib( 44 name = "lib_1", 45 deps = [ 46 ":select_custom_ops_1", 47 ":custom_ops_1", 48 ], 49 custom_ops_yaml_target = ":custom_ops.yaml", 50 visibility = [ 51 "//executorch/...", 52 "@EXECUTORCH_CLIENTS", 53 ], 54 ) 55 56 # ~~~ END of custom ops 1 `my_ops::mul3` library definitions ~~~ 57 # ~~~ START of custom ops 2 `my_ops::mul4` library definitions ~~~ 58 59 et_operator_library( 60 name = "select_custom_ops_2", 61 ops = [ 62 "my_ops::mul4.out", 63 ], 64 define_static_targets = True, 65 visibility = [ 66 "//executorch/codegen/...", 67 "@EXECUTORCH_CLIENTS", 68 ], 69 ) 70 71 runtime.cxx_library( 72 name = "custom_ops_2", 73 srcs = ["custom_ops_2_out.cpp"], 74 deps = [ 75 "//executorch/runtime/kernel:kernel_includes", 76 ], 77 visibility = [ 78 "//executorch/...", 79 "@EXECUTORCH_CLIENTS", 80 ], 81 ) 82 83 runtime.cxx_library( 84 name = "custom_ops_2_aten", 85 srcs = [ 86 "custom_ops_2.cpp", 87 "custom_ops_2_out.cpp", 88 ], 89 deps = [ 90 "//executorch/runtime/kernel:kernel_includes_aten", 91 ], 92 visibility = [ 93 "//executorch/...", 94 "@EXECUTORCH_CLIENTS", 95 ], 96 external_deps = ["libtorch"], 97 # @lint-ignore BUCKLINT link_whole 98 link_whole = True, 99 # WARNING: using a deprecated API to avoid being built into a shared 100 # library. In the case of dynamically loading so library we don't want 101 # it to depend on other so libraries because that way we have to 102 # specify library directory path. 103 force_static = True, 104 ) 105 106 exir_custom_ops_aot_lib( 107 name = "custom_ops_aot_lib_2", 108 yaml_target = ":custom_ops.yaml", 109 visibility = ["//executorch/..."], 110 kernels = [":custom_ops_2_aten"], 111 deps = [ 112 ":select_custom_ops_2", 113 ], 114 ) 115 116 executorch_generated_lib( 117 name = "lib_2", 118 deps = [ 119 ":select_custom_ops_2", 120 ":custom_ops_2", 121 ], 122 custom_ops_yaml_target = ":custom_ops.yaml", 123 visibility = [ 124 "//executorch/...", 125 "@EXECUTORCH_CLIENTS", 126 ], 127 ) 128 # ~~~ END of custom ops 2 `my_ops::mul4` library definitions ~~~ 129