From 4f6b1421bc1176423c510a176691cbaac130cd2f Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Thu, 2 Jul 2026 14:30:23 -0700 Subject: [PATCH] promote TARGETS content into placeholder BUCK files (#20407) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/20407 Chunk 4 of fbcode/executorch TARGETS->BUCK migration. 9 directories where TARGETS contained the real fbcode-side build rules and BUCK was a tiny placeholder (most were 4-8 lines like 'empty BUCK file to unblock landing'). Each TARGETS was scanned for fbcode-only constructs (`fbcode_macros`, `fbcode_target(`, `cpp_unittest(`, `cpp_library(`, `cpp_binary(`, `re_test_utils`, `keep_gpu_sections`, `buck_genrule`, `//tools/build/buck/`) and only those without any of those flags are migrated here. The TARGETS content is copied into BUCK (overwriting the placeholder) and the TARGETS file is deleted. fbcode now resolves these dirs via BUCK instead of TARGETS; the rules also become visible to xplat for the first time via dirsync. Directories migrated: - backends/apple/mps - backends/xnnpack/serialization - devtools/bundled_program - devtools/bundled_program/schema - devtools/etdump/fb - exir/emit - extension/pytree - extension/training - kernels/portable/test 8 PROMOTE candidates remain on TARGETS for follow-up: backends/cortex_m/test, examples/models/llama/fb, examples/qualcomm/oss_scripts/{llama,whisper}, exir/dialects/edge/test, exir/tests, kernels/fb/custom_ops, test/end2end. They have fbcode-only loads (`fbcode_macros`) or kwargs and need `is_fbcode()` gating. Reviewed By: mzlee Differential Revision: D109082058 --- backends/apple/mps/BUCK | 98 ++++++++++++++++++++++++- backends/apple/mps/TARGETS | 98 ------------------------- backends/xnnpack/serialization/BUCK | 29 ++++++++ backends/xnnpack/serialization/TARGETS | 29 -------- devtools/bundled_program/BUCK | 43 +++++++++++ devtools/bundled_program/TARGETS | 44 ----------- devtools/bundled_program/schema/BUCK | 20 ++++- devtools/bundled_program/schema/TARGETS | 24 ------ exir/emit/BUCK | 41 ++++++++++- exir/emit/TARGETS | 38 ---------- extension/pytree/BUCK | 47 +++++++++++- extension/pytree/TARGETS | 49 ------------- extension/training/BUCK | 16 +++- extension/training/TARGETS | 20 ----- kernels/portable/test/BUCK | 24 +++++- kernels/portable/test/TARGETS | 28 ------- 16 files changed, 308 insertions(+), 340 deletions(-) delete mode 100644 backends/apple/mps/TARGETS delete mode 100644 backends/xnnpack/serialization/TARGETS delete mode 100644 devtools/bundled_program/TARGETS delete mode 100644 devtools/bundled_program/schema/TARGETS delete mode 100644 exir/emit/TARGETS delete mode 100644 extension/pytree/TARGETS delete mode 100644 extension/training/TARGETS delete mode 100644 kernels/portable/test/TARGETS diff --git a/backends/apple/mps/BUCK b/backends/apple/mps/BUCK index 00fc5dd178c..bf7e029fe68 100644 --- a/backends/apple/mps/BUCK +++ b/backends/apple/mps/BUCK @@ -3,15 +3,105 @@ # Provided subject to the LICENSE file in the top level directory. # -# Any targets that should be shared between fbcode and xplat must be defined in -# targets.bzl. This file can contain xplat-only targets. - +load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target") load("@fbsource//tools/build_defs:default_platform_defs.bzl", "APPLE") +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") load(":targets.bzl", "define_common_targets") +load("@fbsource//tools/build_defs:fbsource_utils.bzl", "is_xplat") oncall("executorch") define_common_targets( - is_xplat = True, + is_xplat = is_xplat(), platforms = [APPLE], ) + +fbcode_target( + _kind = runtime.python_library, + name = "backend", + srcs = [ + "__init__.py", + "mps_preprocess.py", + ], + visibility = ["PUBLIC"], + deps = [ + ":operators", + ":serialization", + ":utils", + "//caffe2:torch", + "//executorch/exir/backend:backend_details", + "//executorch/exir/backend:compile_spec_schema", + ], +) + +fbcode_target( + _kind = runtime.python_library, + name = "operators", + srcs = glob([ + "operators/*.py", + ]), + deps = [ + ":serialization", + ":utils", + "//executorch/backends/transforms:lib", + ], +) + +fbcode_target( + _kind = runtime.python_library, + name = "partitioner", + srcs = glob([ + "partition/*.py", + ]), + visibility = ["PUBLIC"], + deps = [ + ":backend", + "//caffe2:torch", + "//executorch/exir/backend:compile_spec_schema", + "//executorch/exir/backend:partitioner", + "//executorch/exir/backend/canonical_partitioners:canonical_partitioner_lib", + ], +) + +fbcode_target( + _kind = runtime.python_library, + name = "serialization", + srcs = glob([ + "serialization/*.py", + ]), + resources = [ + "serialization/schema.fbs", + ], +) + +fbcode_target( + _kind = runtime.python_library, + name = "utils", + srcs = glob([ + "utils/*.py", + ]), + deps = [ + ":serialization", + "//caffe2:torch", + "//executorch/exir:lib", + ], +) + +fbcode_target( + _kind = runtime.python_test, + name = "test", + srcs = glob([ + "test/*.py", + ]), + deps = [ + ":backend", + ":partitioner", + "//caffe2:torch", + "//executorch/examples/models:models", + "//executorch/exir/tests:models", + "//executorch/extension/export_util:export_util", + "//executorch/devtools:lib", + "//executorch/devtools/bundled_program/serialize:lib", + "fbsource//third-party/pypi/pytest:pytest", + ], +) diff --git a/backends/apple/mps/TARGETS b/backends/apple/mps/TARGETS deleted file mode 100644 index d138b02e991..00000000000 --- a/backends/apple/mps/TARGETS +++ /dev/null @@ -1,98 +0,0 @@ -# -# Copyright (c) 2023 Apple Inc. All rights reserved. -# Provided subject to the LICENSE file in the top level directory. -# - -# Any targets that should be shared between fbcode and xplat must be defined in -# targets.bzl. This file can contain fbcode-only targets. - -load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") -load(":targets.bzl", "define_common_targets") - -oncall("executorch") - -define_common_targets() - -runtime.python_library( - name = "backend", - srcs = [ - "__init__.py", - "mps_preprocess.py", - ], - visibility = ["PUBLIC"], - deps = [ - ":operators", - ":serialization", - ":utils", - "//caffe2:torch", - "//executorch/exir/backend:backend_details", - "//executorch/exir/backend:compile_spec_schema", - ], -) - -runtime.python_library( - name = "operators", - srcs = glob([ - "operators/*.py", - ]), - deps = [ - ":serialization", - ":utils", - "//executorch/backends/transforms:lib", - ], -) - -runtime.python_library( - name = "partitioner", - srcs = glob([ - "partition/*.py", - ]), - visibility = ["PUBLIC"], - deps = [ - ":backend", - "//caffe2:torch", - "//executorch/exir/backend:compile_spec_schema", - "//executorch/exir/backend:partitioner", - "//executorch/exir/backend/canonical_partitioners:canonical_partitioner_lib", - ], -) - -runtime.python_library( - name = "serialization", - srcs = glob([ - "serialization/*.py", - ]), - resources = [ - "serialization/schema.fbs", - ], -) - -runtime.python_library( - name = "utils", - srcs = glob([ - "utils/*.py", - ]), - deps = [ - ":serialization", - "//caffe2:torch", - "//executorch/exir:lib", - ], -) - -runtime.python_test( - name = "test", - srcs = glob([ - "test/*.py", - ]), - deps = [ - ":backend", - ":partitioner", - "//caffe2:torch", - "//executorch/examples/models:models", - "//executorch/exir/tests:models", - "//executorch/extension/export_util:export_util", - "//executorch/devtools:lib", - "//executorch/devtools/bundled_program/serialize:lib", - "fbsource//third-party/pypi/pytest:pytest", - ], -) diff --git a/backends/xnnpack/serialization/BUCK b/backends/xnnpack/serialization/BUCK index c0b4f27eb52..dd7f2f3dde7 100644 --- a/backends/xnnpack/serialization/BUCK +++ b/backends/xnnpack/serialization/BUCK @@ -1,3 +1,32 @@ +load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target") +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") load(":targets.bzl", "define_common_targets") +oncall("executorch") + define_common_targets() + +fbcode_target( + _kind = runtime.python_library, + name = "xnnpack_schema", + srcs = [ + "xnnpack_graph_schema.py", + ], + visibility = ["PUBLIC"], +) + +fbcode_target( + _kind = runtime.python_library, + name = "xnnpack_serializer", + srcs = [ + "xnnpack_graph_serialize.py", + ], + resources = [ + "schema.fbs", + ], + visibility = ["PUBLIC"], + deps = [ + ":xnnpack_schema", + "//executorch/exir/_serialize:lib", + ], +) diff --git a/backends/xnnpack/serialization/TARGETS b/backends/xnnpack/serialization/TARGETS deleted file mode 100644 index a644520ac64..00000000000 --- a/backends/xnnpack/serialization/TARGETS +++ /dev/null @@ -1,29 +0,0 @@ -load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") -load(":targets.bzl", "define_common_targets") - -oncall("executorch") - -define_common_targets() - -runtime.python_library( - name = "xnnpack_schema", - srcs = [ - "xnnpack_graph_schema.py", - ], - visibility = ["PUBLIC"], -) - -runtime.python_library( - name = "xnnpack_serializer", - srcs = [ - "xnnpack_graph_serialize.py", - ], - resources = [ - "schema.fbs", - ], - visibility = ["PUBLIC"], - deps = [ - ":xnnpack_schema", - "//executorch/exir/_serialize:lib", - ], -) diff --git a/devtools/bundled_program/BUCK b/devtools/bundled_program/BUCK index 0a42614a385..06951d344fb 100644 --- a/devtools/bundled_program/BUCK +++ b/devtools/bundled_program/BUCK @@ -1,5 +1,48 @@ +load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target") +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") load(":targets.bzl", "define_common_targets") oncall("executorch") define_common_targets() + +fbcode_target( + _kind = runtime.python_library, + name = "core", + srcs = [ + "core.py", + ], + visibility = ["PUBLIC"], + deps = [ + ":config", + ":version", + "//caffe2:torch", + "//executorch/devtools/bundled_program/schema:bundled_program_schema_py", + "//executorch/exir:schema", + "//executorch/exir:tensor", + ], +) + +fbcode_target( + _kind = runtime.python_library, + name = "config", + srcs = [ + "config.py", + ], + visibility = ["PUBLIC"], + deps = [ + "fbsource//third-party/pypi/typing-extensions:typing-extensions", + "//caffe2:torch", + ], +) + +fbcode_target( + _kind = runtime.python_library, + name = "version", + srcs = [ + "version.py", + ], + visibility = [ + "//executorch/devtools/...", + ], +) diff --git a/devtools/bundled_program/TARGETS b/devtools/bundled_program/TARGETS deleted file mode 100644 index 10d4d0b9154..00000000000 --- a/devtools/bundled_program/TARGETS +++ /dev/null @@ -1,44 +0,0 @@ -load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") -load(":targets.bzl", "define_common_targets") - -oncall("executorch") - -define_common_targets() - -runtime.python_library( - name = "core", - srcs = [ - "core.py", - ], - visibility = ["PUBLIC"], - deps = [ - ":config", - ":version", - "//caffe2:torch", - "//executorch/devtools/bundled_program/schema:bundled_program_schema_py", - "//executorch/exir:schema", - "//executorch/exir:tensor", - ], -) - -runtime.python_library( - name = "config", - srcs = [ - "config.py", - ], - visibility = ["PUBLIC"], - deps = [ - "fbsource//third-party/pypi/typing-extensions:typing-extensions", - "//caffe2:torch", - ], -) - -runtime.python_library( - name = "version", - srcs = [ - "version.py", - ], - visibility = [ - "//executorch/devtools/...", - ], -) diff --git a/devtools/bundled_program/schema/BUCK b/devtools/bundled_program/schema/BUCK index 1e8cc179228..c943db0765a 100644 --- a/devtools/bundled_program/schema/BUCK +++ b/devtools/bundled_program/schema/BUCK @@ -1,8 +1,26 @@ # Any targets that should be shared between fbcode and xplat must be defined in -# targets.bzl. This file can contain xplat-only targets. +# targets.bzl. This file can contain fbcode-only targets. +load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target") +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") load(":targets.bzl", "define_common_targets") oncall("executorch") define_common_targets() + +fbcode_target( + _kind = runtime.python_library, + name = "bundled_program_schema_py", + srcs = [ + "__init__.py", + "bundled_program_schema.py", + ], + visibility = [ + "//executorch/devtools/bundled_program/...", + "//executorch/devtools/etrecord/...", + ], + deps = [ + "//executorch/exir:scalar_type", + ], +) diff --git a/devtools/bundled_program/schema/TARGETS b/devtools/bundled_program/schema/TARGETS deleted file mode 100644 index 51c004cbec0..00000000000 --- a/devtools/bundled_program/schema/TARGETS +++ /dev/null @@ -1,24 +0,0 @@ -# Any targets that should be shared between fbcode and xplat must be defined in -# targets.bzl. This file can contain fbcode-only targets. - -load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") -load(":targets.bzl", "define_common_targets") - -oncall("executorch") - -define_common_targets() - -runtime.python_library( - name = "bundled_program_schema_py", - srcs = [ - "__init__.py", - "bundled_program_schema.py", - ], - visibility = [ - "//executorch/devtools/bundled_program/...", - "//executorch/devtools/etrecord/...", - ], - deps = [ - "//executorch/exir:scalar_type", - ], -) diff --git a/exir/emit/BUCK b/exir/emit/BUCK index 51846daef65..433b583dc1c 100644 --- a/exir/emit/BUCK +++ b/exir/emit/BUCK @@ -1,4 +1,41 @@ -# add this empty BUCK file to unblock landing. Without this, we get land error: -# "No build file at xplat/executorch/exir/BUCK when resolving target fbsource//xplat/executorch/exir:." +load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target") +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") oncall("executorch") + +fbcode_target( + _kind = runtime.python_library, + name = "lib", + srcs = [ + "__init__.py", + ], + deps = [ + ":emit", + ], +) + +fbcode_target( + _kind = runtime.python_library, + name = "emit", + srcs = [ + "_emit_program.py", + "_emitter.py", + ], + deps = [ + "fbsource//third-party/pypi/typing-extensions:typing-extensions", + "//caffe2:torch", + "//executorch/exir:delegate", + "//executorch/exir:error", + "//executorch/exir:memory", + "//executorch/exir:print_program", + "//executorch/exir:schema", + "//executorch/exir:tensor", + "//executorch/exir:types", + "//executorch/exir:version", + "//executorch/exir/dialects/backend:lib", + "//executorch/exir/dialects/edge:lib", + "//executorch/exir/operator:convert", + "//executorch/exir/passes:prim_ops_py_registry", + "//executorch/extension/pytree:pylib", + ], +) diff --git a/exir/emit/TARGETS b/exir/emit/TARGETS deleted file mode 100644 index 0adee10e82e..00000000000 --- a/exir/emit/TARGETS +++ /dev/null @@ -1,38 +0,0 @@ -load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") - -oncall("executorch") - -runtime.python_library( - name = "lib", - srcs = [ - "__init__.py", - ], - deps = [ - ":emit", - ], -) - -runtime.python_library( - name = "emit", - srcs = [ - "_emit_program.py", - "_emitter.py", - ], - deps = [ - "fbsource//third-party/pypi/typing-extensions:typing-extensions", - "//caffe2:torch", - "//executorch/exir:delegate", - "//executorch/exir:error", - "//executorch/exir:memory", - "//executorch/exir:print_program", - "//executorch/exir:schema", - "//executorch/exir:tensor", - "//executorch/exir:types", - "//executorch/exir:version", - "//executorch/exir/dialects/backend:lib", - "//executorch/exir/dialects/edge:lib", - "//executorch/exir/operator:convert", - "//executorch/exir/passes:prim_ops_py_registry", - "//executorch/extension/pytree:pylib", - ], -) diff --git a/extension/pytree/BUCK b/extension/pytree/BUCK index 1e8cc179228..913a2c43fe1 100644 --- a/extension/pytree/BUCK +++ b/extension/pytree/BUCK @@ -1,8 +1,53 @@ # Any targets that should be shared between fbcode and xplat must be defined in -# targets.bzl. This file can contain xplat-only targets. +# targets.bzl. This file can contain fbcode-only targets. +load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target") +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") load(":targets.bzl", "define_common_targets") oncall("executorch") define_common_targets() + +fbcode_target( + _kind = runtime.cxx_python_extension, + name = "pybindings", + srcs = [ + "pybindings.cpp", + ], + base_module = "executorch.extension.pytree", + deps = [ + ":pytree", + ], + external_deps = [ + "pybind11", + ], +) + +fbcode_target( + _kind = runtime.cxx_python_extension, + name = "pybindings_debug", + srcs = [ + "pybindings.cpp", + ], + base_module = "executorch.extension.pytree", + deps = [ + ":pytree", + ], + external_deps = [ + "pybind11", + ], +) + +fbcode_target( + _kind = runtime.python_library, + name = "pylib", + srcs = [ + "__init__.py", + ], + base_module = "executorch.extension.pytree", + deps = [ + ":pybindings", + "//caffe2:torch", + ], +) diff --git a/extension/pytree/TARGETS b/extension/pytree/TARGETS deleted file mode 100644 index 79c4d2b8b3f..00000000000 --- a/extension/pytree/TARGETS +++ /dev/null @@ -1,49 +0,0 @@ -# Any targets that should be shared between fbcode and xplat must be defined in -# targets.bzl. This file can contain fbcode-only targets. - -load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") -load(":targets.bzl", "define_common_targets") - -oncall("executorch") - -define_common_targets() - -runtime.cxx_python_extension( - name = "pybindings", - srcs = [ - "pybindings.cpp", - ], - base_module = "executorch.extension.pytree", - deps = [ - ":pytree", - ], - external_deps = [ - "pybind11", - ], -) - -runtime.cxx_python_extension( - name = "pybindings_debug", - srcs = [ - "pybindings.cpp", - ], - base_module = "executorch.extension.pytree", - deps = [ - ":pytree", - ], - external_deps = [ - "pybind11", - ], -) - -runtime.python_library( - name = "pylib", - srcs = [ - "__init__.py", - ], - base_module = "executorch.extension.pytree", - deps = [ - ":pybindings", - "//caffe2:torch", - ], -) diff --git a/extension/training/BUCK b/extension/training/BUCK index 1e8cc179228..6c4cc1eabf3 100644 --- a/extension/training/BUCK +++ b/extension/training/BUCK @@ -1,8 +1,22 @@ # Any targets that should be shared between fbcode and xplat must be defined in -# targets.bzl. This file can contain xplat-only targets. +# targets.bzl. This file can contain fbcode-only targets. +load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target") +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") load(":targets.bzl", "define_common_targets") oncall("executorch") define_common_targets() + +fbcode_target( + _kind = runtime.python_library, + name = "lib", + srcs = [ + "__init__.py", + ], + deps = [ + "//executorch/extension/training/pybindings:_training_lib", + "//executorch/extension/training/pybindings:_training_module", + ], +) diff --git a/extension/training/TARGETS b/extension/training/TARGETS deleted file mode 100644 index eeed302c339..00000000000 --- a/extension/training/TARGETS +++ /dev/null @@ -1,20 +0,0 @@ -# Any targets that should be shared between fbcode and xplat must be defined in -# targets.bzl. This file can contain fbcode-only targets. - -load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") -load(":targets.bzl", "define_common_targets") - -oncall("executorch") - -define_common_targets() - -runtime.python_library( - name = "lib", - srcs = [ - "__init__.py", - ], - deps = [ - "//executorch/extension/training/pybindings:_training_lib", - "//executorch/extension/training/pybindings:_training_module", - ], -) diff --git a/kernels/portable/test/BUCK b/kernels/portable/test/BUCK index 1e8cc179228..7d42f44e1c4 100644 --- a/kernels/portable/test/BUCK +++ b/kernels/portable/test/BUCK @@ -1,8 +1,30 @@ # Any targets that should be shared between fbcode and xplat must be defined in -# targets.bzl. This file can contain xplat-only targets. +# targets.bzl. This file can contain fbcode-only targets. +load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target") +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") load(":targets.bzl", "define_common_targets") oncall("executorch") define_common_targets() + +fbcode_target( + _kind = runtime.cxx_library, + name = "aot_ops_test_lib", + srcs = [ + "register_ops_aot_for_test.cpp", + ], + visibility = ["PUBLIC"], + deps = [ + "//executorch/extension/aten_util:aten_bridge", + "//executorch/kernels/portable/cpu:op_grid_sampler_2d", + "//executorch/kernels/portable/cpu:op_upsample_bilinear2d", + "//executorch/kernels/portable/cpu:op_upsample_bilinear2d_aa", + "//executorch/kernels/portable/cpu:op_upsample_nearest2d", + "//executorch/runtime/core/exec_aten:lib", + ], + external_deps = [ + "libtorch", + ], +) diff --git a/kernels/portable/test/TARGETS b/kernels/portable/test/TARGETS deleted file mode 100644 index 44c5697729e..00000000000 --- a/kernels/portable/test/TARGETS +++ /dev/null @@ -1,28 +0,0 @@ -# Any targets that should be shared between fbcode and xplat must be defined in -# targets.bzl. This file can contain fbcode-only targets. - -load(":targets.bzl", "define_common_targets") -load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") - -oncall("executorch") - -define_common_targets() - -runtime.cxx_library( - name = "aot_ops_test_lib", - srcs = [ - "register_ops_aot_for_test.cpp", - ], - visibility = ["PUBLIC"], - deps = [ - "//executorch/extension/aten_util:aten_bridge", - "//executorch/kernels/portable/cpu:op_grid_sampler_2d", - "//executorch/kernels/portable/cpu:op_upsample_bilinear2d", - "//executorch/kernels/portable/cpu:op_upsample_bilinear2d_aa", - "//executorch/kernels/portable/cpu:op_upsample_nearest2d", - "//executorch/runtime/core/exec_aten:lib", - ], - external_deps = [ - "libtorch", - ], -)