|
| 1 | +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "get_oss_build_kwargs", "runtime") |
| 2 | +load("@fbsource//xplat/executorch/codegen:codegen.bzl", "et_operator_library", "executorch_generated_lib") |
| 3 | + |
| 4 | +def 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 | + deps = [ |
| 21 | + "//executorch/kernels/portable:operators", |
| 22 | + ":select_all_ops", |
| 23 | + ], |
| 24 | + ) |
| 25 | + |
| 26 | + # Select a list of operators: defined in `ops` |
| 27 | + et_operator_library( |
| 28 | + name = "select_ops_in_list", |
| 29 | + ops = [ |
| 30 | + "aten::add.out", |
| 31 | + "aten::mm.out", |
| 32 | + ], |
| 33 | + ) |
| 34 | + |
| 35 | + executorch_generated_lib( |
| 36 | + name = "select_ops_in_list_lib", |
| 37 | + functions_yaml_target = "//executorch/kernels/portable:functions.yaml", |
| 38 | + deps = [ |
| 39 | + "//executorch/kernels/portable:operators", |
| 40 | + ":select_ops_in_list", |
| 41 | + ], |
| 42 | + ) |
| 43 | + |
| 44 | + # Select all ops from a yaml file |
| 45 | + et_operator_library( |
| 46 | + name = "select_ops_from_yaml", |
| 47 | + ops_schema_yaml_target = "//executorch/examples/custom_ops:custom_ops.yaml", |
| 48 | + ) |
| 49 | + |
| 50 | + executorch_generated_lib( |
| 51 | + name = "select_ops_from_yaml_lib", |
| 52 | + custom_ops_yaml_target = "//executorch/examples/custom_ops:custom_ops.yaml", |
| 53 | + deps = [ |
| 54 | + "//executorch/examples/custom_ops:custom_ops_1", |
| 55 | + "//executorch/examples/custom_ops:custom_ops_2", |
| 56 | + ":select_ops_from_yaml", |
| 57 | + ], |
| 58 | + ) |
| 59 | + |
| 60 | + # Select all ops from a given model |
| 61 | + # TODO(larryliu0820): Add this |
| 62 | + |
| 63 | + # ~~~ Test binary for selective build ~~~ |
| 64 | + select_ops = native.read_config("executorch", "select_ops", None) |
| 65 | + lib = [] |
| 66 | + if select_ops == "all": |
| 67 | + lib.append(":select_all_lib") |
| 68 | + elif select_ops == "list": |
| 69 | + lib.append(":select_ops_in_list_lib") |
| 70 | + elif select_ops == "yaml": |
| 71 | + lib.append(":select_ops_from_yaml_lib") |
| 72 | + runtime.cxx_binary( |
| 73 | + name = "selective_build_test", |
| 74 | + srcs = [], |
| 75 | + deps = [ |
| 76 | + "//executorch/examples/executor_runner:executor_runner_lib", |
| 77 | + ] + lib, |
| 78 | + define_static_target = True, |
| 79 | + **get_oss_build_kwargs() |
| 80 | + ) |
0 commit comments