Skip to contentSkip to conversation

python3-pybind11: Use cmake to build and add -native version

PATCH In review Philip Balister 2 participants 2 messages Jul 10, 2020 – Jul 12, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 python3-pybind11: Use cmake to build and add -native version

* Switch to git repo to pick up cmake files for recipes to use
* Use cmake to build innstead of pypi so cmake files are included in sysroot
* Disable tests to prevent configure failure (I tried adding pytest asa DEPEND)
* Patch out cmake that strips output to prevent QA failures
* Do not check pointer length for installed python when cross compiling.
* With this I can build gnuradio using pybind11.

---
 ...t-check-pointer-size-when-cross-compiling.patch | 30 +++++++++++++++++
 .../0001-Do-not-strip-binaries.patch               | 39 ++++++++++++++++++++++
 .../python/python3-pybind11_2.5.0.bb               | 17 ++++++++--
 3 files changed, 83 insertions(+), 3 deletions(-)
 create mode 100644 meta-python/recipes-devtools/python/python3-pybind11/0001-Do-not-check-pointer-size-when-cross-compiling.patch
 create mode 100644 meta-python/recipes-devtools/python/python3-pybind11/0001-Do-not-strip-binaries.patch
meta-python/recipes-devtools/python/python3-pybind11/0001-Do-not-check-pointer-size-when-cross-compiling.patch new file +30 -0
new file mode 100644
index 000000000..6455c95e7
@@ -0,0 +1,30 @@
+From 3abfa65517959ad279481021fafefba28f955e76 Mon Sep 17 00:00:00 2001
+From: Philip Balister <[email protected]>
+Date: Fri, 10 Jul 2020 10:14:59 -0400
+Subject: [PATCH] Do not check pointer size when cross compiling.
+
+It is reasonable to build for 32 machine on a 64 bit build machine. Prevents:
+| CMake Error at tools/FindPythonLibsNew.cmake:127 (message):
+|   Python config failure: Python is 64-bit, chosen compiler is 32-bit
+
+Signed-off-by: Philip Balister <[email protected]>
+---
+ tools/FindPythonLibsNew.cmake | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/tools/FindPythonLibsNew.cmake b/tools/FindPythonLibsNew.cmake
+index d0c8fa2..8479e70 100644
+--- a/tools/FindPythonLibsNew.cmake
++++ b/tools/FindPythonLibsNew.cmake
+@@ -123,7 +123,7 @@ list(GET _PYTHON_VALUES 9 PYTHON_MULTIARCH)
+ 
+ # Make sure the Python has the same pointer-size as the chosen compiler
+ # Skip if CMAKE_SIZEOF_VOID_P is not defined
+-if(CMAKE_SIZEOF_VOID_P AND (NOT "${PYTHON_SIZEOF_VOID_P}" STREQUAL "${CMAKE_SIZEOF_VOID_P}"))
++if((NOT CMAKE_CROSSCOMPILING) AND CMAKE_SIZEOF_VOID_P AND (NOT "${PYTHON_SIZEOF_VOID_P}" STREQUAL "${CMAKE_SIZEOF_VOID_P}"))
+     if(PythonLibsNew_FIND_REQUIRED)
+         math(EXPR _PYTHON_BITS "${PYTHON_SIZEOF_VOID_P} * 8")
+         math(EXPR _CMAKE_BITS "${CMAKE_SIZEOF_VOID_P} * 8")
+-- 
+2.25.4
+
meta-python/recipes-devtools/python/python3-pybind11/0001-Do-not-strip-binaries.patch new file +39 -0
new file mode 100644
index 000000000..07ab9a03b
@@ -0,0 +1,39 @@
+From 918f3ef01c7a67f3beb67307966698474f144581 Mon Sep 17 00:00:00 2001
+From: Philip Balister <[email protected]>
+Date: Wed, 8 Jul 2020 09:41:43 -0400
+Subject: [PATCH] Do not strip binaries.
+
+ * OpenEmbedded strips them after creating debug packages.
+
+Signed-off-by: Philip Balister <[email protected]>
+---
+ tools/pybind11Tools.cmake | 13 -------------
+ 1 file changed, 13 deletions(-)
+
+diff --git a/tools/pybind11Tools.cmake b/tools/pybind11Tools.cmake
+index a3603ab..b4c8f63 100644
+--- a/tools/pybind11Tools.cmake
++++ b/tools/pybind11Tools.cmake
+@@ -230,19 +230,6 @@ function(pybind11_add_module target_name)
+ 
+   _pybind11_add_lto_flags(${target_name} ${ARG_THIN_LTO})
+ 
+-  if (NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo)
+-    # Strip unnecessary sections of the binary on Linux/Mac OS
+-    if(CMAKE_STRIP)
+-      if(APPLE)
+-        add_custom_command(TARGET ${target_name} POST_BUILD
+-                           COMMAND ${CMAKE_STRIP} -x $<TARGET_FILE:${target_name}>)
+-      else()
+-        add_custom_command(TARGET ${target_name} POST_BUILD
+-                           COMMAND ${CMAKE_STRIP} $<TARGET_FILE:${target_name}>)
+-      endif()
+-    endif()
+-  endif()
+-
+   if(MSVC)
+     # /MP enables multithreaded builds (relevant when there are many files), /bigobj is
+     # needed for bigger binding projects due to the limit to 64k addressable sections
+-- 
+2.25.4
+
meta-python/recipes-devtools/python/python3-pybind11_2.5.0.bb +14 -3
index dc3b8f6ad..46bba8d8d 100644
@@ -3,7 +3,18 @@ HOMEPAGE = "https://github.com/wjakob/pybind11"
 LICENSE = "BSD-2-Clause"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=beb87117af69fd10fbf9fb14c22a2e62"
 
