Skip to content

Commit 9c3c804

Browse files
committed
Package headers into pip wheel (#5734)
Summary: Changes `CustomBuildPy` to take a list of source directories relative to ExecuTorch root and copies all headers recursively into pip wheel during packaging. The destination is hardcoded to `executorch/include/executorch` in the pip wheel. Pull Request resolved: #5734 Test Plan: ```bash python setup.py bdist_wheel ``` This prints out the following lines: ``` creating pip-out/bdist.linux-x86_64/wheel/executorch/include/executorch/runtime creating pip-out/bdist.linux-x86_64/wheel/executorch/include/executorch/runtime/core copying pip-out/lib.linux-x86_64-cpython-311/executorch/include/executorch/runtime/core/array_ref.h -> pip-out/bdist.linux-x86_64/wheel/executorch/include/executorch/runtime/core ... ``` Then install the wheel: ```bash pip install dist/executorch-0.5.0a0+52d5218-cp311-cp311-linux_x86_64.whl ``` And we can find the headers in site-packages ``` /data/users/larryliu/executorch/pip-out/lib.linux-x86_64-cpython-311/executorch/include/executorch/runtime/core/array_ref.h ``` Reviewed By: dbort Differential Revision: D63561966 Pulled By: larryliu0820 fbshipit-source-id: 0c7d8983a89d11e62da006d361ca00b4a061d73c (cherry picked from commit d62c7ad)
1 parent 040015c commit 9c3c804

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

setup.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,25 @@ def run(self):
429429
"share/cmake/executorch-config.cmake",
430430
),
431431
]
432+
# Copy all the necessary headers into include/executorch/ so that they can
433+
# be found in the pip package. This is the subset of headers that are
434+
# essential for building custom ops extensions.
435+
# TODO: Use cmake to gather the headers instead of hard-coding them here.
436+
# For example: https://discourse.cmake.org/t/installing-headers-the-modern-
437+
# way-regurgitated-and-revisited/3238/3
438+
for include_dir in [
439+
"runtime/core/",
440+
"runtime/kernel/",
441+
"runtime/platform/",
442+
"extension/kernel_util/",
443+
"extension/tensor/",
444+
"extension/threadpool/",
445+
]:
446+
src_list = Path(include_dir).rglob("*.h")
447+
for src in src_list:
448+
src_to_dst.append(
449+
(str(src), os.path.join("include/executorch", str(src)))
450+
)
432451
for src, dst in src_to_dst:
433452
dst = os.path.join(dst_root, dst)
434453

0 commit comments

Comments
 (0)