You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9377ded
Browse filesBrowse the repository at this point in the historyBrowse files
Ship the Core ML delegate as a linkable library in the macOS wheel (pytorch#22202)
## Summary
On macOS, the ExecuTorch pip wheel builds the Core ML delegate as a
static library and folds it into the Python extension `_C`. That has two
downsides:
1. A C++ application that installs the wheel **cannot link the Core ML
delegate**, because there is no standalone library to link against
(XNNPACK and MLX already ship one; Core ML is the odd one out).
2. `_C` carries the delegate's code even though `_C` is otherwise just
the Python bindings.
This change makes Core ML match how XNNPACK and MLX already ship: when
the wheel is built (`EXECUTORCH_BUILD_SHARED`), the delegate is built as
a shared library named `executorch_backend_coreml` and installed into
the wheel's `lib/`. `_C` then links it dynamically instead of absorbing
it, and a C++ app can link it through `find_package(executorch)` with
the new `backend_coreml` component.
Nothing changes for a source build: off the wheel path the delegate
stays static and links exactly as before.
## What changed
- `backends/apple/coreml/CMakeLists.txt`: the delegate builds `SHARED`
under `EXECUTORCH_BUILD_SHARED`, named `executorch_backend_coreml`, with
the shared-object soname policy and an `@loader_path` runtime path, and
bundles its `coreml_util` / `coreml_inmemoryfs` helper archives. The
static (source-build) path is unchanged.
- `setup.py`: ships `lib/libexecutorch_backend_coreml.dylib`.
- `tools/cmake/executorch-wheel-config.cmake`: adds the `backend_coreml`
`find_package` component.
- `.ci/scripts/wheel/test_shared_libraries.py`: adds the library to the
name allowlist and a one-owner row for the delegate.
## Test plan
Built with `EXECUTORCH_BUILD_SHARED=ON EXECUTORCH_BUILD_COREML=ON` on
macOS and confirmed with `nm`/`otool`:
- `libexecutorch_backend_coreml.dylib` is produced with install name
`@rpath/libexecutorch_backend_coreml.1.dylib` and an `@loader_path`
rpath;
- it exports the delegate entry point exactly once;
- it links the shared runtime `@rpath/libexecutorch.1.dylib` (not a
static copy), plus the CoreML/Accelerate/Foundation frameworks and
sqlite3;
- the referenced `coreml_util` / `coreml_inmemoryfs` helpers are bundled
in.
The wheel release check that asserts one owner per component passes,
with the delegate's `get_registered_delegate()` symbol defined only by
this library.
---------
Co-authored-by: PyTorch Bot <pytorchbot@users.noreply.github.com>
0 commit comments