Commit 86c35bd
committed
Ship a prebuilt C++ SDK in the ExecuTorch Linux wheel
## Why this is needed
Today, using the ExecuTorch runtime from a C++ program means building
ExecuTorch from source: clone the repo, sync submodules, and run a CMake
build before you can compile and link your own runner. The pip wheel only
ships the Python runtime module (`_portable_lib`) plus a small set of
headers meant for authoring custom operators. There is no way to just
`pip install executorch` and link a standalone C++ application against the
runtime.
This is friction for anyone whose deployment path is C++ (the common case
for on-device inference) and who already has the wheel installed for
export. The runtime is compiled during the wheel build and then discarded.
This change ships the runtime as a linkable shared library, its public
headers, and a CMake package config inside the Linux wheel, so a C++
program can link the ExecuTorch runtime with no source checkout and no
separate build.
## What is inside
Added to the Linux wheel (nothing removed; other platforms unchanged):
- `executorch/lib/libexecutorch.so` (SONAME-versioned, with the standard
`libexecutorch.so -> .so.1 -> .so.<version>` chain): the consolidated
shared runtime. It bundles the runtime core plus the common runtime
extensions (module, tensor, data_loader, flat_tensor, named_data_map).
- `executorch/include/executorch/extension/...`: the public headers for the
Module, Tensor, DataLoader, FlatTensor (.ptd reader), NamedDataMap, and
header-only MallocMemoryAllocator APIs. Runtime/Program/backend headers
were already shipped and are reused.
- `executorch/share/cmake/executorch-config.cmake`: a CMake package config
that exposes an `executorch::runtime` imported target (plus convenience
aliases `executorch::core`, `executorch::extension_*`).
- `executorch/utils/cmake_prefix_path`: a small helper (mirrors
`torch.utils.cmake_prefix_path`) so CMake can find the config in one line.
## Why a shared library (not static archives)
The runtime is shipped shared on purpose. ExecuTorch keeps a single
process-global backend/kernel registry. Shipping the runtime as one shared
`libexecutorch.so` lets a separately distributed backend or delegate shared
library register into that one registry: the backend `.so` is built without
its own copy of the runtime (its `register_backend` reference is undefined
and resolves against `libexecutorch.so` at load), and its static-init
registration runs when the `.so` is loaded (via whole-archive for a C++ app,
or an explicit import/dlopen for Python, which is how ExecuTorch already
ships the QNN backend today). Static archives would give each consumer its
own private registry, which cannot support loading multiple independently
distributed backends into one runtime.
The set is intentionally libtorch-free and excludes the general CPU
operator/kernel libraries, because a delegate supplies its own compute. It
is also Linux only: the `.so` naming and SONAME symlink chain are Unix
specific, so the Windows and macOS wheels are byte-identical to before.
## How to use it
```bash
pip install executorch
```
```cmake
find_package(executorch CONFIG REQUIRED)
add_executable(my_runner main.cpp)
target_link_libraries(my_runner PRIVATE executorch::runtime)
```
```bash
cmake -S . -B build \
-DCMAKE_PREFIX_PATH="$(python -c 'import executorch.utils as u; print(u.cmake_prefix_path)')"
cmake --build build
```
Existing consumers that use `find_package(executorch)` to link the Python
`_portable_lib` for custom-op extensions keep working unchanged. The new
C++ SDK availability is reported separately via `EXECUTORCH_SDK_FOUND`, so
the legacy `EXECUTORCH_FOUND` / `EXECUTORCH_LIBRARIES` contract is
preserved.
## Test plan
Verified on Linux x86_64:
- Built the wheel with `python setup.py bdist_wheel` and confirmed it
contains `libexecutorch.so` with its SONAME symlink chain, the CMake
config, the `utils` helper, and the new extension headers, and that
headers with no shipped implementation are excluded.
- Installed the wheel into a clean virtual environment and built a small
standalone C++ runner against it with `find_package(executorch)` and
`executorch.utils.cmake_prefix_path`. The runner compiled, linked, ran,
and initialized the runtime.
- Built a separate "coreless" backend shared library (no bundled runtime,
`register_backend` left undefined) and confirmed that loading it against
the installed `libexecutorch.so` registers the backend into the runtime's
registry (`get_backend_class` goes from not-found to found). This is the
mechanism that lets independently distributed backends coalesce into one
runtime.
- Confirmed the runner and the runtime link no libtorch/libc10 (via `ldd`).
- Confirmed the Windows and macOS wheel code paths add nothing new, so those
wheels are unaffected.
- Lint and format pass (flake8, ufmt, cmake-format).
Known limitation: the wheel-build step stores the SONAME symlinks as plain
file copies rather than symlinks. Linking and loading still work because the
SONAME target is present as a real file; a follow-up can preserve them as
true symlinks to save space.1 parent 0b13b6a commit 86c35bd
3 files changed
Lines changed: 294 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
323 | 344 | | |
324 | 345 | | |
325 | 346 | | |
| |||
508 | 529 | | |
509 | 530 | | |
510 | 531 | | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
511 | 569 | | |
512 | 570 | | |
513 | 571 | | |
| |||
663 | 721 | | |
664 | 722 | | |
665 | 723 | | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
666 | 749 | | |
667 | 750 | | |
668 | 751 | | |
| |||
749 | 832 | | |
750 | 833 | | |
751 | 834 | | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
752 | 867 | | |
753 | 868 | | |
754 | 869 | | |
| |||
900 | 1015 | | |
901 | 1016 | | |
902 | 1017 | | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
903 | 1024 | | |
904 | 1025 | | |
905 | 1026 | | |
| |||
954 | 1075 | | |
955 | 1076 | | |
956 | 1077 | | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
957 | 1088 | | |
958 | 1089 | | |
959 | 1090 | | |
| |||
1125 | 1256 | | |
1126 | 1257 | | |
1127 | 1258 | | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
1128 | 1281 | | |
1129 | 1282 | | |
1130 | 1283 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
23 | 34 | | |
24 | | - | |
25 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
26 | 40 | | |
27 | 41 | | |
28 | 42 | | |
| |||
43 | 57 | | |
44 | 58 | | |
45 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
46 | 71 | | |
47 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
48 | 78 | | |
49 | 79 | | |
50 | | - | |
51 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
52 | 84 | | |
53 | 85 | | |
54 | 86 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | 87 | | |
64 | 88 | | |
65 | 89 | | |
66 | 90 | | |
67 | 91 | | |
68 | 92 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
77 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
78 | 175 | | |
0 commit comments