-SRC_URI[md5sum] = "5355e1fd05c8eedef19cc9bfd3d82a77"
-SRC_URI[sha256sum] = "ea5a4e7a880112915463826f1acbec5892df36dfe102ecb249229ac514fb54ad"
+DEPENDS = "boost"
 
-inherit pypi setuptools3
+SRC_URI = "git://github.com/pybind/pybind11.git \
+           file://0001-Do-not-strip-binaries.patch \
+           file://0001-Do-not-check-pointer-size-when-cross-compiling.patch \
+          "
+SRCREV = "3b1dbebabc801c9cf6f0953a4c20b904d444f879"
+
+S = "${WORKDIR}/git"
+
+BBCLASSEXTEND = "native"
+
+EXTRA_OECMAKE =  "-DPYBIND11_TEST=OFF"
+
+inherit cmake python3native
Signature · 1 line
2.13.6
Acked-by on v2 1/1
#1 lore raw
Quoted 8 lines · Philip Balister

* Switch to git repo to pick up cmake files for recipes to use
* Use cmake to build innstead of pypi so cmake files are included in sysroot
* Disable tests to prevent configure failure (I tried adding pytest asa DEPEND)
* Patch out cmake that strips output to prevent QA failures
* Do not check pointer length for installed python when cross compiling.
* With this I can build gnuradio using pybind11.

Quoted 117 lines
---
  ...t-check-pointer-size-when-cross-compiling.patch | 30 +++++++++++++++++
  .../0001-Do-not-strip-binaries.patch               | 39 ++++++++++++++++++++++
  .../python/python3-pybind11_2.5.0.bb               | 17 ++++++++--
  3 files changed, 83 insertions(+), 3 deletions(-)

create mode 100644 meta-python/recipes-devtools/python/python3-pybind11/0001-Do-not-check-pointer-size-when-cross-compiling.patch create mode 100644 meta-python/recipes-devtools/python/python3-pybind11/0001-Do-not-strip-binaries.patch

