Skip to content

Ship a linkable shared runtime and make the Python bindings use it - #21514

Open
shoumikhin wants to merge 23 commits into
mainfrom
gh/shoumikhin/78/head
Open

Ship a linkable shared runtime and make the Python bindings use it#21514
shoumikhin wants to merge 23 commits into
mainfrom
gh/shoumikhin/78/head

Conversation

@shoumikhin

@shoumikhin shoumikhin commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Today pip install executorch gives you the Python half of ExecuTorch but
nothing a C++ application can link. The wheel installs a header subset and an
executorch-config.cmake, but that config only locates the Python extension so
custom-op builds can compile against it: it defines no runtime library and no
CMake targets. Writing a small C++ program that loads and runs a .pte means
cloning the repo, syncing submodules, and building from source.

This change ships the runtime as a real library and exposes it through
find_package, so a standalone application needs nothing but the wheel:

find_package(executorch REQUIRED)
target_link_libraries(my_app PRIVATE executorch::runtime)

executorch::runtime is an imported target whose location is resolved relative
to the config file itself, so the package stays relocatable and no path from the
machine that built the wheel is baked into it. A consumer picks up the wheel's
library directory in its RUNPATH, plus $ORIGIN-relative entries so an
application deployed next to a copy of the runtime keeps working without
LD_LIBRARY_PATH.

The Python extensions have to move to the shared runtime in the same change.
Backends register themselves into a single process-wide table owned by the
runtime, and that table is only process-wide if exactly one loaded library
defines it. The Python extension statically embeds the runtime today, so adding a
shared library beside it would give a process two independent registries, and a
backend could register into the one nobody reads. The extensions therefore link
the shared runtime instead of whole-archiving the static libraries, leaving
exactly one registry owner for both the Python and C++ paths.

Getting that right needs two linker details. The shared runtime is named through
a link option rather than an ordinary dependency, because CMake orders link
libraries so a static archive precedes what it depends on, which would let the
archive satisfy the runtime symbols first. It is also wrapped in
--no-as-needed, because a shared library with no already-referenced symbol at
the point it appears on the link line can be dropped, and a later static archive
would then supply the registry after all.

Registration still happens through static initializers exactly as before. No new
plugin or loader ABI is introduced.

The shared runtime is Linux-only for the wheel. macOS C++ consumers are served by
the existing Swift package distribution, and the runtime has no export
annotations for a Windows DLL. Every other build keeps linking the static
libraries, because the new behavior is gated on the existing
EXECUTORCH_BUILD_SHARED option, so iOS, Android, and embedded builds are
unaffected.

Test plan:

The wheel smoke test now covers this on Linux, so it is checked in CI rather than
only by hand. It asserts that exactly one shipped library defines the backend
registry, builds a standalone C++ program that only calls
find_package(executorch) and links executorch::runtime, runs it without
LD_LIBRARY_PATH, and checks the resulting binary depends on the shipped runtime
with a relocatable RUNPATH. The check was confirmed to fail when a second
registry definition is introduced deliberately. The wheel workflows now also run
when any CMakeLists.txt or anything under tools/cmake changes, since those
files decide what the wheel contains.

Built the wheel from a clean checkout on Linux x86_64 and on Linux aarch64, then
verified each against a fresh virtual environment with a normal
dependency-resolving install:

  • nm -DC across every shipped shared object shows exactly one definition of the
    registry entry points; the Python extensions import them rather than defining
    their own.
  • A C++ program whose CMake only calls find_package(executorch) and links
    executorch::runtime compiles and runs against the installed wheel with no
    source checkout. It initializes the runtime, queries the backend registry, and
    compiles against the shipped program-loading header to confirm it is usable.
  • readelf -d on that program lists the versioned runtime in DT_NEEDED with
    $ORIGIN-relative RUNPATH entries, and it runs without LD_LIBRARY_PATH.
  • A C++ binary that links only executorch::runtime and loads the Python
    extension sees the backends that extension registered, which is the
    one-registry property stated above.
  • import executorch, the registered backend list, and .pte execution through
    the Python bindings are unchanged, with outputs matching eager PyTorch.
  • With EXECUTORCH_BUILD_SHARED off, the Python extension still builds
    self-contained and no shared runtime is produced, so the previous behavior is
    intact.
  • Configured with CMake 3.28 as well as 3.31, since the project supports 3.24 and
    up and the two differ in how strictly they treat link features.

[ghstack-poisoned]
@shoumikhin
shoumikhin requested a review from larryliu0820 as a code owner July 31, 2026 06:23
Copilot AI review requested due to automatic review settings July 31, 2026 06:23
@shoumikhin
shoumikhin requested a review from kirklandsign as a code owner July 31, 2026 06:23
@pytorch-bot

pytorch-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 48 New Failures, 41 Pending, 2 Unrelated Failures, 22 Unclassified Failures

As of commit 3447ef5 with merge base 9789eea (image):

