Skip to content
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
18 changes: 18 additions & 0 deletions cmake/external/pybind11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ set(SOURCE_INCLUDE_DIR ${SOURCE_DIR}/include)

include_directories(${PYBIND_INCLUDE_DIR})

# It can be safely removed in gcc9.1+
set(PYBIND_PATCH_COMMAND "")
Copy link
Member

Choose a reason for hiding this comment

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

加个注释吧,说明这个 patch 可以在 gcc 9.1+ 安全移除

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

if(LINUX
AND (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
set(PYBIND_TAG v2.12.0)
file(TO_NATIVE_PATH
${PADDLE_SOURCE_DIR}/patches/pybind/detail/internals.h.patch native_dst)
# Note: [Why calling some `git` commands before `patch`?]
# Paddle's CI uses cache to accelerate the make process. However, error might raise when patch codes in two scenarios:
# 1. Patch to the wrong version: the tag version of CI's cache falls behind PYBIND_TAG, use `git checkout ${PYBIND_TAG}` to solve this.
# 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
${SOURCE_INCLUDE_DIR}/pybind11/detail < ${native_dst})
endif()

ExternalProject_Add(
extern_pybind
${EXTERNAL_PROJECT_LOG_ARGS} ${SHALLOW_CLONE}
Expand All @@ -33,6 +50,7 @@ ExternalProject_Add(
# third-party library version changes cannot be incorporated.
# reference: https://cmake.org/cmake/help/latest/module/ExternalProject.html
UPDATE_COMMAND ""
PATCH_COMMAND ${PYBIND_PATCH_COMMAND}
CONFIGURE_COMMAND ""
# I intentionally preserved an extern_pybind/include/pybind11 directory
# to site-packages, so that you could discern that you intended to
Expand Down
22 changes: 22 additions & 0 deletions patches/pybind/detail/internals.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h
index c1047e4a..e09a6495 100644
--- a/include/pybind11/detail/internals.h
+++ b/include/pybind11/detail/internals.h
@@ -193,11 +193,18 @@ struct internals {
PyTypeObject *default_metaclass;
PyObject *instance_base;
#if defined(WITH_THREAD)
+#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 8
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
+#endif
// Unused if PYBIND11_SIMPLE_GIL_MANAGEMENT is defined:
PYBIND11_TLS_KEY_INIT(tstate)
# if PYBIND11_INTERNALS_VERSION > 4
PYBIND11_TLS_KEY_INIT(loader_life_support_tls_key)
# endif // PYBIND11_INTERNALS_VERSION > 4
+#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 8
+#pragma GCC diagnostic pop
+#endif
// Unused if PYBIND11_SIMPLE_GIL_MANAGEMENT is defined:
PyInterpreterState *istate = nullptr;