You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by jm...@apache.org on 2021/09/03 22:02:32 UTC

[datasketches-cpp] 02/02: Changes to support wheels on Windows

This is an automated email from the ASF dual-hosted git repository.

jmalkin pushed a commit to branch pybind_build_dependency
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git

commit 40342e5a025cf0d18578ed600a380ed7c8bbf780
Author: Jon Malkin <jm...@users.noreply.github.com>
AuthorDate: Fri Sep 3 15:02:14 2021 -0700

    Changes to support wheels on Windows
---
 CMakeLists.txt          |  2 ++
 pyproject.toml          |  7 ++++---
 python/CMakeLists.txt   | 17 +++++++++--------
 python/pybind11Path.cmd |  3 +++
 setup.py                |  7 ++++---
 5 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e87448e..c1b8e80 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,6 +35,8 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
 #set(CMAKE_VERBOSE_MAKEFILE ON)
 set(CMAKE_MACOSX_RPATH ON)
 
+set(CMAKE_CXX_STANDARD 11)
+
 # enable compiler warnings globally
 # derived from https://foonathan.net/blog/2018/10/17/cmake-warnings.html
 # and https://arne-mertz.de/2018/07/cmake-properties-options/
diff --git a/pyproject.toml b/pyproject.toml
index a989be3..eabadd4 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,9 +1,10 @@
 [build-system]
 requires = ["wheel",
             "setuptools >= 30.3.0",
-            "setuptools_scm",
             "cmake >= 3.12",
-            "pybind11[global] >= 2.6.0"]
+            "pip >= 10.0",
+            "pybind11 >= 2.6.0"]
+build-backend = "setuptools.build_meta"
 
 [tool.tox]
 legacy_tox_ini = """
@@ -13,7 +14,7 @@ envlist = py3
 [testenv]
 deps = pytest
        numpy
-       pybind11[global] >= 2.6.0
+       pybind11 >= 2.6.0
 changedir = python/tests
 commands = pytest
 """
\ No newline at end of file
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index 4da7b9d..f541b93 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -15,18 +15,19 @@
 # specific language governing permissions and limitations
 # under the License.
 
-# TODO: Can we force python version >= 3.0?
+find_package(Python3 COMPONENTS Interpreter Development)
+
+# only Windows+MSVC seems to have trouble locating pybind11
 if (MSVC)
-  set(PYBIND11_CPP_STANDARD /std:c++11)
-else()
-  set(PYBIND11_CPP_STANDARD -std=c++11)
+  execute_process(COMMAND cmd.exe /c ${CMAKE_CURRENT_SOURCE_DIR}/pybind11Path.cmd "${Python3_EXECUTABLE}"
+      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+      OUTPUT_STRIP_TRAILING_WHITESPACE
+      OUTPUT_VARIABLE EXTRA_PACKAGE_PATH)
+  set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${EXTRA_PACKAGE_PATH})
 endif()
 
-find_package(Python3 COMPONENTS Interpreter Development)
-find_package(pybind11 CONFIG)
-#add_subdirectory(pybind11)
+find_package(pybind11 CONFIG REQUIRED)
 
-#pybind11_add_module(python MODULE EXCLUDE_FROM_ALL SYSTEM THIN_LTO)
 pybind11_add_module(python MODULE EXCLUDE_FROM_ALL THIN_LTO)
 
 target_link_libraries(python
diff --git a/python/pybind11Path.cmd b/python/pybind11Path.cmd
new file mode 100644
index 0000000..650625b
--- /dev/null
+++ b/python/pybind11Path.cmd
@@ -0,0 +1,3 @@
+@echo off
+:: Takes path to the Python interpreter and returns the path to pybind11
+%1 -m pip show pybind11 | %1 -c "import sys,re;[sys.stdout.write(re.sub('^Location:\\s+','',line)) for line in sys.stdin if re.search('^Location:\\s+',line)]"
diff --git a/setup.py b/setup.py
index a84954e..d3d89e5 100644
--- a/setup.py
+++ b/setup.py
@@ -60,7 +60,8 @@ class CMakeBuild(build_ext):
                            cfg.upper(),
                            extdir)]
             if sys.maxsize > 2**32:
-                cmake_args += ['-A', 'x64']
+                cmake_args += ['-T', 'host=x64']
+                cmake_args += ['DCMAKE_GENERATOR_PLATFORM=x64']
                 build_args += ['--', '/m']
         else:
             cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
@@ -75,7 +76,7 @@ class CMakeBuild(build_ext):
         subprocess.check_call(['cmake', ext.sourcedir] + cmake_args,
                               cwd=self.build_temp, env=env)
         subprocess.check_call(['cmake', '--build', '.', '--target', 'python'] + build_args,
-                              cwd=self.build_temp)
+                              cwd=self.build_temp, env=env)
         print() # add an empty line to pretty print
 
 setup(
@@ -92,6 +93,6 @@ setup(
     # may need to add all source paths for sdist packages w/o MANIFEST.in
     ext_modules=[CMakeExtension('datasketches')],
     cmdclass={'build_ext': CMakeBuild},
-    setup_requires=['setuptools_scm','tox-setuptools'],
+    install_requires=['numpy', 'pybind11 >= 2.6.0'],
     zip_safe=False
 )

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org