Skip to content

Commit cc2cde8

Browse files
larryliu0820pytorchbot
authored andcommitted
Improve pip package build (#5965)
Summary: Addressing comments in #5961. * Separate out `executorch-wheel-config.cmake` from `executorch-config.cmake`. * Hardcode the envrionment variable `SETUPTOOLS_EXT_SUFFIX` in `setup.py`. Pull Request resolved: #5965 Reviewed By: dbort Differential Revision: D64017947 Pulled By: larryliu0820 fbshipit-source-id: 0bdff5e2d2ec5873540d1b701595c7a316e84e80 (cherry picked from commit 1327090)
1 parent d8dacf3 commit cc2cde8

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

build/executorch-config.cmake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Copyright (c) Meta Platforms, Inc. and affiliates.
23
# All rights reserved.
34
#
@@ -13,7 +14,7 @@
1314
cmake_minimum_required(VERSION 3.19)
1415

1516
set(_root "${CMAKE_CURRENT_LIST_DIR}/../..")
16-
set(required_lib_list executorch executorch_no_prim_ops portable_kernels)
17+
set(required_lib_list executorch executorch_core portable_kernels)
1718
foreach(lib ${required_lib_list})
1819
set(lib_var "LIB_${lib}")
1920
add_library(${lib} STATIC IMPORTED)
@@ -26,7 +27,7 @@ foreach(lib ${required_lib_list})
2627
target_include_directories(${lib} INTERFACE ${_root})
2728
endforeach()
2829

29-
target_link_libraries(executorch INTERFACE executorch_no_prim_ops)
30+
target_link_libraries(executorch INTERFACE executorch_core)
3031

3132
if(CMAKE_BUILD_TYPE MATCHES "Debug")
3233
set(FLATCCRT_LIB flatccrt_d)
@@ -48,8 +49,13 @@ set(lib_list
4849
extension_runner_util
4950
extension_tensor
5051
extension_threadpool
52+
extension_training
5153
xnnpack_backend
54+
# Start XNNPACK Lib Deps
5255
XNNPACK
56+
microkernels-prod
57+
kleidiai
58+
# End XNNPACK Lib Deps
5359
cpuinfo
5460
pthreadpool
5561
vulkan_backend

build/executorch-wheel-config.cmake

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Config defining how CMake should find ExecuTorch package. CMake will search
8+
# for this file and find ExecuTorch package if it is installed. Typical usage
9+
# is:
10+
#
11+
# find_package(executorch REQUIRED)
12+
# -------
13+
#
14+
# Finds the ExecuTorch library
15+
#
16+
# This will define the following variables:
17+
#
18+
# EXECUTORCH_FOUND -- True if the system has the ExecuTorch library
19+
# EXECUTORCH_INCLUDE_DIRS -- The include directories for ExecuTorch
20+
# EXECUTORCH_LIBRARIES -- Libraries to link against
21+
#
22+
cmake_minimum_required(VERSION 3.19)
23+
24+
# Find prebuilt _portable_lib.so. This file should be installed under
25+
# <site-packages>/executorch/share/cmake
26+
find_library(_portable_lib_LIBRARY _portable_lib.so PATHS "${CMAKE_CURRENT_LIST_DIR}/../../extension/pybindings/")
27+
set(EXECUTORCH_LIBRARIES)
28+
set(EXECUTORCH_FOUND OFF)
29+
if(_portable_lib_LIBRARY)
30+
set(EXECUTORCH_FOUND ON)
31+
message(STATUS "ExecuTorch portable library is found at ${_portable_lib_LIBRARY}")
32+
list(APPEND EXECUTORCH_LIBRARIES _portable_lib)
33+
add_library(_portable_lib STATIC IMPORTED)
34+
set(EXECUTORCH_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/include)
35+
set_target_properties(_portable_lib PROPERTIES
36+
IMPORTED_LOCATION "${_portable_lib_LIBRARY}"
37+
INTERFACE_INCLUDE_DIRECTORIES "${EXECUTORCH_INCLUDE_DIRS}"
38+
CXX_STANDARD 17
39+
)
40+
endif()

setup.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,11 @@ def run(self):
423423
"devtools/bundled_program/schema/scalar_type.fbs",
424424
"devtools/bundled_program/serialize/scalar_type.fbs",
425425
),
426+
# Install executorch-wheel-config.cmake to pip package.
427+
(
428+
"build/executorch-wheel-config.cmake",
429+
"share/cmake/executorch-config.cmake",
430+
),
426431
]
427432
for src, dst in src_to_dst:
428433
dst = os.path.join(dst_root, dst)
@@ -663,6 +668,10 @@ def get_ext_modules() -> List[Extension]:
663668
return ext_modules
664669

665670

671+
# Override extension suffix to be ".so", skipping package info such as
672+
# "cpython-311-darwin"
673+
os.environ["SETUPTOOLS_EXT_SUFFIX"] = ".so"
674+
666675
setup(
667676
version=Version.string(),
668677
# TODO(dbort): Could use py_modules to restrict the set of modules we

0 commit comments

Comments
 (0)