NEW FAILURES - The following jobs have failed:

  • Apple / test-demo-ios / mobile-job (ios) (gh)
    ##[error]An error occurred trying to start process '/usr/bin/bash' with working directory '/home/ec2-user/actions-runner/_work/executorch/executorch/test-infra/tools/device-farm-runner'. No such file or directory
  • Cadence Build & Test / cpu-test / test-aot / test-aot (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID E578:11F58D:5E71AB3:14B0CA35:6A6EBAE9 and timestamp 2026-08-02 03:35:05 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • Cadence Build & Test / cpu-test / test-ops / test-ops (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID C508:3171CF:61769C9:155F26AD:6A6EBADD and timestamp 2026-08-02 03:34:53 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • nightly / link-check / lint-urls (gh)
  • nightly / link-check / lint-xrefs (gh)
  • periodic / test-models-linux (buck2, mv3, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID A02E:14CAE2:3229C47:ACEA75D:6A6EBA90 and timestamp 2026-08-02 03:33:36 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (buck2, mv3, xnnpack-quantization-delegation, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID 87D0:B5F58:1EBFA26:6A1AC04:6A6EBAA6 and timestamp 2026-08-02 03:33:58 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, add_mul, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID C696:6F181:298865E:905620A:6A6EBA95 and timestamp 2026-08-02 03:33:41 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, add_mul, xnnpack-quantization-delegation, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID D77E:143A03:28F5016:8E56C13:6A6EBA96 and timestamp 2026-08-02 03:33:42 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, add, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID BCD6:11D5F8:1EA9687:6A10220:6A6EBA98 and timestamp 2026-08-02 03:33:44 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, add, xnnpack-quantization-delegation, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID C596:10C28F:32F7AC2:AF42D67:6A6EBA94 and timestamp 2026-08-02 03:33:40 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, conv1d, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID C4AE:3FCD1F:1DE8DB6:67B86B7:6A6EBA88 and timestamp 2026-08-02 03:33:28 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, deep_autoencoder, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID 8C84:6347F:2A24EF1:928BBBB:6A6EBA96 and timestamp 2026-08-02 03:33:42 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, deit_tiny, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID C9CA:6FC35:62D75FD:1591CFD5:6A6EBA9C and timestamp 2026-08-02 03:33:49 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, ds_cnn, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID C760:6F181:29849E4:9048F8D:6A6EBA87 and timestamp 2026-08-02 03:33:27 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, efficient_sam, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID DDF4:E09F4:31B026B:AADF8CD:6A6EBA8C and timestamp 2026-08-02 03:33:32 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, emformer_transcribe, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID A54E:14FD75:3227E6C:ACC59CC:6A6EBA94 and timestamp 2026-08-02 03:33:40 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, emformer_transcribe, xnnpack-quantization-delegation, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID E592:49914:5B0B1AA:13F3E3FE:6A6EBA92 and timestamp 2026-08-02 03:33:38 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, ic3, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID B448:11E1AE:2988AF3:90908A8:6A6EBA90 and timestamp 2026-08-02 03:33:36 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, ic3, xnnpack-quantization-delegation, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID B43E:37B543:32FA69E:AED7EB5:6A6EBA92 and timestamp 2026-08-02 03:33:38 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, linear, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID D830:144033:32940B4:AE6C7AC:6A6EBA96 and timestamp 2026-08-02 03:33:42 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, linear, xnnpack-quantization-delegation, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID C726:A81BD:34F9207:B68326D:6A6EBA92 and timestamp 2026-08-02 03:33:38 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, llama, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID E2F8:362F76:3233F98:AC2A61C:6A6EBA8D and timestamp 2026-08-02 03:33:33 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, llama2, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID D8B2:827E7:282AD1C:8B9A6F9:6A6EBA9F and timestamp 2026-08-02 03:33:51 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, llama2, xnnpack-quantization-delegation, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID B94C:1A6201:2FE9A68:A5294A5:6A6EBA95 and timestamp 2026-08-02 03:33:41 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, lstm, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID 97D4:11E1AE:298A82E:9096E77:6A6EBA97 and timestamp 2026-08-02 03:33:43 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, mobilebert, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]An error occurred trying to start process '/usr/bin/bash' with working directory '/home/ec2-user/actions-runner/_work/executorch/executorch/pytorch/executorch'. No such file or directory
  • periodic / test-models-linux (cmake, mobilebert, xnnpack-quantization-delegation, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID D20A:33C071:2E736B3:9FE33D8:6A6EBAA8 and timestamp 2026-08-02 03:34:00 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, mobilenet_v1_025, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID B2A0:78E4F:30B8099:A7EC8E4:6A6EBA8B and timestamp 2026-08-02 03:33:31 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, mul, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID B0A8:2940DD:303E56B:A646A00:6A6EBA95 and timestamp 2026-08-02 03:33:41 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, mv2_untrained, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID AEF2:D8E4B:30E1A62:A7CE811:6A6EBA8D and timestamp 2026-08-02 03:33:33 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, mv2, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID A64A:AAB79:304D86C:A6321FC:6A6EBAA2 and timestamp 2026-08-02 03:33:54 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, mv2, xnnpack-quantization-delegation, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID 9720:284A0:28906A6:8B614BA:6A6EBAA3 and timestamp 2026-08-02 03:33:55 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, mv3, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID BBF2:4E211:1E1963B:67FE805:6A6EBA9B and timestamp 2026-08-02 03:33:47 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, mv3, xnnpack-quantization-delegation, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID C9C4:33C071:2E699EC:9FC124D:6A6EBA8C and timestamp 2026-08-02 03:33:32 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, qwen2_5_1_5b, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID AB9E:B5F58:1EB7989:69FEC68:6A6EBA8A and timestamp 2026-08-02 03:33:30 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, qwen3, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID A666:144033:3294524:AE6D68D:6A6EBA96 and timestamp 2026-08-02 03:33:42 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, resnet18, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID ADA4:1D7811:28B4DDA:8D9E840:6A6EBA8D and timestamp 2026-08-02 03:33:33 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, resnet18, xnnpack-quantization-delegation, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID E0B4:1C836C:30E9FA6:A879CF9:6A6EBA8C and timestamp 2026-08-02 03:33:32 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, resnet8, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID EAF0:827E7:282903F:8B94141:6A6EBA98 and timestamp 2026-08-02 03:33:44 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, sdpa, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID C316:3FCD1F:1DEA97D:67BE828:6A6EBA8E and timestamp 2026-08-02 03:33:34 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, smollm2, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID 8D52:D5E37:334284A:B05C545:6A6EBA9C and timestamp 2026-08-02 03:33:48 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, smolvlm, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID A2BC:3D714D:5EA9773:14B98BB0:6A6EBA82 and timestamp 2026-08-02 03:33:22 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, softmax, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID A0BC:49914:5B0D927:13F46F80:6A6EBA9A and timestamp 2026-08-02 03:33:46 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, vit, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]An error occurred trying to start process '/usr/bin/bash' with working directory '/home/ec2-user/actions-runner/_work/executorch/executorch/pytorch/executorch'. No such file or directory
  • periodic / test-models-linux (cmake, vit, xnnpack-quantization-delegation, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID C112:65A0D:2B41131:981C14E:6A6EBAA1 and timestamp 2026-08-02 03:33:53 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, whisper, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID BB9C:21D488:1F3B90D:6BA594E:6A6EBA90 and timestamp 2026-08-02 03:33:36 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting
  • periodic / test-models-linux (cmake, yolo26, portable, linux.2xlarge, 90) / linux-job (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID C0B6:3F8531:60AF5CA:15099339:6A6EBA9D and timestamp 2026-08-02 03:33:49 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

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 31, 2026
@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.

🟡 Not ready to approve

The new shared-runtime linking logic uses GNU ld-specific flags without platform guards, which can break builds when EXECUTORCH_BUILD_SHARED is enabled on non-ELF toolchains.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR makes the ExecuTorch wheel usable as a C++ SDK by shipping a linkable shared runtime (libexecutorch.so) and exposing it via find_package(executorch) as executorch::runtime, while also updating the Python extensions to link against that shared runtime to preserve a single process-wide backend registry.

Changes:

  • Add a consolidated shared runtime target (executorch_shared / libexecutorch.so) and update multiple extension/tool targets to resolve runtime symbols from it.
  • Extend the wheel CMake package config to provide an imported target executorch::runtime resolved relative to the installed wheel for relocatable consumption.
  • Add CI wheel smoke coverage that verifies single-registry behavior and that a standalone C++ app can build/run via only find_package(executorch) + executorch::runtime.
File summaries
File Description
tools/cmake/Utils.cmake Adds helper to force linking against the shared runtime early on the link line.
tools/cmake/preset/pybind.cmake Enables EXECUTORCH_BUILD_SHARED for the Linux pybind preset to ship the shared runtime in wheels.
tools/cmake/executorch-wheel-config.cmake Exposes executorch::runtime imported target and keeps legacy _portable_lib discovery.
tools/cmake/Codegen.cmake Avoids linking executorch_core when shared runtime is enabled; forces shared runtime resolution.
setup.py Installs the shared runtime SONAME into the wheel and expands header install coverage for runtime-linked extensions.
kernels/quantized/CMakeLists.txt Adds wheel-runtime-relative RPATH when shared runtime is enabled.
extension/training/CMakeLists.txt Switches pybind training module to shared runtime path and fixes RPATH for wheel layout.
extension/llm/runner/CMakeLists.txt Forces shared runtime resolution and adjusts RPATH when shared runtime is enabled.
extension/llm/custom_ops/CMakeLists.txt Ensures wheel-built artifact has correct RPATH and resolves runtime from shared library.
devtools/etdump/CMakeLists.txt Avoids executorch whole-archive when shared runtime is present; links shared runtime instead.
devtools/bundled_program/CMakeLists.txt Avoids whole-archive duplication by linking shared runtime when enabled.
codegen/tools/CMakeLists.txt Makes selective_build resolve runtime via shared library and sets wheel-relative RPATH.
CMakeLists.txt Defines executorch_shared earlier and updates pybind/utility targets to avoid embedding duplicate registries.
.github/workflows/build-wheels-*.yml Expands workflow path triggers to include CMakeLists and tools/cmake/.
.ci/scripts/wheel/test_linux.py Runs the new C++ SDK wheel test as part of Linux wheel smoke tests.
.ci/scripts/wheel/test_linux_aarch64.py Runs the new C++ SDK wheel test as part of aarch64 Linux wheel smoke tests.
.ci/scripts/wheel/test_cpp_sdk.py New test that validates single-registry and that a standalone C++ app can link/run via the wheel.
Review details
  • Files reviewed: 20/20 changed files
  • Comments generated: 2
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread tools/cmake/Utils.cmake
Comment thread CMakeLists.txt Outdated
[ghstack-poisoned]
Copilot AI review requested due to automatic review settings July 31, 2026 06:51
shoumikhin added a commit that referenced this pull request Jul 31, 2026
Today `pip install executorch` gives you the Python half of ExecuTorch but
nothing a C++ application can link. The wheel installs a header subset and an
`executorch-config.cmake`, but that config only locates the Python extension so
custom-op builds can compile against it: it defines no runtime library and no
CMake targets. Writing a small C++ program that loads and runs a `.pte` means
cloning the repo, syncing submodules, and building from source.

This change ships the runtime as a real library and exposes it through
`find_package`, so a standalone application needs nothing but the wheel:

    find_package(executorch REQUIRED)
    target_link_libraries(my_app PRIVATE executorch::runtime)

`executorch::runtime` is an imported target whose location is resolved relative
to the config file itself, so the package stays relocatable and no path from the
machine that built the wheel is baked into it. A consumer picks up the wheel's
library directory in its RUNPATH, plus `$ORIGIN`-relative entries so an
application deployed next to a copy of the runtime keeps working without
`LD_LIBRARY_PATH`.

The Python extensions have to move to the shared runtime in the same change.
Backends register themselves into a single process-wide table owned by the
runtime, and that table is only process-wide if exactly one loaded library
defines it. The Python extension statically embeds the runtime today, so adding a
shared library beside it would give a process two independent registries, and a
backend could register into the one nobody reads. The extensions therefore link
the shared runtime instead of whole-archiving the static libraries, leaving
exactly one registry owner for both the Python and C++ paths.

Getting that right needs two linker details. The shared runtime is named through
a link option rather than an ordinary dependency, because CMake orders link
libraries so a static archive precedes what it depends on, which would let the
archive satisfy the runtime symbols first. It is also wrapped in
`--no-as-needed`, because a shared library with no already-referenced symbol at
the point it appears on the link line can be dropped, and a later static archive
would then supply the registry after all.

Registration still happens through static initializers exactly as before. No new
plugin or loader ABI is introduced.

The shared runtime is Linux-only for the wheel. macOS C++ consumers are served by
the existing Swift package distribution, and the runtime has no export
annotations for a Windows DLL. Every other build keeps linking the static
libraries, because the new behavior is gated on the existing
`EXECUTORCH_BUILD_SHARED` option, so iOS, Android, and embedded builds are
unaffected.

Test plan:

The wheel smoke test now covers this on Linux, so it is checked in CI rather than
only by hand. It asserts that exactly one shipped library defines the backend
registry, builds a standalone C++ program that only calls
`find_package(executorch)` and links `executorch::runtime`, runs it without
`LD_LIBRARY_PATH`, and checks the resulting binary depends on the shipped runtime
with a relocatable RUNPATH. The check was confirmed to fail when a second
registry definition is introduced deliberately. The wheel workflows now also run
when any `CMakeLists.txt` or anything under `tools/cmake` changes, since those
files decide what the wheel contains.

Built the wheel from a clean checkout on Linux x86_64 and on Linux aarch64, then
verified each against a fresh virtual environment with a normal
dependency-resolving install:

- `nm -DC` across every shipped shared object shows exactly one definition of the
  registry entry points; the Python extensions import them rather than defining
  their own.
- A C++ program whose CMake only calls `find_package(executorch)` and links
  `executorch::runtime` compiles against the installed wheel with no source
  checkout, then loads a `.pte` and lists its methods.
- `readelf -d` on that program lists the versioned runtime in `DT_NEEDED` with
  `$ORIGIN`-relative RUNPATH entries, and it runs without `LD_LIBRARY_PATH`.
- A C++ binary that links only `executorch::runtime` and loads the Python
  extension sees the backends that extension registered, which is the
  one-registry property stated above.
- `import executorch`, the registered backend list, and `.pte` execution through
  the Python bindings are unchanged, with outputs matching eager PyTorch.
- With `EXECUTORCH_BUILD_SHARED` off, the Python extension still builds
  self-contained and no shared runtime is produced, so the previous behavior is
  intact.
- Configured with CMake 3.28 as well as 3.31, since the project supports 3.24 and
  up and the two differ in how strictly they treat link features.

ghstack-source-id: ab9b01b
ghstack-comment-id: 5139976402
Pull-Request: #21514
@shoumikhin

Copy link
Copy Markdown
Contributor Author

Good catch, fixed in the latest push.

Both of these were real. The whole-archive loop used to go through
$<LINK_LIBRARY:WHOLE_ARCHIVE,...>, which CMake maps to the right flag per
platform, and switching to raw flags lost that. There is now a small
executorch_target_whole_archive helper next to the existing kernel-link helpers
that picks --whole-archive, -force_load, or /WHOLEARCHIVE based on the
platform, and the shared-runtime helper only adds --no-as-needed on ELF
platforms. No raw GNU flag is emitted outside those two helpers now.

Worth noting the option that reaches this code is only turned on for Linux today,
so this is about not breaking someone who enables it by hand rather than a live
failure. Verified by building the wheel and running the wheel checks on Linux
x86_64 and aarch64 after the change.

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.

🟡 Not ready to approve

The new executorch::runtime CMake config has correctness/robustness issues (duplicate target definition risk and unconditional Python failure path) that can break consumers during configuration.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (3)

tools/cmake/executorch-wheel-config.cmake:121

  • With the new executorch::runtime target, a pure C++ consumer should be able to configure successfully even if python3 isn't available on PATH. Right now the unconditional execute_process(${PYTHON_EXECUTABLE} ...) followed by FATAL_ERROR prevents using the shared runtime without Python. Consider treating EXT_SUFFIX lookup as best-effort when the shared runtime was found, and skip _portable_lib discovery in that case.
find_library(
  _portable_lib_LIBRARY
  NAMES _portable_lib${EXT_SUFFIX}
  PATHS "${_executorch_package_root}/extension/pybindings/"
)

tools/cmake/executorch-wheel-config.cmake:121

  • find_library() will also search default system locations, which can accidentally pick up a different _portable_lib<EXT_SUFFIX> (e.g., from another install) and silently mix headers/libs. Since this config is meant to bind to the wheel it lives in, add NO_DEFAULT_PATH to restrict the search to the wheel directory.
find_library(
  _portable_lib_LIBRARY
  NAMES _portable_lib${EXT_SUFFIX}
  PATHS "${_executorch_package_root}/extension/pybindings/"
)

tools/cmake/executorch-wheel-config.cmake:68

  • executorch-config.cmake can be processed more than once in a single configure (e.g., multiple find_package(executorch) calls via subprojects). Unconditionally calling add_library(executorch::runtime ...) will then error with a duplicate target name. Guard the add_library call with if(NOT TARGET executorch::runtime) but still apply the target properties afterward.

This issue also appears in the following locations of the same file:

  • line 117
  • line 117
  add_library(executorch::runtime SHARED IMPORTED)
  set_target_properties(
    executorch::runtime
    PROPERTIES IMPORTED_LOCATION "${_executorch_runtime_library}"
               INTERFACE_INCLUDE_DIRECTORIES "${EXECUTORCH_INCLUDE_DIRS}"
  • Files reviewed: 20/20 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

[ghstack-poisoned]
Copilot AI review requested due to automatic review settings July 31, 2026 14:53
shoumikhin added a commit that referenced this pull request Jul 31, 2026
Today `pip install executorch` gives you the Python half of ExecuTorch but
nothing a C++ application can link. The wheel installs a header subset and an
`executorch-config.cmake`, but that config only locates the Python extension so
custom-op builds can compile against it: it defines no runtime library and no
CMake targets. Writing a small C++ program that loads and runs a `.pte` means
cloning the repo, syncing submodules, and building from source.

This change ships the runtime as a real library and exposes it through
`find_package`, so a standalone application needs nothing but the wheel:

    find_package(executorch REQUIRED)
    target_link_libraries(my_app PRIVATE executorch::runtime)

`executorch::runtime` is an imported target whose location is resolved relative
to the config file itself, so the package stays relocatable and no path from the
machine that built the wheel is baked into it. A consumer picks up the wheel's
library directory in its RUNPATH, plus `$ORIGIN`-relative entries so an
application deployed next to a copy of the runtime keeps working without
`LD_LIBRARY_PATH`.

The Python extensions have to move to the shared runtime in the same change.
Backends register themselves into a single process-wide table owned by the
runtime, and that table is only process-wide if exactly one loaded library
defines it. The Python extension statically embeds the runtime today, so adding a
shared library beside it would give a process two independent registries, and a
backend could register into the one nobody reads. The extensions therefore link
the shared runtime instead of whole-archiving the static libraries, leaving
exactly one registry owner for both the Python and C++ paths.

Getting that right needs two linker details. The shared runtime is named through
a link option rather than an ordinary dependency, because CMake orders link
libraries so a static archive precedes what it depends on, which would let the
archive satisfy the runtime symbols first. It is also wrapped in
`--no-as-needed`, because a shared library with no already-referenced symbol at
the point it appears on the link line can be dropped, and a later static archive
would then supply the registry after all.

Registration still happens through static initializers exactly as before. No new
plugin or loader ABI is introduced.

The shared runtime is Linux-only for the wheel. macOS C++ consumers are served by
the existing Swift package distribution, and the runtime has no export
annotations for a Windows DLL. Every other build keeps linking the static
libraries, because the new behavior is gated on the existing
`EXECUTORCH_BUILD_SHARED` option, so iOS, Android, and embedded builds are
unaffected.

Test plan:

The wheel smoke test now covers this on Linux, so it is checked in CI rather than
only by hand. It asserts that exactly one shipped library defines the backend
registry, builds a standalone C++ program that only calls
`find_package(executorch)` and links `executorch::runtime`, runs it without
`LD_LIBRARY_PATH`, and checks the resulting binary depends on the shipped runtime
with a relocatable RUNPATH. The check was confirmed to fail when a second
registry definition is introduced deliberately. The wheel workflows now also run
when any `CMakeLists.txt` or anything under `tools/cmake` changes, since those
files decide what the wheel contains.

Built the wheel from a clean checkout on Linux x86_64 and on Linux aarch64, then
verified each against a fresh virtual environment with a normal
dependency-resolving install:

- `nm -DC` across every shipped shared object shows exactly one definition of the
  registry entry points; the Python extensions import them rather than defining
  their own.
- A C++ program whose CMake only calls `find_package(executorch)` and links
  `executorch::runtime` compiles against the installed wheel with no source
  checkout, then loads a `.pte` and lists its methods.
- `readelf -d` on that program lists the versioned runtime in `DT_NEEDED` with
  `$ORIGIN`-relative RUNPATH entries, and it runs without `LD_LIBRARY_PATH`.
- A C++ binary that links only `executorch::runtime` and loads the Python
  extension sees the backends that extension registered, which is the
  one-registry property stated above.
- `import executorch`, the registered backend list, and `.pte` execution through
  the Python bindings are unchanged, with outputs matching eager PyTorch.
- With `EXECUTORCH_BUILD_SHARED` off, the Python extension still builds
  self-contained and no shared runtime is produced, so the previous behavior is
  intact.
- Configured with CMake 3.28 as well as 3.31, since the project supports 3.24 and
  up and the two differ in how strictly they treat link features.

ghstack-source-id: 401229a
ghstack-comment-id: 5139976402
Pull-Request: #21514

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

[ghstack-poisoned]

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.

🟡 Not ready to approve

Several new $ORIGIN-relative RPATH adjustments appear wheel-layout-specific but are not guarded as wheel-only, which can break non-wheel shared builds/installs when EXECUTORCH_BUILD_SHARED is enabled.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (9)

backends/qualcomm/CMakeLists.txt:387

  • This RPATH setting assumes the wheel layout (runtime under executorch/lib). For non-wheel shared installs where libexecutorch.so is in ${CMAKE_INSTALL_LIBDIR}, $ORIGIN/../../../lib may be incorrect and can break loading. Consider gating this wheel-specific RPATH on EXECUTORCH_BUILD_WHEEL_DO_NOT_USE.
    if(NOT APPLE)

CMakeLists.txt:1143

  • The added $ORIGIN-relative RPATH entry assumes the wheel layout (runtime under executorch/lib). In a non-wheel shared build/install, libexecutorch.so installs to ${CMAKE_INSTALL_LIBDIR} (e.g. /lib), so $ORIGIN/../../lib would resolve to /executorch/lib and can break runtime loading. Since this path is wheel-specific, gate it on EXECUTORCH_BUILD_WHEEL_DO_NOT_USE (or compute the correct relative path for non-wheel installs).
  set(_portable_lib_rpath "$ORIGIN/../../../torch/lib")
  if(EXECUTORCH_BUILD_SHARED)
    string(APPEND _portable_lib_rpath ":$ORIGIN/../../lib")
  endif()

codegen/tools/CMakeLists.txt:54

  • This $ORIGIN/../../lib RPATH assumes the wheel layout (runtime shipped under executorch/lib). In a normal CMake install, executorch_shared goes to ${CMAKE_INSTALL_LIBDIR}, so this relative path will be wrong and can prevent the module from finding libexecutorch.so at runtime. Consider gating the wheel-specific RPATH on EXECUTORCH_BUILD_WHEEL_DO_NOT_USE.
  if(NOT APPLE)

extension/training/CMakeLists.txt:94

  • This RPATH block hardcodes the wheel’s internal layout (runtime under executorch/lib). For non-wheel shared builds, libexecutorch.so installs to ${CMAKE_INSTALL_LIBDIR}, so this can be incorrect and break loading. Since the comment explicitly describes the wheel layout, guard this block with EXECUTORCH_BUILD_WHEEL_DO_NOT_USE.
  if(EXECUTORCH_BUILD_SHARED AND NOT APPLE)

extension/llm/runner/CMakeLists.txt:141

  • This wheel-layout RPATH addition assumes the runtime is in executorch/lib; that is not true for a standard CMake install where libexecutorch.so goes to ${CMAKE_INSTALL_LIBDIR}. To avoid breaking non-wheel shared builds, gate this on EXECUTORCH_BUILD_WHEEL_DO_NOT_USE.
    if(EXECUTORCH_BUILD_SHARED)

extension/llm/custom_ops/CMakeLists.txt:119

  • This $ORIGIN/../../../lib RPATH is described as matching the wheel layout (runtime under executorch/lib). In a standard install, executorch_shared is in ${CMAKE_INSTALL_LIBDIR}, so this relative path can be wrong and break runtime loading. Gate this wheel-specific adjustment on EXECUTORCH_BUILD_WHEEL_DO_NOT_USE.
    if(EXECUTORCH_BUILD_SHARED)

kernels/quantized/CMakeLists.txt:89

  • This RPATH is described as matching the wheel layout (runtime shipped under executorch/lib). For non-wheel shared builds/install, libexecutorch.so is under ${CMAKE_INSTALL_LIBDIR}, so $ORIGIN/../../lib can be incorrect. Consider guarding this block with EXECUTORCH_BUILD_WHEEL_DO_NOT_USE to avoid breaking non-wheel shared builds.
    if(EXECUTORCH_BUILD_SHARED AND NOT APPLE)

kernels/quantized/CMakeLists.txt:144

  • This wheel-layout RPATH append assumes the runtime is under executorch/lib. In non-wheel shared installs, libexecutorch.so is under ${CMAKE_INSTALL_LIBDIR}, so this relative path can be wrong. Gate this on EXECUTORCH_BUILD_WHEEL_DO_NOT_USE (or compute the correct relative path for non-wheel installs).
        if(EXECUTORCH_BUILD_SHARED)

backends/qualcomm/CMakeLists.txt:265

  • This $ORIGIN/../../lib RPATH assumes the wheel layout (runtime under executorch/lib). In a normal CMake install, executorch_shared is in ${CMAKE_INSTALL_LIBDIR}, so this relative path can be incorrect and break runtime loading. Since wheel-only layout logic should be guarded, consider adding EXECUTORCH_BUILD_WHEEL_DO_NOT_USE to this condition.

This issue also appears on line 387 of the same file.

  if(NOT APPLE)
  • Files reviewed: 21/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

[ghstack-poisoned]

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.

🟡 Human review recommended

It makes wide-reaching build/linker/packaging changes whose safety depends on subtle link-line and runtime loader behavior across multiple targets and needs final human verification.

Review details
  • Files reviewed: 21/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

[ghstack-poisoned]
@shoumikhin

Copy link
Copy Markdown
Contributor Author

Thanks, the RPATH observations across these files were right and I have fixed all
of them.

Every $ORIGIN-relative entry I added was gated only on EXECUTORCH_BUILD_SHARED,
while the paths themselves assume the wheel's directory layout. The two layouts
really do differ:

normal install:  <prefix>/lib/libexecutorch.so      (CMAKE_INSTALL_LIBDIR)
wheel:           .../executorch/lib/libexecutorch.so.1

So in a non-wheel shared install, $ORIGIN/../../lib resolves to
<prefix>/lib/executorch/lib while the runtime sits at <prefix>/lib. That is a
dead RPATH, and it would only show up at load time.

Each of these now also requires EXECUTORCH_BUILD_WHEEL_DO_NOT_USE, which the
pybind preset already sets, so the entries apply to the wheel and a normal shared
install is left alone:

  • the pybindings extension
  • both Qualcomm backend targets
  • the selective-build module
  • the training extension
  • the LLM runner and the custom-ops library
  • the quantized AOT library (both places)

Verified on a freshly built wheel: the extension still carries both
$ORIGIN/../../../torch/lib and $ORIGIN/../../lib, the other modules still
carry their entries, and the C++ consumer test still builds, runs, and works when
deployed next to a copy of the runtime with the absolute build paths stripped.

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.

🟡 Not ready to approve

The wheel CMake config has two verified correctness issues (stale cached _portable_lib_LIBRARY when skipping Python, and non-propagating C++20 requirement for _portable_lib) that can break downstream consumers.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (2)

tools/cmake/executorch-wheel-config.cmake:132

  • When Python is not usable but the shared runtime target exists, this branch sets EXT_SUFFIX to "" and skips find_library(), but _portable_lib_LIBRARY is a cache variable. If it was found in a previous configure (or from a different wheel), it can remain set and the later if(_portable_lib_LIBRARY) block will still run, incorrectly offering/linking the Python extension even though this code path is explicitly skipping it. Clear the cache + normal variable in this branch.
elseif(TARGET executorch::runtime)
  # A C++ application linking only the shared runtime does not need Python at
  # all, so a missing interpreter must not fail its configure. Skip locating the
  # Python extension instead; the legacy _portable_lib target is simply not
  # offered in that case.
  message(
    STATUS
      "Python not usable, skipping the Python extension: ${SYSCONFIG_ERROR}"
  )
  set(EXT_SUFFIX "")

tools/cmake/executorch-wheel-config.cmake:162

  • This imported _portable_lib target tries to enforce C++20 via CXX_STANDARD 20, but CXX_STANDARD does not propagate to consumers (and imported targets have no sources to compile). Downstream custom-op builds that link _portable_lib may still compile as C++17 and fail. Use an interface requirement like INTERFACE_COMPILE_FEATURES cxx_std_20 so it applies to consumer targets.
  set_target_properties(
    _portable_lib
  • Files reviewed: 21/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

[ghstack-poisoned]
@shoumikhin

Copy link
Copy Markdown
Contributor Author

Both of the latest points were correct and are now fixed.

Stale cached library path. The branch that skips the Python extension when no
interpreter is usable set the suffix empty and skipped the lookup, but
find_library caches its result, so a value from an earlier configure survived
and the extension was still offered. Reproduced it in the same build directory:

run 1, interpreter available:  <path to the extension>
run 2, no interpreter:
  "skipping the Python extension"   <- reported as skipped
  <path to the extension>           <- but still set

The config was saying one thing and doing another. It now clears the cache entry
on that path, and the second run reports an empty value.

C++ standard on the imported target. CXX_STANDARD does nothing useful here:
an imported target compiles no sources of its own, and the property does not reach
consumers, so a custom-op build linking it could still compile as C++17 and fail
against headers that need C++20. It is now an interface requirement
(INTERFACE_COMPILE_FEATURES cxx_std_20), and a consumer project reads back
cxx_std_20 as expected.

Also, for completeness on the earlier batch: every wheel-layout RPATH is now gated
so it only applies to the wheel, and a normal shared install is left alone.

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.

🟡 Human review recommended

It changes core build/link behavior and wheel packaging/RPATH mechanics across many targets, which warrants final human verification despite the added CI tests.

Review details
  • Files reviewed: 21/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

[ghstack-poisoned]

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.

🟡 Not ready to approve

The QNN backend’s shared-runtime linkage can run before executorch_shared is defined (top-level ordering), which will break configurations that enable both EXECUTORCH_BUILD_QNN and EXECUTORCH_BUILD_SHARED.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (1)

tools/cmake/executorch-wheel-config.cmake:176

  • This config sets EXECUTORCH_FOUND, but find_package(executorch REQUIRED) gates on executorch_FOUND (the package name + _FOUND). As written, find_package(... REQUIRED) can succeed even when EXECUTORCH_FOUND remains OFF (e.g., if neither the runtime nor _portable_lib is found), which contradicts the documented usage in this file.
endif()
  • Files reviewed: 21/21 changed files
  • Comments generated: 1
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment on lines +260 to +265
# Resolve the runtime from the shared library when one is built, so this
# delegate does not carry its own copy of the backend registry.
if(EXECUTORCH_BUILD_SHARED)
target_link_libraries(qnn_executorch_backend PRIVATE executorch_shared)
executorch_target_link_shared_runtime(qnn_executorch_backend)
if(NOT APPLE AND EXECUTORCH_BUILD_WHEEL_DO_NOT_USE)
[ghstack-poisoned]

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.

🟡 Human review recommended

It makes wide-ranging, linker-order-sensitive build/packaging changes across multiple CMake targets and platforms that merit final human validation beyond automated review.

Review details

Suppressed comments (1)

kernels/quantized/CMakeLists.txt:92

  • The wheel-specific BUILD_RPATH/INSTALL_RPATH block for quantized_ops_aot_lib is later overwritten when TARGET portable_lib is true (another set_target_properties(... BUILD_RPATH ... INSTALL_RPATH ...) runs below). This makes the first block redundant in the common pybind+wheel case and creates two independent places to maintain the runtime rpath logic.
    if(EXECUTORCH_BUILD_SHARED
       AND NOT APPLE
       AND EXECUTORCH_BUILD_WHEEL_DO_NOT_USE
    )
  • Files reviewed: 21/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

[ghstack-poisoned]

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.

🟡 Human review recommended

It makes broad, platform- and linker-sensitive build/distribution changes (CMake linking/RPATH/runtime packaging) that warrant final human verification across supported build modes and environments.

Review details
  • Files reviewed: 21/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

[ghstack-poisoned]

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.

🟡 Not ready to approve

gen_custom_ops_aot_lib() in shared builds can lose required ExecuTorch usage requirements (include dirs/compile defs) when portable_lib is absent, which can break shared+non-pybind configurations.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details
  • Files reviewed: 21/21 changed files
  • Comments generated: 1
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread tools/cmake/Codegen.cmake
Comment on lines 263 to +267
target_link_libraries(${GEN_LIB_NAME} PRIVATE portable_lib)
else()
elseif(NOT EXECUTORCH_BUILD_SHARED)
target_link_libraries(${GEN_LIB_NAME} PRIVATE executorch_core)
endif()
executorch_target_link_shared_runtime(${GEN_LIB_NAME})
[ghstack-poisoned]

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.

🟡 Human review recommended

The change spans core build/link semantics and wheel packaging across many targets/platform conditionals, and needs careful human validation despite added CI coverage.

Review details

Suppressed comments (1)

tools/cmake/executorch-wheel-config.cmake:163

  • _portable_lib is located via find_library using the wheel’s Python extension suffix (i.e., it’s a shared object), but it’s declared as STATIC IMPORTED. That type mismatch can cause CMake to treat it like an archive (and may affect link behavior/rpath handling for custom-op builds). Declare it as an imported shared library instead.
  if(NOT TARGET _portable_lib)
    add_library(_portable_lib STATIC IMPORTED)
  endif()
  • Files reviewed: 21/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

[ghstack-poisoned]

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.

🟡 Not ready to approve

The wheel CMake config’s legacy _portable_lib imported target doesn’t currently propagate C10_USING_CUSTOM_GENERATED_MACROS, which can break custom-op consumers compiling against the wheel’s headers.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (1)

tools/cmake/executorch-wheel-config.cmake:179

  • The legacy _portable_lib imported target doesn’t propagate C10_USING_CUSTOM_GENERATED_MACROS to consumers, but the same headers are exposed via EXECUTORCH_INCLUDE_DIRS. If the wheel doesn’t ship torch/headeronly/macros/cmake_macros.h, custom-op builds that link _portable_lib can fail to compile with cmake_macros.h not found (the runtime target already sets this definition).
  set_target_properties(
    _portable_lib
    PROPERTIES IMPORTED_LOCATION "${_portable_lib_LIBRARY}"
               INTERFACE_INCLUDE_DIRECTORIES "${EXECUTORCH_INCLUDE_DIRS}"
               # An interface requirement rather than CXX_STANDARD: an imported
               # target compiles nothing itself, and CXX_STANDARD does not reach
               # consumers, so a custom-op build linking this could still
               # compile
               # as C++17 and fail against headers that need C++20.
               INTERFACE_COMPILE_FEATURES cxx_std_20
  )
  • Files reviewed: 21/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

[ghstack-poisoned]

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.

🟡 Not ready to approve

The CMake package config’s “skip Python extension” path can still leave _portable_lib_LIBRARY set in normal scope, potentially advertising a stale _portable_lib target despite intentionally skipping Python discovery.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (1)

tools/cmake/executorch-wheel-config.cmake:136

  • When Python sysconfig lookup fails, this code unsets only the cache entry for _portable_lib_LIBRARY. In CMake, a stale normal-scope value can still remain (e.g., populated from the cache at the start of configure), so the later if(_portable_lib_LIBRARY) block can still run and incorrectly offer the _portable_lib imported target even though this configure intentionally skipped locating it. Clearing the normal variable as well makes the skip reliable.
  set(EXT_SUFFIX "")
  # find_library caches its result, so a value left by an earlier configure
  # would survive and the extension would still be offered despite being skipped
  # here.
  unset(_portable_lib_LIBRARY CACHE)
  • Files reviewed: 21/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

[ghstack-poisoned]
[ghstack-poisoned]

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.

🟡 Not ready to approve

The new wheel smoke test currently skips many native-import failures and can miss real ABI/linkage regressions, so the CI coverage claimed in the PR description is not fully enforced.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (1)

.ci/scripts/wheel/test_cpp_sdk.py:265

  • test_python_extensions_import treats most import failures as “unrelated” and skips them. That can hide real wheel/linkage regressions (e.g., undefined symbol, symbol lookup error, or GLIBCXX/GLIBC version mismatches) that indicate a native dependency/ABI problem rather than a missing Python package.
        # A Python dependency that is simply not installed here, including torch,
        # says nothing about how the wheel was built. Only a failure to load a
        # native library does.
        if "ModuleNotFoundError" in result.stderr:
            print(f"- {module} needs a package this environment lacks, skipping")
            continue
        assert "cannot open shared object file" not in result.stderr, (
            f"{module} ships in the wheel but cannot load a native dependency, "
            f"which usually means a runtime path does not reach it: "
            f"{result.stderr.strip()[-400:]}"
        )
        print(f"- {module} did not import for an unrelated reason, skipping")

  • Files reviewed: 21/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

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.

🟡 Human review recommended

It introduces broad, cross-cutting build/link/packaging behavior changes (shared runtime + link-order semantics + wheel relocatability) that warrant final human verification across platforms/toolchains.

Review details
  • Files reviewed: 21/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

[ghstack-poisoned]

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.

🟡 Human review recommended

It makes wide-reaching build/link/packaging changes across CMake, wheel contents, and multiple extension targets where subtle platform/linker behavior regressions warrant final human verification.

Review details
  • Files reviewed: 21/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/binaries/all Release PRs with this label will build wheels for all python versions ciflow/binaries ciflow/cuda ciflow/nightly ciflow/periodic ciflow/trunk 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.

2 participants