Skip to content

Commit d3f40f2

Browse files
larryliu0820pytorchbot
authored andcommitted
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 d8dacf3 commit d3f40f2

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
@@ -424,6 +424,25 @@ def run(self):
424424
"devtools/bundled_program/serialize/scalar_type.fbs",
425425
),
426426
]
427+
# Copy all the necessary headers into include/executorch/ so that they can
428+
# be found in the pip package. This is the subset of headers that are
429+
# essential for building custom ops extensions.
430+
# TODO: Use cmake to gather the headers instead of hard-coding them here.
431+
# For example: https://discourse.cmake.org/t/installing-headers-the-modern-
432+
# way-regurgitated-and-revisited/3238/3
433+
for include_dir in [
434+
"runtime/core/",
435+
"runtime/kernel/",
436+
"runtime/platform/",
437+
"extension/kernel_util/",
438+
"extension/tensor/",
439+
"extension/threadpool/",
440+
]:
441+
src_list = Path(include_dir).rglob("*.h")
442+
for src in src_list:
443+
src_to_dst.append(
444+
(str(src), os.path.join("include/executorch", str(src)))
445+
)
427446
for src, dst in src_to_dst:
428447
dst = os.path.join(dst_root, dst)
429448

0 commit comments

Comments
 (0)