1{ stdenv
2, lib
3, buildPythonPackage
4, fetchFromGitHub
5, fetchpatch
6, python
7, pytest
8, cmake
9, catch
10, numpy
11, eigen
12, scipy
13}:
14
15buildPythonPackage rec {
16 pname = "pybind11";
17 version = "2.6.2";
18
19 src = fetchFromGitHub {
20 owner = "pybind";
21 repo = pname;
22 rev = "v${version}";
23 sha256 = "1lsacpawl2gb5qlh0cawj9swsyfbwhzhwiv6553a7lsigdbadqpy";
24 };
25
26 patches = [
27 # fix pybind11Config.cmake
28 (fetchpatch {
29 url = "https://github.com/pybind/pybind11/commit/d9c4e1047a95f023633a7260af5a633307438941.patch";
30 sha256 = "0kran295kj31xfs6mfha5ip132zd0pnj2dl36qzgyc1rpnha5gz4";
31 })
32 ];
33
34 nativeBuildInputs = [ cmake ];
35
36 buildInputs = [ catch ];
37
38 cmakeFlags = [
39 "-DEIGEN3_INCLUDE_DIR=${eigen}/include/eigen3"
40 ] ++ lib.optionals (python.isPy3k && !stdenv.cc.isClang) [
41 # Enable some tests only on Python 3. The "test_string_view" test
42 # 'testTypeError: string_view16_chars(): incompatible function arguments'
43 # fails on Python 2.
44 "-DPYBIND11_CPP_STANDARD=-std=c++17"
45 ];
46
47 dontUseSetuptoolsBuild = true;
48 dontUsePipInstall = true;
49 dontUseSetuptoolsCheck = true;
50
51 preFixup = ''
52 pushd ..
53 export PYBIND11_USE_CMAKE=1
54 setuptoolsBuildPhase
55 pipInstallPhase
56 # Symlink the CMake-installed headers to the location expected by setuptools
57 mkdir -p $out/include/${python.libPrefix}
58 ln -sf $out/include/pybind11 $out/include/${python.libPrefix}/pybind11
59 popd
60 '';
61
62 checkInputs = [
63 pytest
64 numpy
65 scipy
66 ];
67
68 meta = with lib; {
69 homepage = "https://github.com/pybind/pybind11";
70 description = "Seamless operability between C++11 and Python";
71 longDescription = ''
72 Pybind11 is a lightweight header-only library that exposes
73 C++ types in Python and vice versa, mainly to create Python
74 bindings of existing C++ code.
75 '';
76 license = licenses.bsd3;
77 maintainers = with maintainers;[ yuriaisaka ];
78 };
79}