Skip to content

Add extended_targets CMake hook for non-OSS JNI extensions#17947

Merged
psiddh merged 2 commits intopytorch:mainfrom
psiddh:add-extended-targets-cmake-hook
Mar 6, 2026
Merged

Add extended_targets CMake hook for non-OSS JNI extensions#17947
psiddh merged 2 commits intopytorch:mainfrom
psiddh:add-extended-targets-cmake-hook

Conversation

@psiddh
Copy link
Contributor

@psiddh psiddh commented Mar 6, 2026

Summary

Add a generic hook in extension/android/CMakeLists.txt that conditionally includes fb/extended_targets/CMakeLists.txt if it exists. This allows internal or partner-specific JNI extensions (e.g., Gemma3N) to plug into the Android JNI build without modifying OSS files.

When fb/extended_targets/CMakeLists.txt does not exist (as in OSS builds), the hook is a complete no-op.

Motivation

PR #17942 added Gemma3N Android demo app support, but required modifying two OSS files (extension/android/CMakeLists.txt and scripts/build_android_library.sh) with @oss-disable lines. This creates ongoing merge friction and scales poorly as more internal models are added.

This PR introduces a one-time, stable hook so that:

Build System How it Works Result
Internal Buck CI Uses TARGETS files directly No change needed
Internal CMake/Gradle Hook includes fb/extended_targets/CMakeLists.txt which sets internal flags Works
OSS CMake/Gradle Hook is a no-op (fb/extended_targets/ does not exist) Works

Test plan

  • OSS builds: No behavior change. The fb/extended_targets/ directory does not exist, so the if(EXISTS ...) evaluates to false and is a no-op.
  • Internal builds: Place a CMakeLists.txt in extension/android/fb/extended_targets/ to verify it gets included.

Add a generic hook in extension/android/CMakeLists.txt that conditionally
includes extended_targets/CMakeLists.txt if it exists. This allows
internal or partner-specific JNI extensions (e.g., Gemma3N) to plug into
the Android JNI build without modifying OSS files.

When extended_targets/CMakeLists.txt does not exist (as in OSS builds),
the hook is a complete no-op.
Copilot AI review requested due to automatic review settings March 6, 2026 05:43
@pytorch-bot
Copy link

pytorch-bot bot commented Mar 6, 2026

🔗 Helpful Links

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

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

❌ 7 New Failures, 5 Pending

As of commit 73fbf55 with merge base e6f7d5e (image):

NEW FAILURES - The following jobs have failed:

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 Mar 6, 2026
@github-actions
Copy link

github-actions bot commented Mar 6, 2026

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.

@psiddh psiddh requested a review from lucylq March 6, 2026 05:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a small, optional CMake hook in the Android JNI extension build to allow internal/partner-specific JNI targets to be integrated via a separate extended_targets/CMakeLists.txt without modifying OSS files.

Changes:

  • Conditionally includes extension/android/extended_targets/CMakeLists.txt when present (no-op when absent).

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

@psiddh psiddh merged commit 5ed3616 into pytorch:main Mar 6, 2026
150 of 157 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants