Skip to content

gate fbcode-only TARGETS dirs with is_fbcode() and rename to BUCK#21049

Merged
meta-codesync[bot] merged 1 commit into
pytorch:mainfrom
bigfootjon:export-D109082044
Jul 21, 2026
Merged

gate fbcode-only TARGETS dirs with is_fbcode() and rename to BUCK#21049
meta-codesync[bot] merged 1 commit into
pytorch:mainfrom
bigfootjon:export-D109082044

Conversation

@bigfootjon

Copy link
Copy Markdown
Member

Summary:
Chunk 6 of fbcode/executorch TARGETS->BUCK migration. 32 directories whose
TARGETS files contained fbcode-only macros (fbcode_macros loads,
fbcode_target(, python_library/python_binary from fbcode_macros,
etc.). For each:

  1. Created a new targets.bzl containing the original loads and a
    define_common_targets(is_fbcode = False) function whose body opens
    with if not is_fbcode: return and otherwise contains the original
    TARGETS rule definitions.
  2. Deleted TARGETS and wrote a thin BUCK that calls
    define_common_targets(is_fbcode = is_fbcode()) using
    fbsource_utils.is_fbcode() for runtime cell detection.

In fbcode the function body runs and the rules are defined as before. In
xplat the function returns early before any fbcode-only macro is invoked,
so the loads (which do resolve in xplat) are harmless and no rules
materialize.

Directories migrated:

  • backends/arm/_passes/fb/test
  • backends/arm/fb
  • backends/arm/fb/tests
  • backends/cortex_m
  • backends/cortex_m/quantizer
  • backends/example
  • backends/vulkan/_passes
  • backends/webgpu/test
  • devtools/backend_debug/tests
  • devtools/fb/visualizer
  • devtools/inspector/tests
  • devtools/intermediate_output_tap/tests
  • devtools/pte_tool/tests
  • devtools/size_analysis_tool
  • examples/llm_pte_finetuning
  • examples/models/fb/gemma3n
  • examples/models/fb/gemma4/tests
  • examples/models/fb/gemma4/validation
  • examples/models/fb/llama4/runner/test
  • examples/models/gemma4/tests
  • examples/models/phi_4_mini
  • examples/models/qwen2_5
  • examples/models/qwen3
  • examples/models/resnet
  • examples/qualcomm
  • exir/dialects/edge/spec
  • exir/dialects/test
  • exir/verification
  • extension/audio
  • extension/audio/fb/test
  • extension/llm/custom_ops/spinquant/test/fb
  • scripts/fb/size_monitoring

3 dirs were skipped because they already have a targets.bzl and need a
manual merge (devtools/etdump/fb/tests, devtools/etdump/tests, exir/fb).

Reviewed By: mzlee

Differential Revision: D109082044

Summary:
Chunk 6 of fbcode/executorch TARGETS->BUCK migration. 32 directories whose
TARGETS files contained fbcode-only macros (`fbcode_macros` loads,
`fbcode_target(`, `python_library`/`python_binary` from fbcode_macros,
etc.). For each:

  1. Created a new `targets.bzl` containing the original loads and a
     `define_common_targets(is_fbcode = False)` function whose body opens
     with `if not is_fbcode: return` and otherwise contains the original
     TARGETS rule definitions.
  2. Deleted TARGETS and wrote a thin BUCK that calls
     `define_common_targets(is_fbcode = is_fbcode())` using
     `fbsource_utils.is_fbcode()` for runtime cell detection.

In fbcode the function body runs and the rules are defined as before. In
xplat the function returns early before any fbcode-only macro is invoked,
so the loads (which do resolve in xplat) are harmless and no rules
materialize.

Directories migrated:
  - backends/arm/_passes/fb/test
  - backends/arm/fb
  - backends/arm/fb/tests
  - backends/cortex_m
  - backends/cortex_m/quantizer
  - backends/example
  - backends/vulkan/_passes
  - backends/webgpu/test
  - devtools/backend_debug/tests
  - devtools/fb/visualizer
  - devtools/inspector/tests
  - devtools/intermediate_output_tap/tests
  - devtools/pte_tool/tests
  - devtools/size_analysis_tool
  - examples/llm_pte_finetuning
  - examples/models/fb/gemma3n
  - examples/models/fb/gemma4/tests
  - examples/models/fb/gemma4/validation
  - examples/models/fb/llama4/runner/test
  - examples/models/gemma4/tests
  - examples/models/phi_4_mini
  - examples/models/qwen2_5
  - examples/models/qwen3
  - examples/models/resnet
  - examples/qualcomm
  - exir/dialects/edge/spec
  - exir/dialects/test
  - exir/verification
  - extension/audio
  - extension/audio/fb/test
  - extension/llm/custom_ops/spinquant/test/fb
  - scripts/fb/size_monitoring

3 dirs were skipped because they already have a `targets.bzl` and need a
manual merge (devtools/etdump/fb/tests, devtools/etdump/tests, exir/fb).

Reviewed By: mzlee

Differential Revision: D109082044
Copilot AI review requested due to automatic review settings July 20, 2026 22:57
@pytorch-bot

pytorch-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21049

Note: Links to docs will display an error until the docs builds have been completed.

❌ 2 New Failures

As of commit 0529841 with merge base 2a532de (image):

NEW FAILURES - The following jobs have failed:

  • Cadence Build & Test / hifi-build / hifi4 (gh)
    Refusing to check out fork pull request code from a 'pull_request_target' workflow. This workflow runs with the base repository's GITHUB_TOKEN, secrets, default-branch cache scope, and runner access. Fetching and executing a fork's code in that trusted context commonly leads to "pwn request" vulnerabilities. To opt in, review the risks at https://gh.io/securely-using-pull_request_target and set 'allow-unsafe-pr-checkout: true' on the actions/checkout step.
  • Cadence Build & Test / vision-build / vision (gh)
    Refusing to check out fork pull request code from a 'pull_request_target' workflow. This workflow runs with the base repository's GITHUB_TOKEN, secrets, default-branch cache scope, and runner access. Fetching and executing a fork's code in that trusted context commonly leads to "pwn request" vulnerabilities. To opt in, review the risks at https://gh.io/securely-using-pull_request_target and set 'allow-unsafe-pr-checkout: true' on the actions/checkout step.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 20, 2026
@meta-codesync

meta-codesync Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@bigfootjon has exported this pull request. If you are a Meta employee, you can view the originating Diff in D109082044.

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR continues the fbcode/executorch TARGETS→BUCK migration by moving fbcode-only build rules into targets.bzl behind an is_fbcode gate, and replacing TARGETS with a thin BUCK wrapper that calls define_common_targets(is_fbcode = is_fbcode()). This aims to keep fbcode behavior unchanged while preventing fbcode-only macros/rules from materializing in xplat.

Changes:

  • Introduce targets.bzl files containing define_common_targets(is_fbcode=False) wrappers (early-returning in xplat) for multiple directories that previously used fbcode-only macros.
  • Replace deleted TARGETS files with new BUCK files that call define_common_targets(is_fbcode = is_fbcode()).
  • Convert/adjust some existing BUCK files to support the migration (notably backends/webgpu/test/BUCK and backends/cortex_m/BUCK).

Reviewed changes

Copilot reviewed 56 out of 56 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
extension/audio/targets.bzl New gated target definitions migrated from TARGETS (includes a duplicate runtime load).
extension/audio/TARGETS Removed in favor of BUCK + targets.bzl pattern.
extension/audio/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
exir/verification/targets.bzl New gated target definitions migrated from TARGETS.
exir/verification/TARGETS Removed in favor of BUCK + targets.bzl pattern.
exir/verification/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
exir/dialects/test/targets.bzl New gated unittest target migrated from TARGETS.
exir/dialects/test/TARGETS Removed in favor of BUCK + targets.bzl pattern.
exir/dialects/test/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
exir/dialects/edge/spec/targets.bzl New gated generator/library targets migrated from TARGETS.
exir/dialects/edge/spec/TARGETS Removed in favor of BUCK + targets.bzl pattern.
exir/dialects/edge/spec/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()) (oncall changed vs old TARGETS).
examples/qualcomm/targets.bzl New gated targets migrated from TARGETS (includes a duplicate runtime load).
examples/qualcomm/TARGETS Removed in favor of BUCK + targets.bzl pattern.
examples/qualcomm/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
examples/models/resnet/targets.bzl New gated python_library target.
examples/models/resnet/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
examples/models/qwen3/targets.bzl New gated runtime.python_library target with resources.
examples/models/qwen3/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
examples/models/qwen2_5/targets.bzl New gated runtime.python_library target with resources.
examples/models/qwen2_5/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
examples/models/phi_4_mini/targets.bzl New gated runtime.python_library + runtime.python_binary targets.
examples/models/phi_4_mini/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
examples/models/gemma4/tests/targets.bzl New gated fbcode_target-based python test target.
examples/models/gemma4/tests/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
examples/llm_pte_finetuning/targets.bzl New gated training/export runner targets migrated from TARGETS.
examples/llm_pte_finetuning/TARGETS Removed in favor of BUCK + targets.bzl pattern.
examples/llm_pte_finetuning/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()) (oncall changed vs old TARGETS).
devtools/size_analysis_tool/targets.bzl New gated library/binary/unittest targets migrated from TARGETS.
devtools/size_analysis_tool/TARGETS Removed in favor of BUCK + targets.bzl pattern.
devtools/size_analysis_tool/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
devtools/pte_tool/tests/targets.bzl New gated unittest target migrated from TARGETS.
devtools/pte_tool/tests/TARGETS Removed in favor of BUCK + targets.bzl pattern.
devtools/pte_tool/tests/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
devtools/intermediate_output_tap/tests/targets.bzl New gated unittest targets migrated from TARGETS.
devtools/intermediate_output_tap/tests/TARGETS Removed in favor of BUCK + targets.bzl pattern.
devtools/intermediate_output_tap/tests/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
devtools/inspector/tests/targets.bzl New gated unittest + helper library targets migrated from TARGETS.
devtools/inspector/tests/TARGETS Removed in favor of BUCK + targets.bzl pattern.
devtools/inspector/tests/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
devtools/backend_debug/tests/targets.bzl New gated unittest target migrated from TARGETS.
devtools/backend_debug/tests/TARGETS Removed in favor of BUCK + targets.bzl pattern.
devtools/backend_debug/tests/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
backends/webgpu/test/targets.bzl New gated test/library targets (currently references a non-existent source path).
backends/webgpu/test/BUCK Modified to use fbcode_target, but does not follow the thin-wrapper pattern described in the PR.
backends/vulkan/_passes/targets.bzl New gated python_library targets migrated from TARGETS.
backends/vulkan/_passes/TARGETS Removed in favor of BUCK + targets.bzl pattern.
backends/vulkan/_passes/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
backends/example/targets.bzl New gated example backend targets migrated from TARGETS.
backends/example/TARGETS Removed in favor of BUCK + targets.bzl pattern.
backends/example/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
backends/cortex_m/targets.bzl New gated targets file added, but root BUCK does not call it.
backends/cortex_m/quantizer/targets.bzl New gated quantizer targets migrated from TARGETS.
backends/cortex_m/quantizer/TARGETS Removed in favor of BUCK + targets.bzl pattern.
backends/cortex_m/quantizer/BUCK New thin wrapper calling define_common_targets(is_fbcode = is_fbcode()).
backends/cortex_m/BUCK Modified to use fbcode_target, but does not follow the thin-wrapper pattern described in the PR.
Comments suppressed due to low confidence (2)

