1load("@fbsource//xplat/executorch/build/runtime_wrapper.bzl", "runtime") 2load(":flatcc_defs.bzl", "define_flatcc_targets") 3load(":gflags.bzl", "define_gflags") 4load(":glob_defs.bzl", "subdir_glob") 5load(":gtest_defs.bzl", "define_gtest_targets") 6load(":prebuilt_python_defs.bzl", "add_prebuilt_python_library_targets") 7load("@prelude//rules.bzl", "prebuilt_cxx_library") 8 9define_gflags() 10 11define_gtest_targets() 12 13prebuilt_python_library_defs = { 14 "prettytable": { 15 "additional_deps": [":wcwidth"], 16 "out": "prettytable-3.8.0-py3-none-any.whl", 17 "sha1": "22a8347abd5a72e4ea8d5f5bb2956d956148e6fa", 18 "url": "https://files.pythonhosted.org/packages/25/1e/4c284713b092ec384fad4399452f43f6446ad9aabc9c0b3c3c0920cc53b6/prettytable-3.8.0-py3-none-any.whl", 19 }, 20 "pyyaml": { 21 "out": "pyyaml.whl", 22 "sha1": "11aa9c5fe2d890b6a73212beadc7c8a4265ebc39", 23 "url": "https://files.pythonhosted.org/packages/12/fc/a4d5a7554e0067677823f7265cb3ae22aed8a238560b5133b58cda252dad/PyYAML-6.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", 24 }, 25 "typing-extensions": { 26 "out": "typing_extensions-4.2.0-py3-none-any.whl", 27 "sha1": "ff0849420e94f425818bff5d0f25e3cdfaba8601", 28 "url": "https://files.pythonhosted.org/packages/75/e1/932e06004039dd670c9d5e1df0cd606bf46e29a28e65d5bb28e894ea29c9/typing_extensions-4.2.0-py3-none-any.whl", 29 }, 30 "wcwidth": { 31 "out": "wcwidth-0.1.5-py2.py3-none-any.whl", 32 "sha1": "f132a6fdff56d1d8bf572f00ef6985a327784bbd", 33 "url": "https://files.pythonhosted.org/packages/8b/30/f46badba94cedcd5ceb5918a7c5a34f3a1b9e902e045b7d8d39c1db3d99a/wcwidth-0.1.5-py2.py3-none-any.whl", 34 }, 35} 36 37add_prebuilt_python_library_targets(prebuilt_python_library_defs) 38 39runtime.genrule( 40 name = "torchgen_files", 41 outs = { 42 "torchgen": ["torchgen"], 43 }, 44 default_outs = ["."], 45 srcs = ["link_torch.sh"], 46 bash = "bash $SRCS -f torchgen -o ${OUT}", 47) 48 49runtime.genrule( 50 name = "yaml_files", 51 outs = { 52 "tags": ["aten/src/ATen/native/tags.yaml"], 53 "native_functions": ["aten/src/ATen/native/native_functions.yaml"], 54 }, 55 default_outs = ["."], 56 srcs = ["link_torch.sh"], 57 bash = "mkdir -p ${OUT}/aten/src/ATen/native/ && bash $SRCS -f torchgen/packaged/ATen/native/tags.yaml,torchgen/packaged/ATen/native/native_functions.yaml -o ${OUT}/aten/src/ATen/native/", 58) 59 60runtime.python_library( 61 name = "torchgen", 62 srcs = [":torchgen_files[torchgen]"] + glob(["**/*.py"]), 63 base_module = "torchgen,torchgen.executorch", 64 visibility = ["PUBLIC"], 65 deps = [ 66 "//third-party:pyyaml", 67 "//third-party:typing-extensions", 68 ], 69 _is_external_target = True, 70) 71 72runtime.python_binary( 73 name = "gen", 74 main_module = "torchgen.gen", 75 visibility = [ 76 "PUBLIC", 77 ], 78 deps = [ 79 ":torchgen", 80 ], 81 _is_external_target = True, 82) 83 84runtime.python_binary( 85 name = "gen_executorch", 86 main_module = "torchgen.gen_executorch", 87 visibility = [ 88 "PUBLIC", 89 ], 90 deps = [ 91 ":torchgen", 92 ], 93 _is_external_target = True, 94) 95 96runtime.filegroup( 97 name = "aten_src_path", 98 srcs = [ 99 ":yaml_files[tags]", 100 ":yaml_files[native_functions]", 101 ], 102 visibility = [ 103 "PUBLIC", 104 ], 105 _is_external_target = True, 106) 107 108runtime.cxx_library( 109 name = "flatbuffers-api", 110 public_include_directories = ["flatbuffers/include"], 111 raw_headers = [ 112 "flatbuffers/include/flatbuffers/base.h", 113 "flatbuffers/include/flatbuffers/flatbuffers.h", 114 "flatbuffers/include/flatbuffers/stl_emulation.h", 115 ], 116 link_style = "static", 117 visibility = ["PUBLIC"], 118 _is_external_target = True, 119) 120 121define_flatcc_targets() 122 123runtime.cxx_library( 124 name = "flatc_library", 125 srcs = [ 126 "flatbuffers/src/idl_gen_text.cpp", 127 "flatbuffers/src/idl_parser.cpp", 128 "flatbuffers/src/reflection.cpp", 129 "flatbuffers/src/util.cpp", 130 ], 131 public_include_directories = [ 132 "flatbuffers/grpc", 133 "flatbuffers/include", 134 ], 135 raw_headers = [ 136 "flatbuffers/include/flatbuffers/allocator.h", 137 "flatbuffers/include/flatbuffers/array.h", 138 "flatbuffers/include/flatbuffers/base.h", 139 "flatbuffers/include/flatbuffers/buffer.h", 140 "flatbuffers/include/flatbuffers/buffer_ref.h", 141 "flatbuffers/include/flatbuffers/code_generator.h", 142 "flatbuffers/include/flatbuffers/default_allocator.h", 143 "flatbuffers/include/flatbuffers/detached_buffer.h", 144 "flatbuffers/include/flatbuffers/file_manager.h", 145 "flatbuffers/include/flatbuffers/flatbuffer_builder.h", 146 "flatbuffers/include/flatbuffers/flatbuffers.h", 147 "flatbuffers/include/flatbuffers/flex_flat_util.h", 148 "flatbuffers/include/flatbuffers/flexbuffers.h", 149 "flatbuffers/include/flatbuffers/hash.h", 150 "flatbuffers/include/flatbuffers/idl.h", 151 "flatbuffers/include/flatbuffers/minireflect.h", 152 "flatbuffers/include/flatbuffers/reflection.h", 153 "flatbuffers/include/flatbuffers/reflection_generated.h", 154 "flatbuffers/include/flatbuffers/registry.h", 155 "flatbuffers/include/flatbuffers/stl_emulation.h", 156 "flatbuffers/include/flatbuffers/string.h", 157 "flatbuffers/include/flatbuffers/struct.h", 158 "flatbuffers/include/flatbuffers/table.h", 159 "flatbuffers/include/flatbuffers/util.h", 160 "flatbuffers/include/flatbuffers/vector.h", 161 "flatbuffers/include/flatbuffers/vector_downward.h", 162 "flatbuffers/include/flatbuffers/verifier.h", 163 ], 164 link_style = "static", 165 visibility = ["PUBLIC"], 166 _is_external_target = True, 167) 168 169runtime.cxx_binary( 170 name = "flatc", 171 srcs = [ 172 "flatbuffers/grpc/src/compiler/cpp_generator.cc", 173 "flatbuffers/grpc/src/compiler/go_generator.cc", 174 "flatbuffers/grpc/src/compiler/java_generator.cc", 175 "flatbuffers/grpc/src/compiler/python_generator.cc", 176 "flatbuffers/grpc/src/compiler/swift_generator.cc", 177 "flatbuffers/grpc/src/compiler/ts_generator.cc", 178 "flatbuffers/src/annotated_binary_text_gen.cpp", 179 "flatbuffers/src/bfbs_gen_lua.cpp", 180 "flatbuffers/src/bfbs_gen_nim.cpp", 181 "flatbuffers/src/binary_annotator.cpp", 182 "flatbuffers/src/code_generators.cpp", 183 "flatbuffers/src/file_binary_writer.cpp", 184 "flatbuffers/src/file_name_saving_file_manager.cpp", 185 "flatbuffers/src/file_writer.cpp", 186 "flatbuffers/src/flatc.cpp", 187 "flatbuffers/src/flatc_main.cpp", 188 "flatbuffers/src/idl_gen_binary.cpp", 189 "flatbuffers/src/idl_gen_cpp.cpp", 190 "flatbuffers/src/idl_gen_csharp.cpp", 191 "flatbuffers/src/idl_gen_dart.cpp", 192 "flatbuffers/src/idl_gen_fbs.cpp", 193 "flatbuffers/src/idl_gen_go.cpp", 194 "flatbuffers/src/idl_gen_grpc.cpp", 195 "flatbuffers/src/idl_gen_java.cpp", 196 "flatbuffers/src/idl_gen_json_schema.cpp", 197 "flatbuffers/src/idl_gen_kotlin.cpp", 198 "flatbuffers/src/idl_gen_kotlin_kmp.cpp", 199 "flatbuffers/src/idl_gen_lobster.cpp", 200 "flatbuffers/src/idl_gen_php.cpp", 201 "flatbuffers/src/idl_gen_python.cpp", 202 "flatbuffers/src/idl_gen_rust.cpp", 203 "flatbuffers/src/idl_gen_swift.cpp", 204 "flatbuffers/src/idl_gen_text.cpp", 205 "flatbuffers/src/idl_gen_ts.cpp", 206 ], 207 include_directories = [ 208 "flatbuffers/grpc", 209 "flatbuffers/include", 210 ], 211 raw_headers = [ 212 "flatbuffers/grpc/src/compiler/cpp_generator.h", 213 "flatbuffers/grpc/src/compiler/go_generator.h", 214 "flatbuffers/grpc/src/compiler/java_generator.h", 215 "flatbuffers/grpc/src/compiler/python_generator.h", 216 "flatbuffers/grpc/src/compiler/schema_interface.h", 217 "flatbuffers/grpc/src/compiler/swift_generator.h", 218 "flatbuffers/grpc/src/compiler/ts_generator.h", 219 "flatbuffers/include/flatbuffers/code_generators.h", 220 "flatbuffers/src/annotated_binary_text_gen.h", 221 "flatbuffers/src/bfbs_gen.h", 222 "flatbuffers/src/bfbs_gen_lua.h", 223 "flatbuffers/src/bfbs_gen_nim.h", 224 "flatbuffers/src/bfbs_namer.h", 225 "flatbuffers/src/binary_annotator.h", 226 "flatbuffers/src/idl_namer.h", 227 "flatbuffers/src/namer.h", 228 ], 229 visibility = ["PUBLIC"], 230 deps = [":flatc_library"], 231 link_style = "static", 232 _is_external_target = True, 233) 234 235runtime.genrule( 236 name = "libpython_gen", 237 outs = { 238 "include": ["include"], 239 }, 240 srcs = ["link_python.sh"], 241 bash = select({ 242 "ovr_config//os:macos": "bash $SRCS $OUT libpython.dylib", 243 "DEFAULT": "bash $SRCS $OUT libpython.so", 244 }), 245) 246 247runtime.cxx_library( 248 name = "pybind11", 249 public_include_directories = [ 250 "pybind11/include", 251 ], 252 exported_preprocessor_flags = [ 253 "-I$(location :libpython_gen[include])", # include header directories 254 ], 255 exported_linker_flags = ["-Xlinker", "-undefined", "-Xlinker", "dynamic_lookup"], 256 raw_headers = glob(["pybind11/include/**/*.h"]), 257 visibility = ["PUBLIC"], 258 _is_external_target = True, 259) 260 261runtime.genrule( 262 name = "libtorch_gen", 263 outs = select({ 264 "ovr_config//os:macos": { 265 "libtorch": ["libtorch.dylib"], 266 "libc10": ["libc10.dylib"], 267 "libtorch_cpu": ["libtorch_cpu.dylib"], 268 "libtorch_python": ["libtorch_python.dylib"], 269 "include": ["include"], 270 }, 271 "DEFAULT": { 272 "libtorch": ["libtorch.so"], 273 "libc10": ["libc10.so"], 274 "libtorch_cpu": ["libtorch_cpu.so"], 275 "libtorch_python": ["libtorch_python.so"], 276 "include": ["include"], 277 }, 278 }), 279 default_outs = ["."], 280 srcs = ["link_torch.sh"], 281 bash = select({ 282 "ovr_config//os:macos": "bash $SRCS -f torch/lib/libtorch.dylib,torch/lib/libtorch_cpu.dylib,torch/lib/libtorch_python.dylib,torch/lib/libc10.dylib,torch/include -o ${OUT}", 283 "DEFAULT": "bash $SRCS -f torch/lib/libtorch.so,torch/lib/libtorch_cpu.so,torch/lib/libtorch_python.so,torch/lib/libc10.so,torch/lib/libgomp-a34b3233.so.1,torch/include -o ${OUT}", 284 }), 285) 286 287prebuilt_cxx_library( 288 name = "libc10", 289 shared_lib = ":libtorch_gen[libc10]", 290) 291 292prebuilt_cxx_library( 293 name = "libtorch_cpu", 294 shared_lib = ":libtorch_gen[libtorch_cpu]", 295) 296 297prebuilt_cxx_library( 298 name = "libtorch", 299 shared_lib = ":libtorch_gen[libtorch]", 300 exported_preprocessor_flags = [ 301 "-D_GLIBCXX_USE_CXX11_ABI=0", # `libtorch` is built without CXX11_ABI so any target depends on it need to use the same build config. 302 "-I$(location :libtorch_gen[include])", # include header directories 303 "-I$(location :libtorch_gen[include])/torch/csrc/api/include", # include header directories 304 ], 305 exported_linker_flags = select({ 306 "ovr_config//os:macos": ["-Xlinker", "-rpath", "$(location :libtorch_gen)", "-Xlinker"], 307 "DEFAULT": ["-Wl,-rpath,$(location :libtorch_gen)"], # define rpath to locate shared library 308 }), 309 exported_headers = [":libtorch_gen[include]"], 310 exported_deps = select({ 311 "ovr_config//os:macos": [":libc10", ":libtorch_cpu"], 312 "DEFAULT": [":libc10", ":libtorch_cpu"], 313 }), 314 visibility = ["PUBLIC"], 315) 316 317prebuilt_cxx_library( 318 name = "libtorch_python", 319 shared_lib = ":libtorch_gen[libtorch_python]", 320 exported_preprocessor_flags = [ 321 "-D_GLIBCXX_USE_CXX11_ABI=0", # `libtorch` is built without CXX11_ABI so any target depends on it need to use the same build config. 322 "-I$(location :libtorch_gen[include])", # include header directories 323 "-I$(location :libtorch_gen[include])/torch/csrc/api/include", # include header directories 324 ], 325 exported_linker_flags = select({ 326 "ovr_config//os:macos": ["-ldl", "-framework", "CoreFoundation"], # python3-config --cflags 327 "DEFAULT": [], # define rpath to locate shared library 328 }), 329 exported_headers = [":libtorch_gen[include]"], 330 exported_deps = [ 331 ":libtorch", 332 ], 333 visibility = ["PUBLIC"], 334) 335