Skip to content

Commit 5b56340

Browse files
committed
New pip build system
Summary: Compatible with `pythom -m build` instead of using the deprecated `python setup.py bdist_wheel`. A new custom build command builds all CMake targets, and a new custom build_ext command installs built files into the wheel. A new custom build_py command copies platform-independent files into the wheel instead of copying them into the source tree. Puts all generated files under pip-out instead of mixing with files in the tree. Uses Command methods like `mkpath` and `copy_file` to benefit from setuptools concepts like dry_run, and to get logging for free. Adds `flatc` to the wheel, but doesn't yet make it available on the path. Test Plan: Iteration command to test wheel building without completely rebuilding the system: ``` rm -rf \ /tmp/wheel-out \ pip-out/lib* \ pip-out/bdist.* \ pip-out/temp.*/cmake-out/CMake* \ executorch.egg-info \ third-party/flatcc/{bin,lib} \ ; \ python -m build \ --wheel --outdir /tmp/wheel-out --no-isolation ``` To fully rebuild the system, also `rm -rf pip-out`. The wheel file is written to (e.g.) ``` /tmp/wheel-out/executorch-0.1.0-cp310-cp310-linux_x86_64.whl ``` Examine it with `unzip -l`, or install it with `pip install /tmp/wheel-out/executorch*.whl`. Reviewers: Subscribers: Tasks: Tags:
1 parent 7f49029 commit 5b56340

File tree

12 files changed

+332
-178
lines changed

12 files changed

+332
-178
lines changed

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ buck-out/
33
cmake-out/
44
cmake-android-out/
55
cmake-ios-out/
6+
pip-out/
67
executorch.egg-info
78
__pycache__/
8-
build/lib/
9-
exir/_serialize/scalar_type.fbs
10-
exir/_serialize/program.fbs
11-
sdk/bundled_program/serialize/bundled_program_schema.fbs
12-
sdk/bundled_program/serialize/scalar_type.fbs
139

1410
# Any exported models and profiling outputs
1511
*.pte

CMakeLists.txt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,11 @@ if(EXECUTORCH_BUILD_FLATC)
236236
)
237237
endif()
238238
set(FLATC_EXECUTABLE flatc)
239-
option(FLATBUFFERS_BUILD_FLATC "" ON)
240-
option(FLATBUFFERS_BUILD_FLATHASH "" OFF)
241-
option(FLATBUFFERS_BUILD_FLATLIB "" OFF)
242-
option(FLATBUFFERS_BUILD_TESTS "" OFF)
243-
option(FLATBUFFERS_INSTALL "" OFF)
239+
set(FLATBUFFERS_BUILD_FLATC ON CACHE BOOL "")
240+
set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "")
241+
set(FLATBUFFERS_BUILD_FLATLIB OFF CACHE BOOL "")
242+
set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "")
243+
set(FLATBUFFERS_INSTALL OFF CACHE BOOL "")
244244
add_subdirectory(third-party/flatbuffers)
245245
endif()
246246
if(NOT FLATC_EXECUTABLE)
@@ -301,10 +301,10 @@ endif()
301301
# ${CMAKE_INSTALL_PREFIX}/
302302
install(
303303
TARGETS executorch
304-
DESTINATION lib
304+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
305305
INCLUDES
306306
DESTINATION ${_common_include_directories})
307-
install(FILES build/executorch-config.cmake DESTINATION lib/cmake/ExecuTorch)
307+
install(FILES build/executorch-config.cmake DESTINATION share/cmake/executorch)
308308

309309
#
310310
# executor_runner: Host tool that demonstrates program execution.
@@ -460,9 +460,6 @@ if(EXECUTORCH_BUILD_PYBIND)
460460
${PYBIND_LINK_MPS}
461461
${PYBIND_LINK_XNNPACK}
462462
)
463-
464-
install(TARGETS portable_lib
465-
LIBRARY DESTINATION executorch/extension/pybindings)
466463
endif()
467464

468465
# Print all summary