backends/webgpu/test/BUCK:10

  • This directory now has a targets.bzl with define_common_targets(is_fbcode=False) gating, but the BUCK file still defines targets directly and never calls define_common_targets(is_fbcode = is_fbcode()). That contradicts the PR description’s migration pattern (thin BUCK wrapper calling targets.bzl) and risks reintroducing fbcode-only targets into xplat parsing.
    backends/cortex_m/BUCK:14
  • backends/cortex_m/targets.bzl was added with a gated define_common_targets(), but this BUCK file still defines targets directly (via fbcode_target) and never calls define_common_targets(is_fbcode = is_fbcode()). This is inconsistent with the migration approach described in the PR and suggests targets.bzl may be unused or the BUCK conversion is incomplete.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +3
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
load("@fbcode_macros//build_defs:python_binary.bzl", "python_binary")
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
Comment on lines +1 to +4
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
load("@fbcode_macros//build_defs:python_binary.bzl", "python_binary")
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_version")
Comment on lines +9 to +13
python_unittest(
name = "test_add",
srcs = [
"ops/add/test_add.py",
],
load("@fbsource//tools/build_defs:fbsource_utils.bzl", "is_fbcode")
load(":targets.bzl", "define_common_targets")

oncall("executorch")
load("@fbsource//tools/build_defs:fbsource_utils.bzl", "is_fbcode")
load(":targets.bzl", "define_common_targets")

oncall("executorch")
@meta-codesync
meta-codesync Bot merged commit b3ac2df into pytorch:main Jul 21, 2026
223 of 235 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants