Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【第三方库离线编译】add submodule pybind11 #54322

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
path = third_party/leveldb
url = https://github.com/google/leveldb
ignore = dirty
[submodule "third_party/pybind"]
path = third_party/pybind
url = https://github.com/pybind/pybind11.git
ignore = dirty
[submodule "third_party/threadpool"]
path = third_party/threadpool
url = https://github.com/progschj/ThreadPool.git
Expand Down
20 changes: 14 additions & 6 deletions cmake/external/pybind11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
include(ExternalProject)

set(PYBIND_PREFIX_DIR ${THIRD_PARTY_PATH}/pybind)
set(PYBIND_REPOSITORY ${GIT_URL}/pybind/pybind11.git)
set(PYBIND_SOURCE_DIR ${PYBIND_PREFIX_DIR}/src/extern_pybind)
set(PYBIND_INCLUDE_DIR ${PYBIND_SOURCE_DIR}/include)
set(PYBIND_TAG v2.10.3)
set(SOURCE_DIR ${PADDLE_SOURCE_DIR}/third_party/pybind)
set(SOURCE_INCLUDE_DIR ${SOURCE_DIR}/include)

set(PYBIND_INCLUDE_DIR ${THIRD_PARTY_PATH}/pybind/src/extern_pybind/include)
include_directories(${PYBIND_INCLUDE_DIR})

set(PYBIND_PATCH_COMMAND "")
Expand All @@ -31,14 +33,13 @@ if(NOT WIN32)
# 2. Patch twice: the tag version of cache == PYBIND_TAG, but patch has already applied to cache.
set(PYBIND_PATCH_COMMAND
git checkout -- . && git checkout ${PYBIND_TAG} && patch -Nd
${PYBIND_INCLUDE_DIR}/pybind11 < ${native_dst})
${SOURCE_INCLUDE_DIR}/pybind11 < ${native_dst})
endif()

ExternalProject_Add(
extern_pybind
${EXTERNAL_PROJECT_LOG_ARGS} ${SHALLOW_CLONE}
GIT_REPOSITORY ${PYBIND_REPOSITORY}
GIT_TAG ${PYBIND_TAG}
SOURCE_DIR ${SOURCE_DIR}
PREFIX ${PYBIND_PREFIX_DIR}
# If we explicitly leave the `UPDATE_COMMAND` of the ExternalProject_Add
# function in CMakeLists blank, it will cause another parameter GIT_TAG
Expand All @@ -48,7 +49,14 @@ ExternalProject_Add(
UPDATE_COMMAND ""
PATCH_COMMAND ${PYBIND_PATCH_COMMAND}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
# I intentionally preserved an extern_pybind/include/pybind11 directory
# to site-packages, so that you could discern that you intended to
# employ not only python, but also CPP and were ready to incorporate header files.
BUILD_COMMAND
COMMAND ${CMAKE_COMMAND} -E remove_directory ${PYBIND_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${PYBIND_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${SOURCE_INCLUDE_DIR}
${PYBIND_INCLUDE_DIR}
Comment on lines +52 to +59
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在这里保留了 ${THIRD_PARTY}/pybind/src/extern_pybind/include 目录,并且将 ${SOURCE_DIR}/include 中的内容复制过去。

Paddle/setup.py

Lines 146 to 156 in 2f0b4ad

# third_party
install_dir = re.sub(
env_dict.get("THIRD_PARTY_PATH"), 'third_party', header
)
patterns = [
'install/mkldnn/include/',
'pybind/src/extern_pybind/include/',
'third_party/xpu/src/extern_xpu/xpu/include/',
]
for pattern in patterns:
install_dir = re.sub(pattern, '', install_dir)

因为 setup.py 中需要对该目录('pybind/src/extern_pybind/include/')进行处理,并将之安装到 site-packages 中,所以在不大幅改动 setup.py 逻辑的情况下,先采用该方法。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在这里保留了 ${THIRD_PARTY}/pybind/src/extern_pybind/include 目录,并且将 ${SOURCE_DIR}/include 中的内容复制过去。

Paddle/setup.py

Lines 146 to 156 in 2f0b4ad

# third_party
install_dir = re.sub(
env_dict.get("THIRD_PARTY_PATH"), 'third_party', header
)
patterns = [
'install/mkldnn/include/',
'pybind/src/extern_pybind/include/',
'third_party/xpu/src/extern_xpu/xpu/include/',
]
for pattern in patterns:
install_dir = re.sub(pattern, '', install_dir)

因为 setup.py 中需要对该目录('pybind/src/extern_pybind/include/')进行处理,并将之安装到 site-packages 中,所以在不大幅改动 setup.py 逻辑的情况下,先采用该方法。

ok,的确。

INSTALL_COMMAND ""
TEST_COMMAND "")

Expand Down
2 changes: 1 addition & 1 deletion cmake/third_party.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ endif()

if(NOT ((NOT WITH_PYTHON) AND ON_INFER))
include(external/python) # find python and python_module
include(external/pybind11) # download pybind11
include(external/pybind11) # prepare submodule pybind11
list(APPEND third_party_deps extern_pybind)
endif()

Expand Down
1 change: 1 addition & 0 deletions third_party/pybind
Submodule pybind added at 0bd889