backends/apple/mps/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ target_link_libraries(mpsdelegate
7777

7878
install(
7979
TARGETS mpsdelegate
80-
DESTINATION lib
80+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
8181
INCLUDES
8282
DESTINATION ${_common_include_directories})

backends/qualcomm/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ add_subdirectory(
268268
${QNN_EXECUTORCH_ROOT_DIR}/aot/ir
269269
${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/ir
270270
)
271-
install(TARGETS qnn_executorch_backend DESTINATION lib)
271+
install(TARGETS qnn_executorch_backend DESTINATION ${CMAKE_INSTALL_LIBDIR})
272272

273273
# QNN pybind
274274
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")

extension/data_loader/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ target_compile_options(extension_data_loader PUBLIC ${_common_compile_options})
2525
# Install libraries
2626
install(
2727
TARGETS extension_data_loader
28-
DESTINATION ${CMAKE_BINARY_DIR}/lib
28+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
2929
INCLUDES
3030
DESTINATION ${_common_include_directories})

extension/module/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ target_compile_options(extension_module PUBLIC -Wno-deprecated-declarations
3232
# Install libraries
3333
install(
3434
TARGETS extension_module
35-
DESTINATION lib
35+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
3636
INCLUDES
3737
DESTINATION ${_common_include_directories})

extension/runner_util/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ target_compile_options(extension_runner_util PUBLIC ${_common_compile_options})
2727
# Install libraries
2828
install(
2929
TARGETS extension_runner_util
30-
DESTINATION ${CMAKE_BINARY_DIR}/lib
30+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
3131
INCLUDES
3232
DESTINATION ${_common_include_directories})

install_requirements.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ pip install --force-reinstall --pre transformers==${TRANSFORMERS_VERSION}
6969
TORCHSR_VERSION=1.0.4
7070
pip install --pre torchsr==${TORCHSR_VERSION}
7171

72+
echo STOP # @nocommit
73+
exit 1
7274
# Install ExecuTorch after dependencies are installed.
7375
EXECUTORCH_BUILD_PYBIND="$EXECUTORCH_BUILD_PYBIND" \
7476
CMAKE_ARGS="$CMAKE_ARGS" \

kernels/portable/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ target_compile_options(portable_kernels PUBLIC ${_common_compile_options})
6060
# runtime
6161
gen_operators_lib("portable_ops_lib" portable_kernels executorch)
6262

63-
install(TARGETS portable_kernels portable_ops_lib DESTINATION lib)
63+
install(TARGETS portable_kernels portable_ops_lib
64+
DESTINATION ${CMAKE_INSTALL_LIBDIR})

pyproject.toml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
[build-system]
2-
requires = ["setuptools", "wheel"]
2+
requires = [
3+
"setuptools",
4+
"wheel",
5+
# @nocommit: insted we're using --no-isolation
6+
# "tomli", # Needed by extract_sources.py
7+
# # @nocommit: this will be the wrong torch; it's not the nightly
8+
# "torch", # Provides TorchConfig.cmake
9+
# "ruamel.yaml", # Needed by gen_oplist.py
10+
]
311
build-backend = "setuptools.build_meta"
412

513
[project]
@@ -26,10 +34,13 @@ dependencies=[
2634
]
2735

2836
[tool.setuptools.package-data]
29-
"*" = ["*.fbs", "*.yaml"]
37+
# @nocommit: prune /test[s]/ dirs, /third-party/ dirs
38+
# @nocommit: yaml only for kernels?
39+
"*" = ["*.yaml"]
3040

3141
[tool.setuptools.exclude-package-data]
3242
"*" = ["*.pyc"]
3343

3444
[tool.usort]
45+
# Do not try to put "first-party" imports in their own section.
3546
first_party_detection = false

sdk/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ foreach(schema_file ${_bundled_input_schema_names})
5050
"${CMAKE_CURRENT_SOURCE_DIR}/bundled_program/schema/${schema_file}")
5151
endforeach()
5252

53+
set(FLATCC_TEST OFF CACHE BOOL "")
54+
set(FLATCC_CXX_TEST OFF CACHE BOOL "")
55+
set(FLATCC_REFLECTION OFF CACHE BOOL "")
5356
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third-party/flatcc
5457
${CMAKE_BINARY_DIR}/third-party/flatcc)
5558

@@ -154,6 +157,6 @@ target_include_directories(
154157
# Install libraries
155158
install(
156159
TARGETS bundled_program etdump flatccrt
157-
DESTINATION ${CMAKE_BINARY_DIR}/lib
160+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
158161
INCLUDES
159162
DESTINATION ${_common_include_directories})

0 commit comments

Comments
 (0)