summary refs log tree commit diff
path: root/pkgs/development/python-modules/pybind11/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/python-modules/pybind11/default.nix')
-rw-r--r--pkgs/development/python-modules/pybind11/default.nix52
1 files changed, 36 insertions, 16 deletions
diff --git a/pkgs/development/python-modules/pybind11/default.nix b/pkgs/development/python-modules/pybind11/default.nix
index 2df360dfaab..0f386a7c42f 100644
--- a/pkgs/development/python-modules/pybind11/default.nix
+++ b/pkgs/development/python-modules/pybind11/default.nix
@@ -5,9 +5,10 @@
 , python
 , pytest
 , cmake
-, numpy ? null
-, eigen ? null
-, scipy ? null
+, catch
+, numpy
+, eigen
+, scipy
 }:
 
 buildPythonPackage rec {
@@ -21,23 +22,42 @@ buildPythonPackage rec {
     sha256 = "0k89w4bsfbpzw963ykg1cyszi3h3nk393qd31m6y46pcfxkqh4rd";
   };
 
-  dontUseCmakeConfigure = true;
-
   nativeBuildInputs = [ cmake ];
-  checkInputs = [ pytest ]
-    ++ (lib.optional (numpy != null) numpy)
-    ++ (lib.optional (eigen != null) eigen)
-    ++ (lib.optional (scipy != null) scipy);
-  checkPhase = ''
-    cmake ${if eigen != null then "-DEIGEN3_INCLUDE_DIR=${eigen}/include/eigen3" else ""}
-    make -j $NIX_BUILD_CORES pytest
-  '';
 
-  # re-expose the headers to other packages
-  postInstall = ''
-    ln -s $out/include/python${python.pythonVersion}m/pybind11/ $out/include/pybind11
+  buildInputs = [ catch ];
+
+  cmakeFlags = [
+    "-DEIGEN3_INCLUDE_DIR=${eigen}/include/eigen3"
+  ] ++ lib.optionals (!python.isPy2) [
+  # Enable some tests only on Python 3. The "test_string_view" test
+  # 'testTypeError: string_view16_chars(): incompatible function arguments'
+  # fails on Python 2.
+    "-DPYBIND11_CPP_STANDARD=-std=c++17"
+  ];
+
+  dontUseSetuptoolsBuild = true;
+  dontUsePipInstall = true;
+  dontUseSetuptoolsCheck = true;
+
+  preFixup = ''
+    pushd ..
+    export PYBIND11_USE_CMAKE=1
+    setuptoolsBuildPhase
+    pipInstallPhase
+    # Symlink the CMake-installed headers to the location expected by setuptools
+    mkdir -p $out/include/${python.libPrefix}
+    ln -sf $out/include/pybind11 $out/include/${python.libPrefix}/pybind11
+    popd
   '';
 
+  installCheckTarget = "pytest";
+  doInstallCheck = true;
+  checkInputs = [
+    pytest
+    numpy
+    scipy
+  ];
+
   meta = {
     homepage = https://github.com/pybind/pybind11;
     description = "Seamless operability between C++11 and Python";