meta-python/recipes-devtools/python/python3-pybind11/0001-Do-not-check-pointer-size-when-cross-compiling.patch new file +30 -0
new file mode 100644
index 000000000..6455c95e7
@@ -0,0 +1,30 @@
+From 3abfa65517959ad279481021fafefba28f955e76 Mon Sep 17 00:00:00 2001
+From: Philip Balister <[email protected]>
+Date: Fri, 10 Jul 2020 10:14:59 -0400
+Subject: [PATCH] Do not check pointer size when cross compiling.
+
+It is reasonable to build for 32 machine on a 64 bit build machine. Prevents:
+| CMake Error at tools/FindPythonLibsNew.cmake:127 (message):
+|   Python config failure: Python is 64-bit, chosen compiler is 32-bit
+
+Signed-off-by: Philip Balister <[email protected]>
+---
+ tools/FindPythonLibsNew.cmake | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/tools/FindPythonLibsNew.cmake b/tools/FindPythonLibsNew.cmake
+index d0c8fa2..8479e70 100644
+--- a/tools/FindPythonLibsNew.cmake
++++ b/tools/FindPythonLibsNew.cmake
+@@ -123,7 +123,7 @@ list(GET _PYTHON_VALUES 9 PYTHON_MULTIARCH)
+
+ # Make sure the Python has the same pointer-size as the chosen compiler
+ # Skip if CMAKE_SIZEOF_VOID_P is not defined
+-if(CMAKE_SIZEOF_VOID_P AND (NOT "${PYTHON_SIZEOF_VOID_P}" STREQUAL "${CMAKE_SIZEOF_VOID_P}"))
++if((NOT CMAKE_CROSSCOMPILING) AND CMAKE_SIZEOF_VOID_P AND (NOT "${PYTHON_SIZEOF_VOID_P}" STREQUAL "${CMAKE_SIZEOF_VOID_P}"))
+     if(PythonLibsNew_FIND_REQUIRED)
+         math(EXPR _PYTHON_BITS "${PYTHON_SIZEOF_VOID_P} * 8")
+         math(EXPR _CMAKE_BITS "${CMAKE_SIZEOF_VOID_P} * 8")
+--
+2.25.4
+
meta-python/recipes-devtools/python/python3-pybind11/0001-Do-not-strip-binaries.patch new file +39 -0
new file mode 100644
index 000000000..07ab9a03b
@@ -0,0 +1,39 @@
+From 918f3ef01c7a67f3beb67307966698474f144581 Mon Sep 17 00:00:00 2001
+From: Philip Balister <[email protected]>
+Date: Wed, 8 Jul 2020 09:41:43 -0400
+Subject: [PATCH] Do not strip binaries.
+
+ * OpenEmbedded strips them after creating debug packages.
+
+Signed-off-by: Philip Balister <[email protected]>
+---
+ tools/pybind11Tools.cmake | 13 -------------
+ 1 file changed, 13 deletions(-)
+
+diff --git a/tools/pybind11Tools.cmake b/tools/pybind11Tools.cmake
+index a3603ab..b4c8f63 100644
+--- a/tools/pybind11Tools.cmake
++++ b/tools/pybind11Tools.cmake
+@@ -230,19 +230,6 @@ function(pybind11_add_module target_name)
+
+   _pybind11_add_lto_flags(${target_name} ${ARG_THIN_LTO})
+
+-  if (NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo)
+-    # Strip unnecessary sections of the binary on Linux/Mac OS
+-    if(CMAKE_STRIP)
+-      if(APPLE)
+-        add_custom_command(TARGET ${target_name} POST_BUILD
+-                           COMMAND ${CMAKE_STRIP} -x $<TARGET_FILE:${target_name}>)
+-      else()
+-        add_custom_command(TARGET ${target_name} POST_BUILD
+-                           COMMAND ${CMAKE_STRIP} $<TARGET_FILE:${target_name}>)
+-      endif()
+-    endif()
+-  endif()
+-
+   if(MSVC)
+     # /MP enables multithreaded builds (relevant when there are many files), /bigobj is
+     # needed for bigger binding projects due to the limit to 64k addressable sections
+--
+2.25.4
+
meta-python/recipes-devtools/python/python3-pybind11_2.5.0.bb +14 -3
index dc3b8f6ad..46bba8d8d 100644
@@ -3,7 +3,18 @@ HOMEPAGE = "https://github.com/wjakob/pybind11"
  LICENSE = "BSD-2-Clause"
  LIC_FILES_CHKSUM = "file://LICENSE;md5=beb87117af69fd10fbf9fb14c22a2e62"
 
-SRC_URI[md5sum] = "5355e1fd05c8eedef19cc9bfd3d82a77"
-SRC_URI[sha256sum] = "ea5a4e7a880112915463826f1acbec5892df36dfe102ecb249229ac514fb54ad"
+DEPENDS = "boost"
 
-inherit pypi setuptools3
+SRC_URI = "git://github.com/pybind/pybind11.git \
+           file://0001-Do-not-strip-binaries.patch \
+           file://0001-Do-not-check-pointer-size-when-cross-compiling.patch \
+          "
+SRCREV = "3b1dbebabc801c9cf6f0953a4c20b904d444f879"
+
+S = "${WORKDIR}/git"
+
+BBCLASSEXTEND = "native"
+
+EXTRA_OECMAKE =  "-DPYBIND11_TEST=OFF"
+
+inherit cmake python3native