1load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") 2 3def event_tracer_enabled(): 4 return native.read_config("executorch", "event_tracer_enabled", "false") == "true" 5 6def get_event_tracer_flags(): 7 event_tracer_flags = [] 8 if event_tracer_enabled(): 9 event_tracer_flags += ["-DET_EVENT_TRACER_ENABLED"] 10 return event_tracer_flags 11 12def build_sdk(): 13 return native.read_config("executorch", "build_sdk", "false") == "true" 14 15def get_sdk_flags(): 16 sdk_flags = [] 17 if build_sdk(): 18 sdk_flags += ["-DEXECUTORCH_BUILD_DEVTOOLS"] 19 return sdk_flags 20 21def define_common_targets(): 22 """Defines targets that should be shared between fbcode and xplat. 23 24 The directory containing this targets.bzl file should also contain both 25 TARGETS and BUCK files that call this function. 26 """ 27 28 runtime.cxx_library( 29 name = "core", 30 exported_headers = [ 31 "array_ref.h", # TODO(T157717874): Migrate all users to span and then move this to portable_type 32 "data_loader.h", 33 "error.h", 34 "freeable_buffer.h", 35 "result.h", 36 "span.h", 37 ], 38 visibility = [ 39 "//executorch/...", 40 "@EXECUTORCH_CLIENTS", 41 ], 42 exported_deps = [ 43 "//executorch/runtime/platform:platform", 44 ], 45 ) 46 47 runtime.cxx_library( 48 name = "tensor_shape_dynamism", 49 exported_headers = [ 50 "tensor_shape_dynamism.h", 51 ], 52 visibility = [ 53 "//executorch/runtime/core/exec_aten/...", 54 "//executorch/runtime/core/portable_type/...", 55 ], 56 ) 57 58 runtime.cxx_library( 59 name = "memory_allocator", 60 exported_headers = [ 61 "hierarchical_allocator.h", 62 "memory_allocator.h", 63 ], 64 exported_deps = [ 65 ":core", 66 ], 67 visibility = [ 68 "//executorch/...", 69 "@EXECUTORCH_CLIENTS", 70 ], 71 ) 72 73 for aten_mode in (True, False): 74 aten_suffix = ("_aten" if aten_mode else "") 75 runtime.cxx_library( 76 name = "evalue" + aten_suffix, 77 exported_headers = [ 78 "evalue.h", 79 ], 80 srcs = ["evalue.cpp"], 81 visibility = [ 82 "//executorch/...", 83 "@EXECUTORCH_CLIENTS", 84 ], 85 exported_deps = [ 86 "//executorch/runtime/core:core", 87 "//executorch/runtime/core/exec_aten:lib" + aten_suffix, 88 ":tag", 89 ], 90 ) 91 92 runtime.cxx_library( 93 name = "event_tracer" + aten_suffix, 94 exported_headers = [ 95 "event_tracer.h", 96 "event_tracer_hooks.h", 97 "event_tracer_hooks_delegate.h", 98 ], 99 visibility = [ 100 "//executorch/...", 101 "@EXECUTORCH_CLIENTS", 102 ], 103 exported_preprocessor_flags = get_event_tracer_flags() + get_sdk_flags(), 104 exported_deps = [ 105 "//executorch/runtime/platform:platform", 106 "//executorch/runtime/core:evalue" + aten_suffix, 107 ], 108 ) 109 110 runtime.cxx_library( 111 name = "tag", 112 exported_headers = [ 113 "tag.h", 114 ], 115 visibility = [ 116 "//executorch/...", 117 ], 118 ) 119